|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
From: Pradeep Tapadiya (pradeep
TAPADIYA.NET)Date: Sat Apr 07 2001 - 14:26:53 CDT
Daniel,
It indeed is a reference counting problem.You need
an extra AddRef in CDrawing's constructor for each of
the objects being created. You would also need a
Release for each of the objects in CDrawing's destructor.
Alternatively, you can use "CComPtr<CComObject<CColor>>"
instead of "CComObject<CColor>*."
On a side note, instead of a calling "new" followed by "FinalConstruct,"
you can just call CreateInstance, as shown below:
hr = CComObject<CColor>::CreateInstance(&pvarColor)
HTH.
Pradeep
http://www.tapadiya.net/pradeep
----- Original Message -----
From: "Daniel Dobrincic" <daniel.dobrincic
BSS.HR>
To: <DCOM
DISCUSS.MICROSOFT.COM>
Sent: Saturday, April 07, 2001 4:35 AM
Subject: QueryInterface
> hi,
>
> im newbi in visual c++ com programming and hope some1 can help me with
this
> one here:
>
> i have method imp :
>
> STDMETHODIMP CDrawing::get_Color(IColor* *pVal)
> {
>
> /* Return reference to Color - property */
> return pvarColor->QueryInterface(IID_IColor, (void**)pVal);
>
> }
>
> which is actually a get property.
>
> pvarColor is protected variable in CDrawing class :
>
> protected:
> CComObject<CColor>* pvarColor;
>
> .. and is initialized in CDrawing constructor
> CDrawing::CDrawing()
> {
> HRESULT hr;
>
> /* Create CColor object */
> pvarColor = new CComObject<CColor>();
> hr = pvarColor->FinalConstruct();
>
> /* Create CPen object */
> pvarPen = new CComObject<CPen>();
> hr = pvarPen->FinalConstruct();
>
> /* Create CQuery object */
> pvarQuery = new CComObject<CQuery>();
> hr = pvarQuery->FinalConstruct();
>
> /* Create CText object */
> pvarText = new CComObject<CText>();
> hr = pvarText->FinalConstruct();
> }
>
> now, when im calling properties from VB strange thing occure.
>
> Dim id As New Drawing
> Dim ic As Color
>
> id.CreateNew(100, 100)
>
> Set ic = id.Color
> ic.Allocate(0, 0, 0)
> ic.Allocate(255, 255, 255)
>
> .. this works fine ... but if i say :
> Dim id As New Drawing
>
> id.CreateNew(100, 100)
>
> id.Color.Allocate(0, 0, 0)
> id.Color.Allocate(255, 255, 255)
>
> ... on the second call to Color property i get memory could not be read
> error.
>
> has this something to do with reference counting and have can i resolve
it?
>
> thanx,
>
> Daniel
>
> ----------------------------------------------------------------
> Users Guide http://msdn.microsoft.com/workshop/essentials/mail.asp
> contains important info. Save time, search the archives at
> http://discuss.microsoft.com/archives/index.html .
> To unsubscribe, mailto:DCOM-signoff-request
DISCUSS.MICROSOFT.COM
>
----------------------------------------------------------------
Users Guide http://msdn.microsoft.com/workshop/essentials/mail.asp
contains important info. Save time, search the archives at
http://discuss.microsoft.com/archives/index.html .
To unsubscribe, mailto:DCOM-signoff-request
DISCUSS.MICROSOFT.COM
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]