Link to home
Start Free TrialLog in
Avatar of PastorDwayne
PastorDwayne

asked on

IUnkown as param

Good-day,

I need to pass IUnkown as a parameter to a function.  Here is how it is done in C++:

******************************
CComObject<CTestImpl> * m_pImpl;
m_pImpl->AddRef();
ICallBackItf * pCallBk = 0;
m_pImpl->QueryInterface(&pCallBk);
m_spInterface1->Function1(pCallBk);
******************************

What is the equivalent in C#?

Thanks for your time
Avatar of vascov
vascov
Flag of United States of America image

You want to pass a callback to C# that calls into COM, is that it ?
You'll need COM interop.

In .NET you'll need the COM type definitions, and then it's just passing back a pointer and assigning it.

Have a look here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconexposingcomcomponentstonetframework.asp?frame=true

hth

Vasco
Avatar of PastorDwayne
PastorDwayne

ASKER

Thanks for your response.  I followed the link, but wasn't able to find any pertinent info.  Here's more details:  I am attempting to access a COM object which has two interfaces.  I add a reference to my C# for this object; I am able to access one of the interfaces, and it's methods.  One of the method parameters is IUnknown of the second interface.  Here is what I thought might work:

**********************************
CTestImpl m_spInterface1 = new CTestImpl ();
ICallBackItf cb = m_spInterface1  as ICallBackItf;
spInterface1.(cb);
**********************************

I thought I could query spInterface1 for the IUnknown of ICallBackItf, but it doesn’t work.
ASKER CERTIFIED SOLUTION
Avatar of _ys_
_ys_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial