几何尺寸与公差论坛

 找回密码
 注册
查看: 2544|回复: 1

1-376578754- How to connect SW with a floating license via OLE Automation?

[复制链接]
发表于 2007-9-3 23:54:14 | 显示全部楼层 |阅读模式
1-376578754- How to connect SW with a floating license via OLE Automation?
Hi,
If SW is running in the foreground and is visible, are there other OLE functions or ways to catch and connect SW? (My current way is that of m_pSldWorks.CreateDispatch(_T("SldWorks.Application"));) Sometimes my customers need network to connect SW with a floating license.
Yanhua
 楼主| 发表于 2007-9-3 23:54:56 | 显示全部楼层

回复: 1-376578754- How to connect SW with a floating license via OLE Automati

Dear Yanhua,

Please see below for the answers to your queries:

-->Visual Basic 6.0 Standalone and Add-in Applications:

Your project can either attach to a running instance of the SolidWorks software by calling the Visual Basic GetObject method or open a new instance of the SolidWorks software by calling the Visual Basic CreateObject method. Lines of code similar to the following must appear in your project.

Sub main()
   Dim swApp as SldWorks.SldWorks
   ' Attach to running instance of SolidWorks software
   Set swApp = GetObject(, "SldWorks.Application")
   swApp.ExitApp
   Set swApp = Nothing
End Sub
- or -
Sub main()
   Dim swApp as SldWorks.SldWorks
   ' Open new instance of SolidWorks software
   Set swApp = CreateObject("SldWorks.Application")
   swApp.ExitApp
   Set swApp = Nothing
End Sub

-->Visual C++ Standalone and Add-in Applications:

To create an instance of the SolidWorks software, your executable project should contain lines of code similar to the following:
    //Import the SolidWorks type library
#import "sldworks.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);     
swApp->ExitApp();
swApp = NULL;
CoUninitialize();
return 0;
}
I hope this helps.

Thanks,
Pabitra
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|小黑屋|几何尺寸与公差论坛

GMT+8, 2024-11-13 14:08 , Processed in 0.096260 second(s), 19 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表