General discussion
-
Topic
-
VB – calling a function in an extnal DLL
LockedHello,
I hope I can explain my problem clearly, so here goes:
I have an external DLL with various functions (written in C if this makes
any difference?).I delcare it:
Declare Function SomeFunction Lib “some.dll” (ByVal str1 As String, ByRef
vartype1 As newType) As LongThe DLL is coded in C and the programmer told me that newType should be:
typedef struct
{
char *m_szDateTimeReceived;
char *m_szFrom;
char *m_szTo;
char *m_szSubject;
char *m_szDateTimeSent;
char *m_szCC;
char *m_szReplyTo;
char *m_szCompany;
} DECENC_MSG_INFO, * LPDECENC_MSG_INFO;What should this typedef look like in VB?
I started with
Type DECENC_MSG_INFO
m_szDateTimeReceived As String
m_szFrom As String
m_szTo As String
m_szSubjectAs String
m_szDateTimeSent As String
m_szCC As String
m_szReplyTo As String
m_szCompany As String
End TypeNow, when I called the function using all the above, VB blew itself to
smithers. So, on the instruction of the DLL programmer (who was graciously
helping me despite his stated lack of VB knowledge) changed the “string”
type to “Long”.
Type DECENC_MSG_INFO
m_szDateTimeReceived As Long
m_szFrom As Long
..
..Now this had some better results.
When I called the necessaryfunction “somefunction(, varTest (where
varTest is of type newType)) I get something back.I was expecting a string as a result, but now get a number. (Have I lost
you all?)What am I doing wrong?
The programmer says ”
The items inthe structure are “C” style character pointers, which are 4
bytes. String is larger, probably why you are seeing a problem. I’m not sure
exactly how the structure elements are changed to String unfortunately. Each
Long is really a Byte * something allocated by the DLL which, if not 0
contains the string you need.”Is the numebr bring returned a pointer? If so, how do I deal with it?
Any help appreciated.
Thnx