Converting interface pointers
-
Hi all! I tried to post this in the C# forum, but without replies. I tought I might try here too. I have a small Interop question: I have a COM object that takes a structure as in-parameter. One of the fields in the structure is an IID*. When doing this in C++ the code: GUID rrid = __uuidof( _InterfaceName ); parStruct.riid = &rrid; works fine. How would I do this in C#? I have tried several things, but can´t get it to work. The type of the struct-field in C# is intPtr. And the only way I can find such a type, that I can think of, is: Type t = typeof( _InterfaceName ); System.RuntimeTypeHandle h = t.TypeHandle; parStruct.riid = h.Value; But I guess that I am way off here. Any one that can give me a hand here? Regards Mikke Added info: Hi again! I tried to create a C++ .Net project instead, just to try and find a work-around. When I took the COM objects needed and tried to import them into my brand new cpp project i got this error message: TlbImp warning: The type library importer could not convert the signature for the member 'RobEventParams.riid'. And a couple of other ones like this one for other similar parameter-structs with riid fields. What does that mean for me? Is it impossible to marshal something from .Net into this COM? The purpose is to set up a sink and recieve events from the COM object, to do this I should send a ref to an object that should recieve the events and the signature of an interface implemented in the receiver. It is the interface "signature" that is the riid, and also the problem here. When I execute my C# code above I get an exception telling me that "No such interface supported". Do I have to submit a non-.net method as a sink here? Best regards again / Mikke
-
Hi all! I tried to post this in the C# forum, but without replies. I tought I might try here too. I have a small Interop question: I have a COM object that takes a structure as in-parameter. One of the fields in the structure is an IID*. When doing this in C++ the code: GUID rrid = __uuidof( _InterfaceName ); parStruct.riid = &rrid; works fine. How would I do this in C#? I have tried several things, but can´t get it to work. The type of the struct-field in C# is intPtr. And the only way I can find such a type, that I can think of, is: Type t = typeof( _InterfaceName ); System.RuntimeTypeHandle h = t.TypeHandle; parStruct.riid = h.Value; But I guess that I am way off here. Any one that can give me a hand here? Regards Mikke Added info: Hi again! I tried to create a C++ .Net project instead, just to try and find a work-around. When I took the COM objects needed and tried to import them into my brand new cpp project i got this error message: TlbImp warning: The type library importer could not convert the signature for the member 'RobEventParams.riid'. And a couple of other ones like this one for other similar parameter-structs with riid fields. What does that mean for me? Is it impossible to marshal something from .Net into this COM? The purpose is to set up a sink and recieve events from the COM object, to do this I should send a ref to an object that should recieve the events and the signature of an interface implemented in the receiver. It is the interface "signature" that is the riid, and also the problem here. When I execute my C# code above I get an exception telling me that "No such interface supported". Do I have to submit a non-.net method as a sink here? Best regards again / Mikke
I can see why no one responded to your inquiry. The way you phrased it is confusing, even to me, and I read it and then re-read it several times. The basic concept is that you are trying to write a .NET application that will respond to events fired from a COM object that you have imported. While it appears that this should be a simple matter, it is actually confusing as hell. I have a copy of the book, ".NET and COM: The Complete Interoperability Guide", by Adam Nathan, that I have learned an immense amount of 'stuff' from. I would highly recommend it, especially if you do this type of thing alot. He has an entire chapter devoted to the subject, "Responding to COM Events", which is about 50 pages long and describes the techniques clearly and in detail. To be perfectly honest with you, I don't completely understand the matter, and I am reluctant to provide you with confusing information. However, you are working in the right direction. In his book, Adam Nathan describes the callback mechanisms for both .NET and COM, and, while similar, they differ significantly. Basically, he describes the way the type library importer transforms the Source Interface in order to expose the COM object connection points as .NET events using a number of additional types (these are: an event interface, a delegate, a private class that handles interaction with the connection point, and a private sink class that implements the source interface). It is just too much information to adequately describe here. I suggest that you consult his book.