Using a C++ dll in VB.net
-
There is an excellent library here on CodeProject contributed by Omid Shahabi called CadLib for creating viewing and modifying dxf(Drawing Interchange Format) files I am attempting to use this C++ library in VB.Net and have started to write the declare functions to do so - example follows ____________________________________________________________________________ Private Declare Function drwCreate Lib "CADIO" () As Long Private Declare Function drwInitView Lib "CADIO" (ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal Nheight As Integer) As Boolean Private Declare Function drwLoadDataFromFile Lib "CADIO" (ByVal Handle As Long, ByVal BlockHandle As Long, ByVal Res0 As Integer, ByVal Filename As String, ByVal ProgHandle As Long) As Boolean Private Declare Function drwSaveDataToFile Lib "CADIO" (ByVal Handle As Long, ByVal Res0 As Integer, ByVal Filename As String, ByVal ProgHandle As Long) As Boolean Private Declare Function drwPaint Lib "CADIO" (ByVal drwhandle As Long) As Boolean ____________________________________________________________________________ The dwfCreate worked well, returning a (long integer) handle But I am having trouble figuring out how to pass null values where required (i.e in drwLoadDataFromFile) and how to handle the C++ "progress window handle") Do any experts out there have any suggestions of how to use this library in VB.net to display a dxf file (as in the C++ test program) Many Thanks
-
There is an excellent library here on CodeProject contributed by Omid Shahabi called CadLib for creating viewing and modifying dxf(Drawing Interchange Format) files I am attempting to use this C++ library in VB.Net and have started to write the declare functions to do so - example follows ____________________________________________________________________________ Private Declare Function drwCreate Lib "CADIO" () As Long Private Declare Function drwInitView Lib "CADIO" (ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal Nheight As Integer) As Boolean Private Declare Function drwLoadDataFromFile Lib "CADIO" (ByVal Handle As Long, ByVal BlockHandle As Long, ByVal Res0 As Integer, ByVal Filename As String, ByVal ProgHandle As Long) As Boolean Private Declare Function drwSaveDataToFile Lib "CADIO" (ByVal Handle As Long, ByVal Res0 As Integer, ByVal Filename As String, ByVal ProgHandle As Long) As Boolean Private Declare Function drwPaint Lib "CADIO" (ByVal drwhandle As Long) As Boolean ____________________________________________________________________________ The dwfCreate worked well, returning a (long integer) handle But I am having trouble figuring out how to pass null values where required (i.e in drwLoadDataFromFile) and how to handle the C++ "progress window handle") Do any experts out there have any suggestions of how to use this library in VB.net to display a dxf file (as in the C++ test program) Many Thanks
If you create a form, you can get the window handle from it, it's a property. Isn't Nothing the same as null ? If not, then just pass 0, a pointer with a value of 0 is null in C++. Christian Graus - Microsoft MVP - C++
-
If you create a form, you can get the window handle from it, it's a property. Isn't Nothing the same as null ? If not, then just pass 0, a pointer with a value of 0 is null in C++. Christian Graus - Microsoft MVP - C++
-
Thanks Christian, I will try passing 0 as an integer value where I need a null sent to the C++ dll. For the handle to the "progress form" I take it that i would create a form in VB.Net and pass it's handle to the file open as shown. Regards
Reanalyse wrote: For the handle to the "progress form" I take it that i would create a form in VB.Net and pass it's handle to the file open as shown. I'd assume they need the form to have a progress bar on it with a specific ID, so that it can use it to update it's progress. I'd also hope you could pass null ( IntPtr.Null probably exists for this purpose ), and not have a progress dialog at all. It's IntPtr.Zero ( I just checked ), so I'd try passing that rather than a straight 0, where Null is concerned. Christian Graus - Microsoft MVP - C++
-
Reanalyse wrote: For the handle to the "progress form" I take it that i would create a form in VB.Net and pass it's handle to the file open as shown. I'd assume they need the form to have a progress bar on it with a specific ID, so that it can use it to update it's progress. I'd also hope you could pass null ( IntPtr.Null probably exists for this purpose ), and not have a progress dialog at all. It's IntPtr.Zero ( I just checked ), so I'd try passing that rather than a straight 0, where Null is concerned. Christian Graus - Microsoft MVP - C++
Thanks Christian I have got a long way down the track thanks to your help I have got this far Am I passing the correct way to a VC++ DLL from VB.NET ? ------------------------------------------------------------------------------ Structure PVIEW '// View Structure ********************************************** 'typedef struct tag_VIEW '{ 'BOOL Viewable; // TRUE = Drawing can be viewed 'int WindowLeft; // Drawing Window Boundary Properties (In Pixels) 'int WindowTop; // Drawing Window Boundary Properties (In Pixels) 'int WindowRight; // Drawing Window Boundary Properties (In Pixels) 'int WindowBottom; // Drawing Window Boundary Properties (In Pixels) 'double ViewLeft; // Drawing View Properties (In Units) 'double ViewBottom; // Drawing View Properties (In Units) 'double ViewRight; // Drawing View Properties (In Units) 'double ViewTop; // Drawing View Properties (In Units) 'double PPU; // Pixels Per Unit 'double ZoomLevel; // Zoom Level '} VIEW, *PVIEW; Public Viewable As Boolean Public WindowLeft As Integer Public WindowTop As Integer Public WindowRight As Integer Public WindowBottom As Integer Public ViewLeft As Double Public ViewBottom As Double Public ViewRight As Double Public ViewTop As Double Public PPU As Double Public ZoomLevel As Double End Structure Public Class Form1 Inherits System.Windows.Forms.Form Public Declare Function drwCreate Lib "CADIO" () As Long 'Exported Function drwCreate 'BOOL Create( ); Private Declare Function drwLoadDataFromFile Lib "CADIO" (ByVal Handle As Long, ByVal Handle1 As Long, ByVal Res0 As Integer, ByVal Filename As String, ByVal Handle2 As Long) As Boolean 'Exported Function drwLoadDataFromFile 'BOOL (*drwLoadDataFromFile)( HDRAWING hDrawing, OBJHANDLE BlockObjhandle, DWORD Reserved, LPCTSTR strFileName, HWND hWndProgress ); Public Declare Function drwInitView Lib "CADIO" (ByVal Handle As Long, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal Nheight As Integer) As Boolean 'Exported Function form DLL =drwInitView 'Public BOOL InitView( int x, int y, int nWidth, int nHeight ); Private Declare Function drwPaint Lib "CADIO" (ByVal drwhandle As Long) As Boolean Private Declare Function dxfSetCurrentColor Lib "CADIO" (ByVal drwhandle As Long, ByVal Color As Integer) As Boolean Private Declare Function drwGetViewProperties Lib "C
-
Thanks Christian I have got a long way down the track thanks to your help I have got this far Am I passing the correct way to a VC++ DLL from VB.NET ? ------------------------------------------------------------------------------ Structure PVIEW '// View Structure ********************************************** 'typedef struct tag_VIEW '{ 'BOOL Viewable; // TRUE = Drawing can be viewed 'int WindowLeft; // Drawing Window Boundary Properties (In Pixels) 'int WindowTop; // Drawing Window Boundary Properties (In Pixels) 'int WindowRight; // Drawing Window Boundary Properties (In Pixels) 'int WindowBottom; // Drawing Window Boundary Properties (In Pixels) 'double ViewLeft; // Drawing View Properties (In Units) 'double ViewBottom; // Drawing View Properties (In Units) 'double ViewRight; // Drawing View Properties (In Units) 'double ViewTop; // Drawing View Properties (In Units) 'double PPU; // Pixels Per Unit 'double ZoomLevel; // Zoom Level '} VIEW, *PVIEW; Public Viewable As Boolean Public WindowLeft As Integer Public WindowTop As Integer Public WindowRight As Integer Public WindowBottom As Integer Public ViewLeft As Double Public ViewBottom As Double Public ViewRight As Double Public ViewTop As Double Public PPU As Double Public ZoomLevel As Double End Structure Public Class Form1 Inherits System.Windows.Forms.Form Public Declare Function drwCreate Lib "CADIO" () As Long 'Exported Function drwCreate 'BOOL Create( ); Private Declare Function drwLoadDataFromFile Lib "CADIO" (ByVal Handle As Long, ByVal Handle1 As Long, ByVal Res0 As Integer, ByVal Filename As String, ByVal Handle2 As Long) As Boolean 'Exported Function drwLoadDataFromFile 'BOOL (*drwLoadDataFromFile)( HDRAWING hDrawing, OBJHANDLE BlockObjhandle, DWORD Reserved, LPCTSTR strFileName, HWND hWndProgress ); Public Declare Function drwInitView Lib "CADIO" (ByVal Handle As Long, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal Nheight As Integer) As Boolean 'Exported Function form DLL =drwInitView 'Public BOOL InitView( int x, int y, int nWidth, int nHeight ); Private Declare Function drwPaint Lib "CADIO" (ByVal drwhandle As Long) As Boolean Private Declare Function dxfSetCurrentColor Lib "CADIO" (ByVal drwhandle As Long, ByVal Color As Integer) As Boolean Private Declare Function drwGetViewProperties Lib "C
A BOOL is in fact a typedef for an int, pass 0 for false, 1 for true. It's used in APIs that are to be called from C, as C does not have a boolean type. Are you declaring your handles as IntPtr ( can you access that type in VB.NET ) ? Christian Graus - Microsoft MVP - C++
-
A BOOL is in fact a typedef for an int, pass 0 for false, 1 for true. It's used in APIs that are to be called from C, as C does not have a boolean type. Are you declaring your handles as IntPtr ( can you access that type in VB.NET ) ? Christian Graus - Microsoft MVP - C++
-
Changed both of those (you can use IntPtr in VB.Net but ")" as boolean came as a surprise :-0),the code previously still will not work with the changes. Thanks
Reanalyse wrote: boolean came as a surprise Yeah, it's definately a trap. Reanalyse wrote: the code previously still will not work with the changes. To be honest, anything else I suggest will just be a stab in the dark. If it were me, I'd be trying to use the dll in C++, then if I got that to work successfully, I'd be trying to move it to VB.NET. If it was usable in C++ and hard to use in VB.NET, I'd wrap it in a C++ COM project, and call that from VB.NET. Christian Graus - Microsoft MVP - C++