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