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. C / C++ / MFC
  4. Convert C++ DLL to VB.net Help

Convert C++ DLL to VB.net Help

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++help
5 Posts 5 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.
  • N Offline
    N Offline
    nelsonbd
    wrote on last edited by
    #1

    Hi, I am struggling to convert some functions from a C++ DLL to some function references in VB.net I dont program in C++, so I am hoping someone can help me with converting a couple of function prototypes: This are the C++ prototypes: CP2101_Open(DWORD dwDevice, HANDLE* cyHandle); CP2101_GetProductString(DWORD dwDeviceNum, LPVOID lpvDeviceString, DWORD dwFlags); CP2101_Close(HANDLE cyHandle ); This is what i have in vb.net: Public Declare Function CP2101_Open Lib "CP2101.dll" (ByVal DeviceNum As Long, ByRef Handle As Long) As Integer Public Declare Function CP2101_GetProductString Lib "CP2101.dll" (ByVal DeviceNum As Long, ByRef DeviceString As String, ByVal Options As Long) As Integer Public Declare Function CP2101_Close Lib "CP2101.dll" (ByVal DeviceNum As Long) As Integer I am not sure that I am converting the pointer data types correctly etc from C++ to Vb.net. If some could check my work. Thanks Barry

    A A A M 4 Replies Last reply
    0
    • N nelsonbd

      Hi, I am struggling to convert some functions from a C++ DLL to some function references in VB.net I dont program in C++, so I am hoping someone can help me with converting a couple of function prototypes: This are the C++ prototypes: CP2101_Open(DWORD dwDevice, HANDLE* cyHandle); CP2101_GetProductString(DWORD dwDeviceNum, LPVOID lpvDeviceString, DWORD dwFlags); CP2101_Close(HANDLE cyHandle ); This is what i have in vb.net: Public Declare Function CP2101_Open Lib "CP2101.dll" (ByVal DeviceNum As Long, ByRef Handle As Long) As Integer Public Declare Function CP2101_GetProductString Lib "CP2101.dll" (ByVal DeviceNum As Long, ByRef DeviceString As String, ByVal Options As Long) As Integer Public Declare Function CP2101_Close Lib "CP2101.dll" (ByVal DeviceNum As Long) As Integer I am not sure that I am converting the pointer data types correctly etc from C++ to Vb.net. If some could check my work. Thanks Barry

      A Offline
      A Offline
      Antony M Kancidrowski
      wrote on last edited by
      #2

      What problems are you experiencing here? The VB declarations look OK to me. :) Ant.

      1 Reply Last reply
      0
      • N nelsonbd

        Hi, I am struggling to convert some functions from a C++ DLL to some function references in VB.net I dont program in C++, so I am hoping someone can help me with converting a couple of function prototypes: This are the C++ prototypes: CP2101_Open(DWORD dwDevice, HANDLE* cyHandle); CP2101_GetProductString(DWORD dwDeviceNum, LPVOID lpvDeviceString, DWORD dwFlags); CP2101_Close(HANDLE cyHandle ); This is what i have in vb.net: Public Declare Function CP2101_Open Lib "CP2101.dll" (ByVal DeviceNum As Long, ByRef Handle As Long) As Integer Public Declare Function CP2101_GetProductString Lib "CP2101.dll" (ByVal DeviceNum As Long, ByRef DeviceString As String, ByVal Options As Long) As Integer Public Declare Function CP2101_Close Lib "CP2101.dll" (ByVal DeviceNum As Long) As Integer I am not sure that I am converting the pointer data types correctly etc from C++ to Vb.net. If some could check my work. Thanks Barry

        A Offline
        A Offline
        Alexander M
        wrote on last edited by
        #3

        These nelsonbd wrote: This are the C++ prototypes: not true! These are C prototypes, else they would have very crazy export names in C++ name convention! Don't try it, just do it! ;-)

        1 Reply Last reply
        0
        • N nelsonbd

          Hi, I am struggling to convert some functions from a C++ DLL to some function references in VB.net I dont program in C++, so I am hoping someone can help me with converting a couple of function prototypes: This are the C++ prototypes: CP2101_Open(DWORD dwDevice, HANDLE* cyHandle); CP2101_GetProductString(DWORD dwDeviceNum, LPVOID lpvDeviceString, DWORD dwFlags); CP2101_Close(HANDLE cyHandle ); This is what i have in vb.net: Public Declare Function CP2101_Open Lib "CP2101.dll" (ByVal DeviceNum As Long, ByRef Handle As Long) As Integer Public Declare Function CP2101_GetProductString Lib "CP2101.dll" (ByVal DeviceNum As Long, ByRef DeviceString As String, ByVal Options As Long) As Integer Public Declare Function CP2101_Close Lib "CP2101.dll" (ByVal DeviceNum As Long) As Integer I am not sure that I am converting the pointer data types correctly etc from C++ to Vb.net. If some could check my work. Thanks Barry

          A Offline
          A Offline
          antlers
          wrote on last edited by
          #4

          The potential problem I see is in interpreting the LPVOID DeviceString as a ByRef String. If I remember my VB right, a ByRef String is passed to a C function as a pointer to BSTR. That may not be (probably is not) what the C function is expecting. An LPVOID doesn't give very much information about what it is expecting: it could be a null-terminated string, a null-terminated wide-string, a BSTR or perhaps a pointer to BSTR. Do you have source for that C function, or a C example of its use?

          1 Reply Last reply
          0
          • N nelsonbd

            Hi, I am struggling to convert some functions from a C++ DLL to some function references in VB.net I dont program in C++, so I am hoping someone can help me with converting a couple of function prototypes: This are the C++ prototypes: CP2101_Open(DWORD dwDevice, HANDLE* cyHandle); CP2101_GetProductString(DWORD dwDeviceNum, LPVOID lpvDeviceString, DWORD dwFlags); CP2101_Close(HANDLE cyHandle ); This is what i have in vb.net: Public Declare Function CP2101_Open Lib "CP2101.dll" (ByVal DeviceNum As Long, ByRef Handle As Long) As Integer Public Declare Function CP2101_GetProductString Lib "CP2101.dll" (ByVal DeviceNum As Long, ByRef DeviceString As String, ByVal Options As Long) As Integer Public Declare Function CP2101_Close Lib "CP2101.dll" (ByVal DeviceNum As Long) As Integer I am not sure that I am converting the pointer data types correctly etc from C++ to Vb.net. If some could check my work. Thanks Barry

            M Offline
            M Offline
            Mike Dimmick
            wrote on last edited by
            #5

            Firstly, you should normally use System.IntPtr for opaque pointer types when using VB.NET. This will help you if you ever port to 64-bit (the IntPtr type is 32 bit in a 32-bit process but 64 bits in a 64-bit process). As for CP2101_GetProductString, if the C/C++ code is interpreting the lpvDeviceString parameter as a string, you should use

            Public Declare Function CP2101_GetProductString Lib "CP2101.dll" ( _
            ByVal DeviceNum As Long, _
            ByVal DeviceString As String, _
            ByVal Options As Long) As Integer

            ByRef indicates an in/out parameter. If the function alters this data, you should use a StringBuilder object instead (still passed ByVal), and set its Capacity to the maximum size you expect the function to write. If you're getting MissingMethodExceptions, your DLL's exports may be mangled. To verify this, use dumpbin /exports. If the output contains ? characters and no recognisable function names, the names are mangled. You have two choices. Either you can rewrite your declarations to use the DllImportAttribute rather than Declare, and use the EntryPointName property to indicate the mangled name, or you can specify extern "C" in front of the exported function declarations to tell the compiler not to mangle the names. Remember that the latter will break binary compatibility with any existing clients. Stability. What an interesting concept. -- Chris Maunder

            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