ASE, SQL, OLE, ADE

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

Documents.Open throws exception in Acad 2011

534 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;
}

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community