Using Cadlib with C#
-
I am slowly going nuts trying to make this work. I can compile the CADIO.dll in Visual Studio 2003, and have the exported functions list (from http://www.codeproject.com/library/cadlib.asp). I am trying to call the DLL using the sample code as below ___________________________________________________________________________ namespace BC_Imager { using System; using System.Windows.Forms; using System.Drawing; using System.Runtime.InteropServices; public class FormDXF : System.Windows.Forms.Form { [DllImport("CadIO.dll")] static extern bool drvCreate(string filename,bool overwrite); } } ____________________________________________________________________________ but having problems getting my head around how to use this DLL in C# to carry out the functions demonstrated in the test.cpp code. Can anyone please give me some pointers, especially in the use in C# of window items generated in MFC (i.e the progress and output "drawing" window in this DLL) Many Thanks for your help Regards
-
I am slowly going nuts trying to make this work. I can compile the CADIO.dll in Visual Studio 2003, and have the exported functions list (from http://www.codeproject.com/library/cadlib.asp). I am trying to call the DLL using the sample code as below ___________________________________________________________________________ namespace BC_Imager { using System; using System.Windows.Forms; using System.Drawing; using System.Runtime.InteropServices; public class FormDXF : System.Windows.Forms.Form { [DllImport("CadIO.dll")] static extern bool drvCreate(string filename,bool overwrite); } } ____________________________________________________________________________ but having problems getting my head around how to use this DLL in C# to carry out the functions demonstrated in the test.cpp code. Can anyone please give me some pointers, especially in the use in C# of window items generated in MFC (i.e the progress and output "drawing" window in this DLL) Many Thanks for your help Regards
Specifically I am trying to open a file using a call ________________________________________________________________________ string filetoget="H:\test.dxf"; [DllImport("CadIO.dll")] static extern bool drvLoadDataFromFile(IntPtr boxhandle,IntPtr NULL, IntPtr NULL ,string filetoget); ________________________________________________________________________ But C# complains "The parameter name 'NULL' is a duplicate" the C++ DLL Exported Interface is BOOL drwLoadDataFromFile( HDRAWING hDrawing, // handle to the current DRAWING structure OBJHANDLE BlockObjhandle, // handle of block that entities must be put in it. (NULL = Entity Section) DWORD Reserved, // reserved, must be 0 LPCTSTR strFileName // input file name (Can not be NULL) ); Thanks in advance
-
Specifically I am trying to open a file using a call ________________________________________________________________________ string filetoget="H:\test.dxf"; [DllImport("CadIO.dll")] static extern bool drvLoadDataFromFile(IntPtr boxhandle,IntPtr NULL, IntPtr NULL ,string filetoget); ________________________________________________________________________ But C# complains "The parameter name 'NULL' is a duplicate" the C++ DLL Exported Interface is BOOL drwLoadDataFromFile( HDRAWING hDrawing, // handle to the current DRAWING structure OBJHANDLE BlockObjhandle, // handle of block that entities must be put in it. (NULL = Entity Section) DWORD Reserved, // reserved, must be 0 LPCTSTR strFileName // input file name (Can not be NULL) ); Thanks in advance
Think I have cracked it - I needed to pass variable not constants The code [DllImport("CadIO.dll")] static extern bool drvLoadDataFromFile(IntPtr boxhandle,IntPtr NULL, int nonum ,string filetoget); compiled OK, whether it will work at runtime is another matter :sigh:
-
Think I have cracked it - I needed to pass variable not constants The code [DllImport("CadIO.dll")] static extern bool drvLoadDataFromFile(IntPtr boxhandle,IntPtr NULL, int nonum ,string filetoget); compiled OK, whether it will work at runtime is another matter :sigh:
Well for the calls _______________________________________ [DllImport("CadIO.dll")] static extern bool drwCreate(); [DllImport("CadIO.dll")] static extern bool drwLoadDataFromFile(IntPtr boxhandle,int npoint,int nonum ,string filetoget); [DllImport("CadIO.dll")] static extern bool drwInitView(int top1,int left1, int bottom1, int right1); [DllImport("CadIO.dll")] static extern int drwPaint(IntPtr boxhandle); ___________________________________________________ And calling it with ____________________________________________________ private void button1_Click(object sender, System.EventArgs e) { bool step1=drwCreate(); bool step2=drwLoadDataFromFile(dxfBox.Handle, 0 ,0,"H:\test.dxf"); bool step3=drwInitView(1,1,200,300); } __________________________________________________________ worked OK for step 1 -drwCreate() but returned false (no exceptions though) but returned faklse for steps 2 & 3
-
Well for the calls _______________________________________ [DllImport("CadIO.dll")] static extern bool drwCreate(); [DllImport("CadIO.dll")] static extern bool drwLoadDataFromFile(IntPtr boxhandle,int npoint,int nonum ,string filetoget); [DllImport("CadIO.dll")] static extern bool drwInitView(int top1,int left1, int bottom1, int right1); [DllImport("CadIO.dll")] static extern int drwPaint(IntPtr boxhandle); ___________________________________________________ And calling it with ____________________________________________________ private void button1_Click(object sender, System.EventArgs e) { bool step1=drwCreate(); bool step2=drwLoadDataFromFile(dxfBox.Handle, 0 ,0,"H:\test.dxf"); bool step3=drwInitView(1,1,200,300); } __________________________________________________________ worked OK for step 1 -drwCreate() but returned false (no exceptions though) but returned faklse for steps 2 & 3
-
This is an old code, but did you get the CadIO.dll to work with C#. I am trying now and any help would be appreciated.