Re: CreateInstance
Well, technically you don't need it before each CreateInstance.
You only need to call CoInitialize[Ex] once per thread (and
match that with CoUninitialize when finished with COM). So
if somebody else called it before your code you'll be fine without.
--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnickolov@mvps.org
MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================
"Brian Muth" <bmuth@mvps.org> wrote in message
news:%23oWJ8ZCgGHA.2172@TK2MSFTNGP04.phx.gbl...
<jean_cai@yahoo.com> wrote in message
news:1148577227.009503.190130@u72g2000cwu.googlegroups.com...
Hi,
I have an exe com. I have two questions.
1. After I create an instance:
IXserverPtr _pServer;
_pServer.CreateInstance(CLSID_Xserver);
Do I need to release like this _pServer.Release() ?
No, it's not necessary. IXserverPtr is a "smart" pointer. The destructor
will automatically call Release() for you when the variable goes out of
scope.
2. Do I need CoInitialize(NULL) before CreateInstance?
Yes.
Why it still
works if I don't have CoInitilzie?
No, it won't work. Look at the HRESULT returned by
_pServer.CreateInstance(CLSID_Xserver);
Brian