最近在使用Visual Studio 2017对中望CAD进行二次开发时,当使用"Marshal.GetActiveObject"函数连接对象时,总是提示下图中的报错:
Google了一下发现了一个帖子中提到:
If you have UAC on, and your application requests administrator privilege to run, then it can not access the registry of HKEY_CURRENT_USER, and Inventor has some registry values in HKEY_CURRENT_USER for the CreateInstance to work, so your application would fail in this case, and if you run it as standard user privilege it would work. So I suggest in this case you just run your application in standard user privilege.
帖子链接:
Not able to create inventor instance when Visual studio in Admin mode - Autodesk Community
也就是说,调试时,ZWCAD和vs2017都不要【以管理员身份运行】,因为我的电脑本身就是以管理员账号登录的,所以vs2017无法通过传统方式去掉【以管理员身份运行】的设置。研究了两天,Google了一堆帖子,最终完美解决了此问题,解决方案分享如下:
1.win+R输入:regedit打开注册表,浏览到:计算机\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
2.在空白处右键新建【字符串值】
3.将【数值名称】改为:C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe
将【数值数据】改为:~ RUNASINVOKER
说明:如果需要将vs2017默认改为【以管理员身份运行】
则需要将【数值数据】改为:~ RUNASADMIN