Problem with C function called from Visual Basic

Status
Not open for further replies.
How can I have a c function inside of a DLL return a string that can be read and stored as the VB String type. This of course works with other c functions:

char * blah(void) {
return "test\0";
}

declaring this function in VB with:

Private Declare Function blah Lib "mydll.dll" () As String

Trying to use this function gives me bad memory errors and VB is terminated : ). Anyone know what I can do?
 

Rubycon

Smack-Fu Master, in training
53
From Dan Appleman's "VB Programmers Guide to the Win32 API"
DLL functions may not return VB Strings directly, but they can modify strings that are passed to them.

I.e.
void blah(char* out)
{ ... }

Make sure that the string the VB programming is passing has been filled with null chars and is big enough to hold the return.

[Edited: found reference]

[This message was edited by Rubycon on October 26, 2001 at 12:26.]

[This message was edited by Rubycon on October 26, 2001 at 12:27.]
 
Status
Not open for further replies.