CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    2

    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.



  2. #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>

  3. #3
    Join Date
    Sep 2001
    Location
    Philadelphia,PA,USA
    Posts
    46

    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
  •  





Click Here to Expand Forum to Full Width

Featured