OpenDoc6 from C++

May 07, 2004 4 Replies

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 swApp; CComPtr swModel; HRESULT hres = swApp.CoCreateInstance(__uuidof(SldWorks), NULL, CLSCTX_LOCAL_SERVER); if (hres != S_OK) { cout


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 ?

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.

I'll try without the silent option.

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...

ouch! how much time lost on such a stupid / incoherent problem ? Move to a real OO standard clean API wrapper :

formatting link
;-)

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required