How to implement COM callbacks in managed C++?

G

Guest

I call from managed C++ a DCOM server interface method that takes a callback
interface as parameter. I cannot figure out how to implement such a callback
object in managed C++. The callback interface (e.gr. ICallback) is defined by
the server type library.

I have figured out that the following code seems to implement a COM object
in managed C++ but how do I implement the callback interface ICallback:

#import "dcom_server.exe" // Import server type library
using namespace System::Runtime::InteropServices;

[GuidAttribute("..."), ClassInterface(ClassInterfaceType::AutoDual)]
public __gc class CallbackImplementation
{
};

I cannot inherit from the ICallback interface because it's unmanaged code.

Any ideas?

Anders
 
J

Jochen Kalmbach [MVP]

Hi anders!
I call from managed C++ a DCOM server interface method that takes a callback
interface as parameter. I cannot figure out how to implement such a callback
object in managed C++. The callback interface (e.gr. ICallback) is defined by
the server type library.

If your server uses late-bindung you can implement the callback like:

<code>
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class MyCallback
{
[DispId(1)]
public void OnXxx(int eventHandle, object data, int result)
{
}
}
</code>

Currently I do not know how to do it if you must provide a early-binding...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top