-
April 15th, 2002, 07:51 PM
#1
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
-
April 16th, 2002, 03:48 AM
#2
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
-
April 16th, 2002, 04:22 AM
#3
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
-
April 16th, 2002, 04:45 AM
#4
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
-
April 16th, 2002, 08:16 PM
#5
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
-
April 17th, 2002, 05:02 AM
#6
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|