Re: Who could help me about smart pointer?
"Lee Tow" <fbjlt@pub3.fz.fj.cn> wrote in message
news:OrGgJxdeHHA.4564@TK2MSFTNGP03.phx.gbl
There is a method Add and interface ISMath In my compont using
ATL,but when I
compile my client software ,it always display:
error C2039: 'Add' : is not a member of 'CComPtr<struct ISMath>'
CComPtr<ISMath> *pISMath;
There's no point declaring a pointer to a smart pointer. Make it
CComPtr<ISMath> pISMath;
Everything else below would just work with this change.
pISMath->Add(1,2,&rst);
cout<<rst<<endl;
CoUninitialize();
Make sure to release the object before calling CoUninitialize - like
this:
pISMath.Release();
CoUninitialize();
Otherwise, CComPtr will call Release automatically when it goes out of
scope, which would be at the closing curly brace of main(), which would
be after CoUninitialize has already been called. It's illegal to make
any COM calls after CoUninitialize, and if you do your program will
likely crash.
Alternatively, organize your code in such a way that CComPtr's scope
ends before CoUninitialize is called. E.g. by introducing an extra pair
of braces, or moving the code between CoInitialize and CoUninitialize
into a separate function.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925