一般不用funtion形式返回,而是把输出也封装字输入中,如下例:
Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Sub GetComputerName_test()
Dim Name As String, Length As Long
Length = 255
Name = String(Length, 0)
GetComputerName Name, Length
Name = Left(Name, Length)
MsgBox "此一电脑的名称=" & Name, , "GetComputerName"
End Sub
What is your DLL type? ActiveX DLL or normal DLL
in ActiveX DLL, it's very simple.
in normal DLL, your must Convert your string to UNICODE before
return. use MultiByteToWideChar.
if you don't like MultiByteToWideChar in C,
you can also use result = StrConv(buf, vbtoUniCode) in VB
here is a sample:
in VB:
Private Declare Function RevString Lib "MyDLL" Alias "RevString" (ByVal lpBuffer As String, ByRef BufOut, nSizeBuf As Long) As Long
s = "xxx[Chinese]XXX"
buf = StrConv(s, vbfromUnicode)
call RevString(buf, sout, 255)
s = StrConv(sout, vbtoUnicode)
in C:
__declspec( dllexport ) void RecString(char *, char*, long);
void RecString(char *, char*, long)
{
do something
}
in your MAKEFILE
EXPORTS
RecString@1