in vb6, how do I retrieve a char* parameter from a

2019-07-13 07:37发布

问题:

I am calling a C dll from my VB6 application. The dll has a function call signature as follows.

void WINAPI geterrstr(char* foo);

where foo is a string that has to be returned.

In my VB6 application, I have tried calling my dll by using the following syntax, but it returns an empty string.

Declare Sub geterrstr Lib "technopnp.dll" (ByRef lpbuffer As String)

Any ideas?

回答1:

You should be able to;

Declare Sub geterrstr Lib "technopnp.dll" (ByVal lpbuffer As String)
...
dim buff as string
buff=string$(n, vbnullchar)
geterrstr buff

//read upto 1st vbnullchar
buff = left$(buff, instr(1, buff, vbnullchar) - 1)
if (buff="") then
  //no data
else
  msgbox buff
end if

n needs to be an appropriate buffer size, too short and it will crash.