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. Call to C++ DLL from VB???

Call to C++ DLL from VB???

Scheduled Pinned Locked Moved Visual Basic
c++helpquestion
2 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
    Richard Hudson
    wrote on last edited by
    #1

    :wtf:I am a C++ prgrammer but have very little VB experience. Could someone help me with the following: I have Win32 dll, and need to call a function from VB:- code:-------------------------------------------------------------------------------- int WINAPI SCN_Open_Device(HWND, LPDWORD, LPSTR, LPSTR, LPSTR, LPSTR, LPWORD); -------------------------------------------------------------------------------- I have declared the function as code:-------------------------------------------------------------------------------- Declare Function SCN_Open_Device Lib "D:\My Projects\Development\Phillipines\VB1\scn_scsi.dll" (ByVal hwnd As Long, ByVal num_device As Long, ByVal vendor_model As String, ByVal product_version As String, ByVal periph_name As String, ByVal path_ini_file As String, ByVal dll_version As Integer) As Integer -------------------------------------------------------------------------------- And called the function from Vb as follows: code:-------------------------------------------------------------------------------- Dim Par1 As Long Dim Par2 As String Dim Par3 As String Dim Par4 As String Dim Par5 As String Dim Par6 As Integer Dim Result As Integer Result = SCN_Open_Device(Form1.hwnd, Par1, Par2, Par3, Par4, Par5, Par6) -------------------------------------------------------------------------------- But I get a crash. Could someone tell me what I am doing wrong? I guess my data types are incorrect ??? Eternally grateful to anyone who helps me Rich

    C 1 Reply Last reply
    0
    • R Richard Hudson

      :wtf:I am a C++ prgrammer but have very little VB experience. Could someone help me with the following: I have Win32 dll, and need to call a function from VB:- code:-------------------------------------------------------------------------------- int WINAPI SCN_Open_Device(HWND, LPDWORD, LPSTR, LPSTR, LPSTR, LPSTR, LPWORD); -------------------------------------------------------------------------------- I have declared the function as code:-------------------------------------------------------------------------------- Declare Function SCN_Open_Device Lib "D:\My Projects\Development\Phillipines\VB1\scn_scsi.dll" (ByVal hwnd As Long, ByVal num_device As Long, ByVal vendor_model As String, ByVal product_version As String, ByVal periph_name As String, ByVal path_ini_file As String, ByVal dll_version As Integer) As Integer -------------------------------------------------------------------------------- And called the function from Vb as follows: code:-------------------------------------------------------------------------------- Dim Par1 As Long Dim Par2 As String Dim Par3 As String Dim Par4 As String Dim Par5 As String Dim Par6 As Integer Dim Result As Integer Result = SCN_Open_Device(Form1.hwnd, Par1, Par2, Par3, Par4, Par5, Par6) -------------------------------------------------------------------------------- But I get a crash. Could someone tell me what I am doing wrong? I guess my data types are incorrect ??? Eternally grateful to anyone who helps me Rich

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      This might help, but the final five parameters are to be pointers and the only way to have VB pass a pointer would be in the function definition to use the clause 'ByRef' instead of using 'ByVal'. Having said that though, I suspect that 'String' types in VB are not the same as the 'string' types in C++. AFAIR I had to declare my C routine in the DLL as "pointer to a pointer to a type" in order to get things to work properly. Also I'm not sure whether the WINAPI is a std_call or not. The calling convention is pretty important to get correct for all these things to work. Chris Meech It's much easier to get rich telling people what they want to hear. Chistopher Duncan I can't help getting older, but I refuse to grow up. Roger Wright I've been meaning to change my sig. Thanks! Alvaro Mendez

      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