CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2000
    Posts
    737

    Equivalent C statement for VB Set

    in VB, we can set a variable reference to another variable, like this

    dim d as new class1
    dim withevents c as class1

    set c = d

    so, c is not an instance, but rather reference to d, but whenever, some event happen in d, c get triggered.

    So, what is the equivalent C statement for "set c = d" ? thanks.


    HTH

    cksiow
    http://vblib.virtualave.net - share our codes

  2. #2
    Join Date
    Mar 2002
    Location
    Izhevsk, Udmurtia, Russia
    Posts
    930

    Re: Equivalent C statement for VB Set

    Your question actually contains 2 questions: with and without "WithEvents"
    1.

    dim d as class1
    dim c as class1
    set c = d



    are equivalent the origin assignment of object pointer

    CComPtr<IClass1> spd;
    CComPtr<IClass1> spc;
    spc = spd;



    2.

    dim d as class1
    dim withevents c as class1
    set c = d



    are equivalent the origin assignment of object pointer and connection to object

    CComPtr<IClass1> spd;
    CComPtr<IClass1> spc;
    spc = spd;
    // Here should be the CComPtr<IClass1>::Advise to connect to stored object with Event Sink pUnk
    // CComPtr<>::Advise(IUnknown* pUnk, const IID& iid, LPDWORD pdw)





    With best wishes,
    Vita
    With best wishes,
    Vita
    -----------------------
    Russian Software Development Network -- http://www.rsdn.ru

  3. #3
    Join Date
    Apr 2000
    Posts
    737

    Re: Equivalent C statement for VB Set

    thanks. but i don't intend to use ATL, can u change to following statement to C++ statement, assuming my interface is call IClass1

    CComPtr<IClass1> spd;CComPtr<IClass1> spc;spc = spd;

    thanks again.



    HTH

    cksiow
    http://vblib.virtualave.net - share our codes

  4. #4
    Join Date
    Mar 2002
    Location
    Izhevsk, Udmurtia, Russia
    Posts
    930

    Re: Equivalent C statement for VB Set

    There are too many techniques.

    IClass1* d;
    IClass1* c;



    1.

    c = d;
    c->AddRef();
    ...
    c->Release();



    2.

    HRESULT hr = d->QueryInterface(IID_IClass1, static_cast<void**>&c );
    if( SUCCEEDED(hr) )
    {
    ...
    c->Release();
    }



    and so on. But it's good idea to use the wrappers of the interface pointers (CComPtr, smart-pointers etc.).

    With best wishes,
    Vita
    With best wishes,
    Vita
    -----------------------
    Russian Software Development Network -- http://www.rsdn.ru

  5. #5
    Join Date
    Apr 2000
    Posts
    737

    Re: Equivalent C statement for VB Set

    for the Advise, how do we get the sink pUnknown ? thanks.


    HTH

    cksiow
    http://vblib.virtualave.net - share our codes

  6. #6
    Join Date
    Mar 2002
    Location
    Izhevsk, Udmurtia, Russia
    Posts
    930

    Re: Equivalent C statement for VB Set

    For the Advise, you must create the sink COM object (realizing of class1's event interface) and get its IUnknown interface to Advise() function.
    For example, ATL realization of this technique:

    ATLINLINE ATLAPI AtlAdvise(IUnknown* pUnkCP, IUnknown* pUnk, const IID& iid, LPDWORD pdw)
    {
    CComPtr<IConnectionPointContainer> pCPC;
    CComPtr<IConnectionPoint> pCP;
    HRESULT hRes = pUnkCP->QueryInterface(IID_IConnectionPointContainer, (void**)&pCPC);
    if (SUCCEEDED(hRes))
    hRes = pCPC->FindConnectionPoint(iid, &pCP);
    if (SUCCEEDED(hRes))
    hRes = pCP->Advise(pUnk, pdw);
    return hRes;
    }



    where pUnkCP - IUnknown of Server object (class1 for you, either c or d object),
    pUnk - IUnknown of Sink object
    iid - IID of class1's event interface
    pdw - cookie to Unadvise()

    With best wishes,
    Vita
    With best wishes,
    Vita
    -----------------------
    Russian Software Development Network -- http://www.rsdn.ru

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