Problem Building a standalone SolidWorks-based application

Discussion in 'SolidWorks' started by arno, Jan 29, 2006.

  1. arno

    arno Guest

    Hello,

    I'm trying to build a standalone application based on SolidWorks
    and I'm facing some problems when I try to use the sample code that is
    included in solidworks API documentation. It seems that I manage to
    launch an instance of SolidWorks but I don't manage to perform further
    operations (like loading an IGES file or getting the ModelDoc object) :
    I get error codes. I post here very simple sample that launches a
    SolidWorks instance but doesn't manage to perform LoadFile2 or
    get_IActiveDoc2 ...

    #include <windows.h>
    #include <stdio.h>
    #include <direct.h>
    #include <tchar.h>



    #include <atlbase.h>


    #import "C:\\Program Files\SolidWorks\\sldworks.tlb"
    raw_interfaces_only, raw_native_types, no_namespace, named_guids
    //Import the SolidWorks type library

    int _tmain(int argc, _TCHAR* argv[])

    {

    CoInitialize(NULL); //Initialize COM

    CComPtr<ISldWorks> swApp; //Use ATL smart pointers

    CComPtr<IModelDoc2> ModelDoc;

    VARIANT_BOOL res;

    HRESULT hres = swApp.CoCreateInstance(__uuidof(SldWorks), NULL,
    CLSCTX_LOCAL_SERVER); //Create an instance of SolidWorks

    hres = swApp->LoadFile2(bstr_t ("a.sldprt"),bstr_t (""),&res);

    hres = swApp->get_IActiveDoc2 (&ModelDoc);


    swApp->ExitApp();

    swApp = NULL;

    CoUninitialize();

    return 0;

    }



    Thanks for your help,
     
    arno, Jan 29, 2006
    #1
  2. arno

    Bob Hanson Guest

    Hello Arno,

    What compiler are you using VC++ 6.0?

    Best regards,

    Bob Hanson
    Senion SolidWorks API Solutions Provider
    Centare Group Ltd.
    www.centare.com
     
    Bob Hanson, Jan 29, 2006
    #2
  3. arno

    arno Guest

    I use VC ++ 6.0 indeed. I think I should try maybe under .NET ?!
     
    arno, Jan 30, 2006
    #3
  4. arno

    Bob Hanson Guest

    Hello Arno,

    It would be much easier :)

    Bob Hanson
    Senior SolidWorks API Solutions Provider
    Centare Group Ltd.
    www.centare.com
     
    Bob Hanson, Jan 31, 2006
    #4
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.