473,406 Members | 2,387 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,406 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 2605
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.