zoukankan      html  css  js  c++  java
  • CAD 二次开发 -- 自动加载开发的DLL

    CAD二次开发可以采用写扩展DLL的方式实现。该DLL的函数可以被CAD调用。

    但是调用前,必须用命令netload 将该dll加载到CAD。

    其实可以修改注册表,当CAD软件启动后,自动加载扩展DLL。

    为此,我写了一个函数,很方便的修改注册表,达到自动加载dll的目的!

    该函数支持各个版本cad。

    
    

    string[] GetRegSubDir(RegistryKey autoCad, string startFlag)
    {
    string[] subKey = autoCad.GetSubKeyNames();
    return subKey.Where(o => o.StartsWith(startFlag)).ToArray();
    }


    1
    //strCadRegKey = "HLD_CAD_Import"; //唯一注册标识 可用公司名称和程序名称 2 //strDll dll文件路径 3 private bool WriteRegistryKey(string strDll,string strCadRegKey) 4 { 5 try 6 { 7 RegistryKey localMachine = Registry.LocalMachine; 8 RegistryKey SOFTWARE = localMachine.OpenSubKey("SOFTWARE", true); 9 RegistryKey Autodesk = SOFTWARE.OpenSubKey("Autodesk", true); 10 RegistryKey AutoCAD = Autodesk.OpenSubKey("AutoCAD", true); 11 12 int result = 0; 13 foreach (string subDir in GetRegSubDir(AutoCAD, "R")) 14 { 15 try 16 { 17 RegistryKey CadVersion = AutoCAD.OpenSubKey(subDir, true); 18 19 string AcadVersion = GetRegSubDir(CadVersion, "ACAD-").FirstOrDefault(); 20 RegistryKey ACAD = CadVersion.OpenSubKey(AcadVersion, true); 21 22 RegistryKey Applications = ACAD.OpenSubKey("Applications", true); 23 24 //删除旧有记录 25 try 26 { 27 Applications.DeleteSubKeyTree(strCadRegKey); 28 } 29 catch (Exception ex) 30 { } 31 32 RegistryKey MXCAD = Applications.CreateSubKey(strCadRegKey); 33 MXCAD.SetValue("LOADCTRLS", 0x02); 34 MXCAD.SetValue("LOADER", strDll); 35 MXCAD.SetValue("MANAGED", 0x01); 36 result++; 37 } 38 catch (Exception ex) 39 { 40 if (showMessage) 41 System.Windows.Forms.MessageBox.Show(string.Format("注册时出错!{0}", ex.Message)); 42 } 43 } 44 45 if (result > 0 && showMessage) 46 System.Windows.Forms.MessageBox.Show(string.Format("注册成功!")); 47 return true; 48 } 49 catch (Exception ex) 50 { 51 52 return false; 53 } 54 }

    技术交流联系qq 13712486

  • 相关阅读:
    update语句
    java List和数组相互转换方法
    mysql查最大字符串
    Mybatis各种模糊查询
    mysql 递归查询父节点 和子节点
    String类型根据逗号分隔转为list
    This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de 错误解决办法
    java中String数组和List的互相转化
    实现List集合中数据逆序排列
    String字符串去掉双引号
  • 原文地址:https://www.cnblogs.com/yuanchenhui/p/cad_auto_load.html
Copyright © 2011-2022 走看看