Use of SmartPointer CComPtr in ATL programming
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Use of SmartPointer CComPtr in ATL programming

  1. #1
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    5

    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

  2. #2
    Join Date
    May 2002
    Posts
    485
    This works for me.

    CComPtr<IMyInterface> pMyInterface;
    hr = pMyInterface.CoCreateInstance(CLSID_MyInterface);

  3. #3
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    5
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center