Passing .NET references through COM objects

  • Thread starter Thread starter David Vestal
  • Start date Start date
D

David Vestal

Suppose a COM object creates a .NET object (call it 'A') through a Com-
Callable Wrapper.

Can the COM object then pass a .NET reference to 'A' to a different .NET
object (call it 'B')? The goal is for 'B' to be able to use 'A' like any
other .NET object.


This is a much simpler way to ask the same question I was asking in my
recent post "Fairly complicated COM/.NET mixing."
 
David,
Can the COM object then pass a .NET reference to 'A' to a different .NET
object (call it 'B')? The goal is for 'B' to be able to use 'A' like any
other .NET object.

Yes



Mattias
 
David,


Well it should "just work", no magic needed. I assume you are having
problems with it since you're asking. What's failing?

It's more that I just don't know what variable type I should use in COM
code to represent a .NET reference.

Suppose my COM object instantiates a CCW-wrapped .NET object that exposes
as a property a System.Collections.Queue.

The COM object provides a getQueue method, which should return the property
exposed by the .NET object. What should the signature of this method be?

class COMObject : IUnknown{
public:
CComPtr<IDotNetObject> dotNetObject;

HRESULT getQueue([out, retval] ?Type? returnValue){
return dotNetObject->get_queueProperty(returnValue);
}
};

Obviously, the code is inexact, but what should I put in place of ?Type?
such that a .NET object could obtain the Queue exposed by IDotNetObject?
 
David,

Mscorlib.tlb contains interfaces for COM visible types in
Mscorlib.dll. If you #import it in your C++ code, you should be able
to use _Queue* as the parameter type.

That said, I personally wouldn't directly expose framework types like
that to COM, but instead write my own wrapper class so I could control
exactly which methods are visisble to the COM clients.



Mattias
 

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

Back
Top