[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

ZhangZQ

11/4/2003 1:31:00 AM

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!


2 Answers

ZhangZQ

11/4/2003 1:36:00 AM

0

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" <zhangzq71@hotmail.com> wrote in message
news:OqueiNnoDHA.1948@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!
>
>


Peter Koen

11/4/2003 3:21:00 AM

0

"ZhangZQ" <zhangzq71@hotmail.com> wrote in
news:OqueiNnoDHA.1948@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/l...
us/cpguide/html/cpconcomdatatypes.asp

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

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

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

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