473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

VARIANT type problem

If I have a method in an OCX, the definition is

[id(5), helpstring("Method Test1")] void Test1(VARIANT* a);

After I add reference to this OCX in Visual studio .net, it generates 2
dlls, and I look at the object browser, the definition of the above method
in the wrapper class is

Test1(ref object);

Now I use the C# to call this method,

object myObj = new object();
MyOCX.Test1(ref myObj); // Then it will throw an exception with error
message "type mismatch"

and no matter which value I set to myObj it always throws the exception with
the same error message.
I want to know how to call that
[id(5), helpstring("Method Test1")] void Test1(VARIANT* a); method?
Thank you very much!
Nov 15 '05 #1
2 1791
This is the IL of that RCW

.method public hidebysig newslot virtual
instance void Test1(object& a) cil managed
{
.maxstack 3
IL_0000: ldarg.0
IL_0001: ldfld class
[Interop.ocx030820Lib]ocx030820Lib._Docx030820
Axocx030820Lib.Axocx030820::ocx
IL_0006: brtrue.s IL_0014

IL_0008: ldstr "Test1"
IL_000d: ldc.i4.0
IL_000e: newobj instance void
[System.Windows.Forms]System.Windows.Forms.AxHost/InvalidActiveXStateExcepti
on::.ctor(string,

valuetype
[System.Windows.Forms]System.Windows.Forms.AxHost/ActiveXInvokeKind)
IL_0013: throw

IL_0014: ldarg.0
IL_0015: ldfld class
[Interop.ocx030820Lib]ocx030820Lib._Docx030820
Axocx030820Lib.Axocx030820::ocx
IL_001a: ldarg.1
IL_001b: callvirt instance void
[Interop.ocx030820Lib]ocx030820Lib._Docx030820::Test1(object&)
IL_0020: ret
} // end of method Axocx030820::Test1

The exception will be thrown at IL_011b.

"ZhangZQ" <zh*******@hotmail.com> wrote in message
news:Oq**************@TK2MSFTNGP12.phx.gbl...
If I have a method in an OCX, the definition is

[id(5), helpstring("Method Test1")] void Test1(VARIANT* a);

After I add reference to this OCX in Visual studio .net, it generates 2
dlls, and I look at the object browser, the definition of the above method
in the wrapper class is

Test1(ref object);

Now I use the C# to call this method,

object myObj = new object();
MyOCX.Test1(ref myObj); // Then it will throw an exception with error
message "type mismatch"

and no matter which value I set to myObj it always throws the exception with the same error message.
I want to know how to call that
[id(5), helpstring("Method Test1")] void Test1(VARIANT* a); method?
Thank you very much!

Nov 15 '05 #2
"ZhangZQ" <zh*******@hotmail.com> wrote in
news:Oq**************@TK2MSFTNGP12.phx.gbl:
If I have a method in an OCX, the definition is

[id(5), helpstring("Method Test1")] void Test1(VARIANT* a);

After I add reference to this OCX in Visual studio .net, it generates
2 dlls, and I look at the object browser, the definition of the above
method in the wrapper class is

Test1(ref object);

Now I use the C# to call this method,

object myObj = new object();
MyOCX.Test1(ref myObj); // Then it will throw an exception with
error message "type mismatch"

and no matter which value I set to myObj it always throws the
exception with the same error message.
I want to know how to call that
[id(5), helpstring("Method Test1")] void Test1(VARIANT* a); method?
Thank you very much!


Hi,

Either you use Convert.TOxxxx to get the value you want from that object
or you make your own wrapper. For that you will have to use the
MarshalAsAttribute to tell the Runtime what type you really want to pass.

Details about the mapping of the different datatypes can be found here:

http://msdn.microsoft.com/library/en-
us/cpguide/html/cpconcomdatatypes.asp

Further Information about Marshaling can also be found here:
http://msdn.microsoft.com/library/en-
us/cpguide/html/cpconmarshalingdatawithcominterop.asp

--
------ooo---OOO---ooo------

Peter Koen - www.kema.at
MCAD CAI/RS CASE/RS IAT

------ooo---OOO---ooo------
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Matt Smith | last post by:
Hi, all. Just a quick question, when setting a COM process to read a value from a pre-defined register index, I think, I have to change the variable that the value will be returned to (as I have...
1
by: C. N. Sridhar | last post by:
Hi, I'm writing a wrapper to a win32 dll in C#. I need to call a method in DLL which has a Variant type reference parameter. How to marshal variant type from win32 (unmanaged code) to C#...
19
by: Jon Davis | last post by:
Hi guys! Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days. This is written in C#, but you can build a CLR/.NET class library assembly and reference...
0
by: dwinson | last post by:
I am writing an add-in in C# for a server written in VB6. In order for my add-in to work I need to implement this method: MyMethod(string inputData) .... so my C# code looks like this: ...
7
by: Tracks | last post by:
I have old legacy code from vb5 where data was written to a file with a variant declaration (this was actually a coding error?)... in vb5 the code was: Dim thisdata as integer Dim thatdata...
4
by: Claus77 | last post by:
Hi there, I've got a little problem with the following: I'm just writing a com-application in C++ with VS-6, which should also be used with VB-Script, so I have to use variables of type...
11
by: MLH | last post by:
The following procedures found at http://ffdba.com/downloads/Send_Mail_With_Outlook_Express.htm are meant to work together in harmony to effect eMail sends via OE. The last procedure (FN SplitB)...
1
by: darrenbenn | last post by:
I need to convert this code to VB .NET (2003). Dim FaxMsg As IFaxMessage Set FaxMsg = gFC.NewMessage Dim Recip As Variant ' add a recipient to the fax recipients collection Set Recip =...
0
by: MikalE | last post by:
I’m using a third-party ActicveX component that has the following description for one of its events: They mean by this that LocationType is an array of VARIANTS (containing enumeration) When...
4
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
How can I define type variant in c#?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.