Create instance of an com object inside a the Com server 
Author Message
 Create instance of an com object inside a the Com server

what is the best way to create an instance of a com object inside another
object,
the two object are in the same Com server dll.

the way i use now is this :
i want to allocate this pointer IMyObj * pIObj

CComObject<MyObj>* pObj;
CComObject<MyObj>::CreateInstance(&pObj)
pObj->QueryInterface(IID_IMyObj, (void**)&pIObj);
pObj->Release();

pIObj-> ....
and so on
is there another way more effecient

is this right : pIObj = new CComObject<MyObj>;

--
--
best regards
Hatem KNANI



Mon, 14 Jul 2003 22:29:53 GMT  
 Create instance of an com object inside a the Com server
The difference is mainly in the fact that CComObject::CreateInstance calls
FinalConstruct on the newly constructed object, and if that fails, it
deletes the object and returns failed HRESULT. Just using new doesn't call
FinalConstruct (where many objects perform initialization) and doesn't
provide for a way to return failure.

BTW, CreateInstance doesn't increment reference count - you shouldn't call
Release after it.
--
With best wishes,
    Igor Tandetnik


Quote:
> what is the best way to create an instance of a com object inside another
> object,
> the two object are in the same Com server dll.

> the way i use now is this :
> i want to allocate this pointer IMyObj * pIObj

> CComObject<MyObj>* pObj;
> CComObject<MyObj>::CreateInstance(&pObj)
> pObj->QueryInterface(IID_IMyObj, (void**)&pIObj);
> pObj->Release();

> pIObj-> ....
> and so on
> is there another way more effecient

> is this right : pIObj = new CComObject<MyObj>;

> --
> --
> best regards
> Hatem KNANI



Mon, 14 Jul 2003 23:09:43 GMT  
 Create instance of an com object inside a the Com server
Ok Think you for your answer
but is this true :
IMyObj* pIObj;
pIObj = new CComObject<MyObj>;
I use this and the compiler accept it and it works well

but i think they are  two different types
i means that IMyObj and CComObject<MyObj> are different

I dont understand how it works well


Quote:
> The difference is mainly in the fact that CComObject::CreateInstance calls
> FinalConstruct on the newly constructed object, and if that fails, it
> deletes the object and returns failed HRESULT. Just using new doesn't call
> FinalConstruct (where many objects perform initialization) and doesn't
> provide for a way to return failure.

> BTW, CreateInstance doesn't increment reference count - you shouldn't call
> Release after it.
> --
> With best wishes,
>     Igor Tandetnik



> > what is the best way to create an instance of a com object inside
another
> > object,
> > the two object are in the same Com server dll.

> > the way i use now is this :
> > i want to allocate this pointer IMyObj * pIObj

> > CComObject<MyObj>* pObj;
> > CComObject<MyObj>::CreateInstance(&pObj)
> > pObj->QueryInterface(IID_IMyObj, (void**)&pIObj);
> > pObj->Release();

> > pIObj-> ....
> > and so on
> > is there another way more effecient

> > is this right : pIObj = new CComObject<MyObj>;

> > --
> > --
> > best regards
> > Hatem KNANI



Tue, 15 Jul 2003 18:13:25 GMT  
 Create instance of an com object inside a the Com server
A typical ATL coclass implements interfaces by deriving from them, so the
compiler has no problem casting the pointer to the class to the interface
pointer (casting from derived class pointer to base class pointer is almost
always allowed, except in complicated cases like deriving from the same
class twice through multiple inheritance). Remember that this also will not
increment reference counter. Good for internal use only, when you clearly
understand what you're doing.
--
With best wishes,
    Igor Tandetnik


Quote:
> Ok Think you for your answer
> but is this true :
> IMyObj* pIObj;
> pIObj = new CComObject<MyObj>;
> I use this and the compiler accept it and it works well

> but i think they are  two different types
> i means that IMyObj and CComObject<MyObj> are different

> I dont understand how it works well



> > The difference is mainly in the fact that CComObject::CreateInstance
calls
> > FinalConstruct on the newly constructed object, and if that fails, it
> > deletes the object and returns failed HRESULT. Just using new doesn't
call
> > FinalConstruct (where many objects perform initialization) and doesn't
> > provide for a way to return failure.

> > BTW, CreateInstance doesn't increment reference count - you shouldn't
call
> > Release after it.
> > --
> > With best wishes,
> >     Igor Tandetnik



> > > what is the best way to create an instance of a com object inside
> another
> > > object,
> > > the two object are in the same Com server dll.

> > > the way i use now is this :
> > > i want to allocate this pointer IMyObj * pIObj

> > > CComObject<MyObj>* pObj;
> > > CComObject<MyObj>::CreateInstance(&pObj)
> > > pObj->QueryInterface(IID_IMyObj, (void**)&pIObj);
> > > pObj->Release();

> > > pIObj-> ....
> > > and so on
> > > is there another way more effecient

> > > is this right : pIObj = new CComObject<MyObj>;

> > > --
> > > --
> > > best regards
> > > Hatem KNANI



Tue, 15 Jul 2003 23:37:36 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. why Can\'t create COM Instance After registering COM Server Successfully

2. Problem with scripting context when using VB com object inside VC com object

3. Creating COM objects from COM objects

4. running instance of COM object in ATL/MFC server

5. Creating Instances coclasses in another COM server

6. COM Server Instance Created on Each Instantiation?

7. Access to object interfaces inside the COM server?

8. How to enable and create multiple instances of a COM server in ATL

9. Unable to create instance of the COM Object

10. Service trying to create remote COM object instance.

11. Creating an instance of a COM object

12. Creating an instance of a COM object

 

 
Powered by phpBB® Forum Software