ASE, SQL, OLE, ADE

ASE, SQL, OLE, ADE

Reply
New Member
dmitryy
Posts: 1
Registered: ‎11-23-2010
Message 1 of 1 (603 Views)

Documents.Open throws exception in Acad 2011

603 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
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.