|
-
August 30th, 2001, 08:22 PM
#1
How to pass IUnknown* from VB to C++ code?
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.
-
August 31st, 2001, 01:53 AM
#2
Re: How to pass IUnknown* from VB to C++ code?
Dim lPI as IMyInterface
set lPI = new MyLib.MyObj
myVar.FooBar(lPI)
<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
</center>
-
September 26th, 2001, 04:40 PM
#3
Re: How to pass IUnknown* from VB to C++ code?
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|