|
-
March 7th, 2003, 10:32 AM
#1
Use of SmartPointer CComPtr in ATL programming
I want to create an instance of an automation server program (s.a.excel) with SmartPointer from ATL program.
I have imported the tlb libraries with the import statement
#import "caxolesrv.tlb" raw_native_types, no_namespace, named_guids
CComPtr<ICaxOleSrv> m_CaxOleSrv;
What do I have to do to get a new instance of automation server and start it automaticly. With MFC OLE I can use CreateObject(..) but in ATL I cannot find a equivalent function.
To get it without smart pointer was also not succesful
CLSID clsid;
HRESULT hr = -10;
IDispatch *pDisp = NULL;
CLSIDFromProgID(L"CaxOleSrv.Application",&clsid);
hr = CoCreateInstance(clsid, NULL, CLSCTX_ALL, IID_IDispatch, (void**)&pDisp);
Thanks for your help,
Thomas
-
March 7th, 2003, 04:28 PM
#2
This works for me.
CComPtr<IMyInterface> pMyInterface;
hr = pMyInterface.CoCreateInstance(CLSID_MyInterface);
-
March 7th, 2003, 04:52 PM
#3
Tron,
the solution is the following line:
hr = m_iCaxOleSrv.CoCreateInstance(clsid, NULL, CLSCTX_LOCAL_SERVER);
this does not work:
hr = m_iCaxOleSrv.CoCreateInstance(clsid, NULL, CLSCTX_ALL);
My be this is a bug.
THanks,
Thomas
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|