CAD Secondary Development--Automatic Loading of Developed DLL

Posted by benkillin on Fri, 17 Jul 2020 17:17:54 +0200

CAD secondary development can be achieved by writing extended DLLs.The function of the DLL can be called by the CAD.

However, before calling it, you must load the dll into CAD with the command netload.

Actually, you can modify the registry and automatically load the extended DLL when the CAD software starts.

For this reason, I have written a function to easily modify the registry to achieve the purpose of loading DLLs automatically!

This function supports various versions of cad.

 1 //strCadRegKey = "HLD_CAD_Import"; //Unique Registration Identification Available Company and Program Names
 2 //strDll dll File Path
 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                         //Delete old records
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("Error registering!{0}", ex.Message));
42                     }
43                 }
44 
45                 if (result > 0 && showMessage)
46                     System.Windows.Forms.MessageBox.Show(string.Format("Registration successful!"));
47                 return true;
48             }
49             catch (Exception ex)
50             {
51               
52                 return false;
53             }
54         }

Technical Communication Contact qqq 13712486

Topics: C# Windows