-
September 1st, 2010, 01:41 AM
#1
Calling C++ DLL from VB
I'm not sure whether this is a VB forum question or a C++ question, but I'll try here first.
I have an API library written in C++ (including source) which compiles to several DLLs. I want to call the functions in the library from VB but I can't get the parameter passing right.
Simple ones like:
void yasdiMasterInitialize( char * cIniFileName, DWORD * pDriverCount)
Can be called by:
<DllImport("yasdimaster.dll", CallingConvention:=CallingConvention.Cdecl)> Public Function yasdiMasterInitialize(ByVal IniFile As String, ByRef DriverCount As UInt32) As Integer
End Function
But anything with arrays:
int GetDeviceName( DWORD DevHandle, char * DestBuffer, int len)
I can't seem to get right:
<DllImport("yasdimaster.dll", CallingConvention:=CallingConvention.Cdecl)> Public Function GetDeviceName(ByVal DeviceNumber As UInt32, ByVal DeviceName As String, ByVal Length As Integer) As Integer
End Function
The above example runs but returns nothing. If I change DeviceName to ByRef, I get protected memory errors.
The full library and documentation is available on the internet if anyone would like to download it and I've successfully compiled it with VS2010.
-
September 1st, 2010, 11:43 AM
#2
Re: Calling C++ DLL from VB
C++ has POINTERS. VB.Net doesn't, so, there is a MAJOR problem...
-
September 2nd, 2010, 04:52 AM
#3
Re: Calling C++ DLL from VB
In .net we use a string builder class as input when calling such a C function and the system automatically takes care of things. If that is not possible, is there any way of passing in a raw array from VB?
Last edited by Zaccheus; September 2nd, 2010 at 04:54 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|