tags:

views:

27

answers:

1

Most com methods have a signature like this:

STDMETHOD(someFunc) (THIS_ ParamType param) PURE;

Which translates to C# via ComImport as:

[PreserveSig()]
int someFunc(MarshaledParamType param);

Is there some way to preserve the "THIS_" parameter in the PInvoke signature? So that I can do something like:

int someFunc(IntPtr ptrToCOMInstance, MarshaledParamType param);

or

int someFunc(IMyCOMClass comInstance, MarshaledParamType param);
+1  A: 

That's a fake annotation, representing the this pointer that gets passed to a class method. You don't actually declare it in neither C++ nor C#, it gets passed without writing it out explicitly.

But do note the difference between the server and the client. In the server, you use the this keyword to recover that pointer. In the client, you have the object reference. For example:

Word.Application app = new Word.Application();
Word.Document doc = new Word.Document();

The app and doc variables are the object references you are looking for. The value of this inside Word's implementation of the Application and Document interfaces. Ignoring the intricacies of RCWs for a moment.

Hans Passant