excel - VBA call same C++ dll return different results -
i have test dll function reads string , display it:
int _stdcall test(lpstr mystring) { messageboxa(null, (lpcstr)mystring, "test", mb_ok); return 0;}
the excel vba declaration is
declare function test lib "test.dll" (byval text string) long
there sub calls function. reads excel cell value "abcde" , able display correct result. sub code is:
sub testcode() test (cells(1,1).value) end sub
however when call dll function using excel formula =test(a1)
, message box display first char "a" of string.
i had spent entire weekend reading bstr, etc, still not able solve this. going on here?
declare imported function private:
private declare function test_internal lib "test.dll" alias "test" (byval text string) long
and create wrapper function excel use:
public function test (byval text string) long test = test_internal(text) end functin
because apparently, while vb(a) converts string arguments ascii using current system codepage when calling declare
d apis, excel engine not.
on side note, might want remove parentheses.
Comments
Post a Comment