OpenDoc6 from C++

Discussion in 'SolidWorks' started by Rich, May 7, 2004.

  1. Rich

    Rich Guest

    I am working on an external C++ module to load SolidWorks with a
    specified Drawing, and then perform operations on it. A VB versoin
    seems to work ok, but from C++ (.net version 7.1.3088), I don't get
    valid returns from the OpenDoc6 call.

    The symptoms I see are that SolidWorks starts (appears in Task
    Manager), grows somewhat in memory usage when the OpenDoc6 call is
    made, but then exits after a few moments. The OpenDoc6 call returns
    hres of S_OK, zero values in the error or warning values, and a null
    value for the IModelDoc2 return pointer.

    Code snippet is as follows:

    CoInitialize(NULL);
    CComPtr<ISldWorks> swApp;
    CComPtr<IModelDoc2> swModel;
    HRESULT hres = swApp.CoCreateInstance(__uuidof(SldWorks), NULL,
    CLSCTX_LOCAL_SERVER);
    if (hres != S_OK)
    { cout << "Error starting a SolidWorks session. Exiting..." << endl;
    swApp = NULL; //release COM references
    CoUninitialize();
    return 1;
    }
    long qErrs = 0;
    long qWarn = 0;
    hres = swApp->OpenDoc6( L"C:\\tmp.SolidWorks\\Tutor1.SLDDRW",
    swDocDRAWING,
    swOpenDocOptions_Silent |
    swOpenDocOptions_ReadOnly,
    L"",
    &qErrs,
    &qWarn,
    &swModel );
    ...

    If I substitute get_IActiveDoc2 for OpenDoc6, and use an existing
    instance of SolidWorks, the sample code seems to work ok.

    Anybody else been successful in using OpenDoc6 from an external C++
    app?
     
    Rich, May 7, 2004
    #1
  2. all I can say is that it works from within an add-in.

    stupid (friday) questions :

    1) are you sure the file exists ? (there is no FileDoesntExist
    error/warning...)

    2) did you try without the Silent option ?
     
    Philippe Guglielmetti, May 7, 2004
    #2
  3. Rich

    Rich Guest

    2) Yes, I'm sure the file exists, the strangest part is that both the
    warning and error variables are left with a zero value, and the hres
    return value is S_OK. But SolidWorks then exits<sigh>.

    I'll try without the silent option.
     
    Rich, May 7, 2004
    #3
  4. Rich

    Rich Guest

    SolidWorks support supplied the answer to this, you can't pass literal
    strings in this api. Needed to have set up the test call as follows:

    CComBSTR bsFile(_T("C:\\tmp.SolidWorks\\Tutor1.SLDDRW")) ;
    CComBSTR bsConfig (_T("")) ;
    hres = swApp->OpenDoc6( bsFile,
    swDocDRAWING,
    swOpenDocOptions_Silent
    | swOpenDocOptions_ReadOnly,
    bsConfig,
    &qErrs,
    &qWarn,
    &swModel );

    Works fine now...
     
    Rich, May 10, 2004
    #4
  5. ouch! how much time lost on such a stupid / incoherent problem ?
    Move to a real OO standard clean API wrapper : www.cadoo.com ;-)
     
    Philippe Guglielmetti, May 10, 2004
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.