Calling a C++ Created DLL Function from VB6 with User Define Type
Posted on 2010-11-10
Have an API written in C++ that has the following function.
int SD_GetPacket(char *buffer, unsigned short sizeofbuffer);
Return success=1, no data=0, fail=-error_no (-1=not enough space, others for future
This function is called to return data from the API. This can be done by simply polling in a
timer or by calling the routine following reception of a message denoting data arrival.
Regardless of the method, SD_GetPacket should be called in a while loop structure so that
on each message or timer event all available data is processed until it returns a zero value.
char *buffer – buffer to receive the packet information received.
The data delivered is in the flowing format;
Description Type Offset Length
The stream the data was delivered from (i.e. 20-38) Word 0 2 bytes
A unique key for this packet used internally by SD Byte array 2 10
Length of the following payload (i.e. the packet) Word 12 2
Data (BettorData Packet), variable length Byte Array 14 <32767
If you were to define a suitable structure using C Language, the following would suit;
#define DDS_MAX_CHUNK 32766
#define UNIQUEIFIER_LEN 10
unsigned short stream; //SD Stream number
unsigned char key[UNIQUEIFIER_LEN]; //SD Unique Key
unsigned short elen; //Length of data payload following
unsigned char data[DDS_MAX_CHUNK]; //Data payload from BettorData
unsigned short sizeofbuffer – size of the memory block passed above. In C Language
using the structure above this is best specified using something similar to
Now trying to work out the best way to call this function from VB6, at present I am getting Bad DLL Calling Convention.
I've presently defined the function as follows:
Public Declare Function SD_GetPacket Lib "sdapi" (ByVal sBuffer, sBufferSize) As Integer
using variant datatypes, however this is obviously incorrect.