#VB string params to DLL
2 messages in this thread
A couple of questions I've run into while trying to get some DLLs (in C)
working when called from Visual BASIC… How does one declare in a VB
program a DLL function that has a string as a parameter? I'd like the
function to remain & work the same as it currently does with other C
programs. I'm probably having a problem with VB's variable length strings
— how can I declare a C-style fixed length null-terminated string in
Visual Basic?
As an example, if I had a DLL function like this…
VOID FAR PASCAL ReverseString(LPSTR lpsz)
{
int i;
char c;
int nLen = lstrlen(lpsz);
for (i = 0; i < nLen / 2; i++) {
c = lpsz[i];
lpsz[i] = lpsz[nLen – i – 1];
lpsz[nLen – i – 1] = c;
}
}
…how would the function declaration, string, and function call be done in
Visual BASIC?
Thanks.
There is 1 Reply.
Declare Sub ReverseString Lib "MyLib.dll" (ByVal lpsz As String)
should do it.
To call it, you should say something like:
S$ = "Rick Sands"
ReverseString S$
not ReverseString (S$) since that would pass the result of (S$) which
would be a new string with the same contents of S$ (eg. a Copy of S$)