473,386 Members | 2,078 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,386 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 16 '05 #1
2 2601
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 16 '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 16 '05 #3

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

Similar topics

3
by: kieran | last post by:
Hi, I have a form which is submitting into a sql server db. i have one of the fields set to ntext which says length of 16. when i insert info, it only sumbits about a paragraph and when i pull...
2
by: ZhangZQ | last post by:
If I have a method in an OCX, the definition is 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...
1
by: icedac | last post by:
I have some questions about template and c++ itself. ///////////////////////////////////////////////////////////////////////// q1) see follow c++ code, and compile. it's works only IntelC++8.1...
1
by: Vinay Jain | last post by:
Hi I am newbie so this problem may be too simple to be asked.please help me if any new thing to be added in following: I want to use user defined data type in User_Type(n) way.... I created...
6
by: Picho | last post by:
Hi all. I have a webservice and a windows app. both of them reference the same class library called WebServiceTest.Core that defines a class called Class1. the webservice exposes a method...
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...
3
by: G Gerard | last post by:
Hello If Variant type is the data type that contains any kind of data type is there a reason why one would not always use Variant when declaring variables? Thanks G Gerard
6
by: cppnow | last post by:
Hello. I have a strange conceptual problem I'm trying to think about. I would like to build a library that allows the user to do the following: 1) User defined types: The user defines their...
2
by: Bjoern | last post by:
Hi I have a COM object which fires an event where I have to pass an array of SHORTs as a parameter to the listening object. The array of SHORTs is encapsulated in a the CComSafeArray-class and...
17
by: irfan200x | last post by:
Folder Option Hi All, I have the new type problem in folder option where should i get this problem through Flash Drive Plug into USB port and its Shows ON and OFF in the Windows XP SP2. and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.