ASE, SQL, OLE, ADE

ASE, SQL, OLE, ADE

Reply
New Member
1 Posts
0 Kudos
Registered: ‎11-23-2010
Post 1 of 1

Documents.Open throws exception in Acad 2011

610 Views, 0 Replies
11-23-2010 09:25 AM

Hi All,


I am trying to open dwg document from external application using code below.

Open instruction throws exception and I have no idea what is wrong. This code works okay in Acad 2010.


Please help!

Dmitry.

 

#import <C:\Program Files\Common Files\Autodesk Shared\acax18enu.tlb>


dwg_open (char *dwgFileSpec)
{
  IAcadApplicationPtr p_app;
  IAcadDocumentsPtr p_docs;
  IAcadDocumentPtr p_doc;

  IUnknownPtr spUnk;
  HRESULT h_res = 0;

  CLSID clsid;
  LPUNKNOWN p_unk;
  IDispatch* p_disp;

  try
  {
    OleInitialize (NULL);

    CLSIDFromProgID (L"Autocad.Application", &clsid);

    // Check if AutoCad is already running.
    if (GetActiveObject (clsid, NULL, &p_unk) == S_OK)
    {
      p_unk->QueryInterface (IID_IDispatch, (void**) &p_disp);
    }
    else
    {
      CoCreateInstance (clsid, NULL, CLSCTX_LOCAL_SERVER, IID_IDispatch, (void **)&p_disp);
    }

    if (p_disp == NULL) return 1;

    h_res = p_disp->QueryInterface(IID_IAcadApplication, (void**)&p_app);

    if (h_res != S_OK) return 1;

    p_app->put_Visible(true);

    p_docs = p_app->GetDocuments();

    p_doc = p_docs->Open (_bstr_t (dwgFileSpec)); //PROBLEM IS HERE!!!
  }
  catch (_com_error &e)
  {
    return 1;
  }

  return 0;
}

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!