General discussion

Locked

VB - calling a function in an extnal DLL

By simon.wellborne ·
Hello,

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 Long

The 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 Type

Now, 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(<var>, 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

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

VB - calling a function in an extnal DLL

by awimsatt In reply to VB - calling a function i ...

My VB knowledge is also limited but have you tried the following?

Type DECENC_MSG_INFO
m_szDateTimeReceived As Variant
m_szFrom As Variant
m_szTo As Variant
m_szSubject As Variant
m_szDateTimeSent As Variant
m_szCC As Variant
m_szReplyTo As Variant
m_szCompany As Variant
End Type

When retrieving data from the dll, just type cast it using cSTR() to convert it to String. I hope this helps. Though it is just a guess. I've never setup a Type struct in VB.

Adam

Collapse -

VB - calling a function in an extnal DLL

by simon.wellborne In reply to VB - calling a function i ...

Poster rated this answer

Collapse -

VB - calling a function in an extnal DLL

by simon.wellborne In reply to VB - calling a function i ...

This question was closed by the author

Back to Windows Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums