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

对着背影说爱祢 提交于 2020-01-24 12:04:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!