在PIESDK中调用envi函数时注册Interop.COM_IDL_connectLib.dll
在PIESDK开发中我们偶尔会使用到envi的一些函数或者算法需要进行调用。
方式①:通过cmd.exe进行注册
先找到我们regsvr32.exe的位置,参考路径:C:\Windows\System32\regsvr32.exe
再找到需要注册的COM_idl_connect.dll的位置,参考路径:C:\Program Files\Exelis\IDL85\resource\bridges\export\COM\COM_idl_connect.dll
打开cmd.exe输入:C:\Windows\System32\regsvr32.exe "C:\Program Files\Exelis\IDL85\resource\bridges\export\COM\COM_idl_connect.dll"
方式②:通过代码方式进行注册
先在引用中添加Interop.COM_IDL_connectLib.dll
再加入Microsoft.Win32和System.Runtime.InteropServices命名空间
using System.Runtime.InteropServices;
using Microsoft.Win32;
再加入DLLImport和方法
[DllImport("COM_idl_connect.dll")]
public static extern int DllRegisterServer();//注册时用
[DllImport("COM_idl_connect.dll")]
public static extern int DllUnregisterServer();//删除注册时用
最后只要在调用之前执行以下代码即可
//注册COM_IDL_connectClass
RegistryKey rkTest = Registry.ClassesRoot.OpenSubKey("CLSID\\{CFE4DC3F-F78E-4CA8-8586-84B3E6F12437}\\");
if (rkTest == null)
{
if (DllRegisterServer() >= 0){ MessageBox.Show("注册成功!"); }
else { MessageBox.Show("注册失败!"); }
}
//DllUnregisterServer();删除注册
若注册失败可能是未获取管理员权限。