How to pass a byte array from VB to C++ DLL

C, C++, Visual C++, C++.Net Topics
Post Reply
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

How to pass a byte array from VB to C++ DLL

Post by Saman » Thu Nov 24, 2011 10:04 pm

Define the C++ DLL function as below.

Code: Select all

int __stdcall MyFunc(char *buf, long length);
Now declare the function in VB6 as below.

Code: Select all

Declare Function MyFunc(ByVal buf as Long, ByVal len As Long) As Long
Here is how you need to call it.

Code: Select all

Dim buf(1023) as Byte ' 1024 element array
MyFunc VarPtr(buf(0)), 1024
Post Reply

Return to “C/C++ Programming”