问题
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.
来源:https://stackoverflow.com/questions/8106496/in-vb6-how-do-i-retrieve-a-char-parameter-from-a-c-dll