Thread
:
Passing arguments from VBA to DLL
View Single Post
#
9
Posted to microsoft.public.excel.programming
NickHK[_3_]
external usenet poster
Posts: 415
Passing arguments from VBA to DLL
Now you mention that, changing the declare of lstrlenA to the Wide version;
Public Declare Function lstrlenW Lib "kernel32" (ByVal lpString As String)
As Long
now works fine the worksheet also.
IIRC normally when calling window function from
VB
there is Unicode ANSI
conversion. Hence the "A" versions of these function are used.
If I wanted to use the W version it would be
Public Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As
Long
and call it with
lstrlenW(strPtr("MyString"))
From the worksheet, seems the conversion does not occur.
NickHK
egroups.com...
schrieb:
I just took the first few steps in writing a little DLL that should
be called from Excel/VBA, and I stumbled upon some wierd behaviour.
The function in my DLL is declared as
int __stdcall foo( const char *t );
and is used in VBA via
Declare Function foo Lib "C:\foo\foo.dll" (ByVal t As String) As Long
I noticed that foo didn't work internally as I expected and added
writing *t to a file on each call of foo as a debugging measure.
According to this output, only the first character of String t seems
to be passed to foo when called directly from Excel (putting
=foo("xyz") in a cell).
Let me answer my own post:
Excel passes the string as some kind of wide-character. Using
const wchar_t *t in my function works perfectly.
Regards,
Matthias
Reply With Quote
NickHK[_3_]
View Public Profile
Find all posts by NickHK[_3_]