我試圖創建一個獨立的Solidworks應用程序(我想讓我的C++程序在後臺運行的Solidworks中創建新的幾何體)。我使用的是MSVC++表示2010年在C++中創建獨立的Solidworks應用程序
我試圖實現下面的代碼suggested here
//Import the SolidWorks type library
#import "sldworks.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids
//Import the SolidWorks constant type library
#import "swconst.tlb" raw_interfaces_only, raw_native_types, no_namespace, named_guids
int _tmain(int argc, _TCHAR* argv[])
{
//Initialize COM
CoInitialize(NULL);
//Use ATL smart pointers
CComPtr<ISldWorks> swApp;
//Create an instance of SolidWorks
HRESULT hres = swApp.CoCreateInstance(__uuidof(SldWorks), NULL, CLSCTX_LOCAL_SERVER);
//My Code here
//Shut down SolidWorks
swApp->ExitApp();
// Release COM reference
swApp = NULL;
//Uninitialize COM
CoUninitialize();
return 0;
}
它不抱怨的導入語句庫,但它不會建立由於以下錯誤:
1>main.cpp(19): error C2065: 'CComPtr' : undeclared identifier
1>main.cpp(19): error C2275: 'ISldWorks' : illegal use of this type as an expression
1> c:\users\nolan\documents\c++\solidworks_test\solidworks_test\debug\sldworks.tlh(7515) : see declaration of 'ISldWorks'
1>main.cpp(19): error C2065: 'swApp' : undeclared identifier
1>main.cpp(22): error C2065: 'swApp' : undeclared identifier
1>main.cpp(22): error C2228: left of '.CoCreateInstance' must have class/struct/union
1> type is ''unknown-type''
1>main.cpp(26): error C2065: 'swApp' : undeclared identifier
1>main.cpp(26): error C2227: left of '->ExitApp' must point to class/struct/union/generic type
1> type is ''unknown-type''
1>main.cpp(29): error C2065: 'swApp' : undeclared identifier
顯然我失去了一些東西,但我無法弄清楚是什麼。我覺得它與ATL有關,但我不確定...請幫助。
感謝
編輯:
好,我下載的Windows開發工具包8.0,所有的文件都在那裏。我已經在屬性頁中靜態鏈接到ATL,我也嘗試鏈接目錄中的庫文件:C:\Program Files\Windows Kits\8.0\Lib\Atl
但是這些頭文件無處可查...請幫助。
它看起來像你試圖使用ATL類型,而不包括定義這些類型的ATL頭文件(atlbase.h)。 – 2013-02-28 21:45:26
看看這個[鏈接](http://stackoverflow.com/questions/2681050/atlbase-h-not-found-when-using-visual-c-express-2010),看到它有助於使項目編譯 – 2013-03-19 10:42:08
我其實剛剛結束了使用Visual Studio 2010,它解決了。我只是想找點時間來回答這個問題。 – NauticalMile 2013-03-22 15:57:58