- 检查dll是否已经注册
检查是否已经注册的代码为:
#region Is dll register public bool IsDllRegistered() { bool reg=true; RegistryKey rk=Registry.ClassesRoot.OpenSubKey("CLSID\\{AC53EFE4-94A7-47E6-BBFC-E9B9CF322299}"); if(rk==null) { MessageBox.Show("未注册"); reg=false; } else { MessageBox.Show("已注册"); } return reg; } #endregion
其中GUID串{AC53EFE4-94A7-47E6-BBFC-E9B9CF322299}为注册dll的Class ID。注册表搜索了半天没有找到,可通过一个名叫RegDllView的小工具进行查找。
- 注册dll控件
#region Open dwg file [DllImport(@"../ja-JP/com/DwgViewX.dll")] private static extern int DllRegisterServer(); private void OpenDwgFile(string savePath) { if(!IsDllRegistered()) { int i = DllRegisterServer(); if (i >= 0) { /* * Inoke special function to open dwg file * */ } else { /* * Register failed and open dwg with CAD * */ System.Diagnostics.Process.Start(savePath); } } } #endregion
其中@"../ja-JP/com/DwgViewX.dll"是你的dll存储的相对路径。注意需要引用名空间:
using System.Runtime.InteropServices; using Microsoft.Win32;
时间: 2024-10-10 18:00:50