|
-
February 4th, 2010, 08:14 AM
#1
COM Interop problem
Hi all,
We have a COM component which was built with VC++ 6.0 and we are using it for more than 10 years. But, now we creating some client interfaces using c# and we are using this COM component as reusable.
Now, when we load the COM object as reference in VS2008, it generates a wrapper assembly by default. When we look into the assembly, the interface was not properly translated because some of the parameters were not properly marshalled to their required types. So, we decided to create our own wrapper assembly. In this way, all the calls will be properly marshalled to their respective types.
When we created our own assembly, some of the methods in COM object are not called even we are calling it from our .NET application. Our interfaces does not support IDispatch interface so there is no late binding over here.
Below is the COM interface and its .NET wrapper: -
///////////////////////////////
/// COM interface
///////////////////////////////
[
object,
uuid(799D3581-58C3-11d4-930F-004005E1576C),
helpstring("IInstrument Interface"),
pointer_default(unique)
]
interface IInstrument
{
HRESULT GetModel([out,retval] long *pVal);
HRESULT Connect([in] IInstrumentSink *pSink);
HRESULT Disconnect();
HRESULT QueryInstCap([in] INSTRUMENT_COMMAND pCmd,[out,retval] BOOL *pVal);
};
[
uuid(F7D90C10-9DC2-11D4-930F-004005E1576C),
helpstring("TestInstrument Class")
]
coclass TestInstrument
{
[default] interface IInstrument;
};
///////////////////////////////////////////////////////////
Custom .NET COM Wrapper
///////////////////////////////////////////////////////////
[ComImport]
[Guid("799D3581-58C3-11d4-930F-004005E1576C")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInstrument
{
int GetModel();
void Connect([In] IInstrumentSink pSink);
void Disconnect();
[return: MarshalAs(UnmanagedType.Bool)]
bool QueryInstCap([In] INSTRUMENT_COMMAND pCmd);
}
[ComImport]
[Guid("F7D90C10-9DC2-11D4-930F-004005E1576C")]
class TestInstrument
{
}
Here, whenever I try to call 'GetModel' method in .NET, it is not called. But, when I try to call 'Connect' method, instead of calling the same method, it calls 'QueryInstCap'. It is wired, I do not understand it.
Any help will be highly appreciated?
Thanks in advance.
Regards.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|