Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Using a C++ dll in VB.net

Using a C++ dll in VB.net

Scheduled Pinned Locked Moved Visual Basic
tutorialcsharpc++graphics
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Reanalyse
    wrote on last edited by
    #1

    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

    C 1 Reply Last reply
    0
    • R Reanalyse

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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++

      R 1 Reply Last reply
      0
      • C Christian Graus

        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++

        R Offline
        R Offline
        Reanalyse
        wrote on last edited by
        #3

        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

        C 1 Reply Last reply
        0
        • R Reanalyse

          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

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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++

          R 1 Reply Last reply
          0
          • C Christian Graus

            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++

            R Offline
            R Offline
            Reanalyse
            wrote on last edited by
            #5

            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

            C 1 Reply Last reply
            0
            • R Reanalyse

              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

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              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++

              R 1 Reply Last reply
              0
              • C Christian Graus

                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++

                R Offline
                R Offline
                Reanalyse
                wrote on last edited by
                #7

                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

                C 1 Reply Last reply
                0
                • R Reanalyse

                  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

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  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++

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups