Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: 25 May 2006 10:36:08 -0700,    group: microsoft.public.platformsdk.com_ole        back       


CreateInstance   
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() ?


2. Do I need CoInitialize(NULL) before CreateInstance?  Why it still
works if I don't have CoInitilzie? 


Thanks, 
Jean
date: 25 May 2006 10:36:08 -0700   author:   ZhenCai

Re: CreateInstance   
ZhenCai  wrote:
> 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() ?

You can, but you don't have to. IXserverPtr is a smart pointer class, it 
will automatically release the underlying interface pointer in its 
destructor when _pServer goes out of scope.

> 2. Do I need CoInitialize(NULL) before CreateInstance?

Yes.

> Why it still
> works if I don't have CoInitilzie?

Are you sure your program does not call CoInitialize anywhere? Depending 
on the framework you use, and the wizard you used to originally generate 
the project (if any), chances are high there is a CoInitialize call 
somewhere.
-- 
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
date: Thu, 25 May 2006 13:58:08 -0400   author:   Igor Tandetnik

Re: CreateInstance   
Thanks for reply.

For #2, I searched all code, i could not fine CoInitialize
date: 25 May 2006 11:16:05 -0700   author:   ZhenCai

Re: CreateInstance   
Proposal for experiment:

You can call CoInitializeEx() in two versions of your program with (a) 
APARTMENT_THREADED and (b) MULTITHREADED before you create instance.

If both calls retrurn with S_OK, no CoInitialize has been called before. In 
that case the framework that implements the smartpointer calls probably 
somehow CoInitializeEx.

But I expect, that one calls returns S_FALSE, so any object that you create 
is derived from a class that calls CoInitializeEx. It's not necessary to 
find the call in your source code.

/Helge
date: Fri, 26 May 2006 10:02:56 +0200   author:   Helge Kruse

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us