Click to See Complete Forum and Search --> : How to pass IUnknown* from VB to C++ code?


Anirban
August 30th, 2001, 08:22 PM
Hi All,

I would like to use a COM component that is written in C++ from VB code. The idl looks like this,
-----
library Myib
{
....
....
interface IFoo:IDispatch
{
HRESULT FooBar([in] IMyInterface* Item);
};
...
coclass MyObj
{
[default] interface IFoo;
};
};
----

In the VB code, I do this:
---
Dim lPI As IMyInterface
Set myVar = New MyLib.MyObj
Dim v As Variant
v = lPI
myVar.FooBar(v)
----

All I get here is that v as a VT_BSTR (in the C++ side). Is there any way of packing Variant v as an varObj instead of default string? If not, what is the best way to send something that corresponds to IMyInterface* in the C++ side?

Thanks much.

-Anirban.

berta
August 31st, 2001, 01:53 AM
Dim lPI as IMyInterface
set lPI = new MyLib.MyObj

myVar.FooBar(lPI)





<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/images/bertaplanet.gif'>
</center>

Biplab Das
September 26th, 2001, 04:40 PM
All VB Objects are basically COM objects and which means(obviously) that all VB objects supports IUnknown.
So you can directly pass the VB Object as argument where an IUNKNOWN* is required.
I am trying to exemplify this idea in the following code:


Dim oVbObject as VBProj.VBClass
Dim oVCObject as VCClass

'Never use new operator to create a COM object.
'It can scre up MTS functionality. It bypasses
'many of the COM-thing. Always use CreateObject()

set oVBObject=CreateObject("VBProj.VBClass")
set oVCObject =CreateObject("ProgID_of_VC_Object")

oVCObject.DoSomethingWithIUnknownPtr(oVBObject)





Biplab