View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] mkluwe@gmail.com is offline
external usenet poster
 
Posts: 6
Default Passing arguments from VBA to DLL

Hi!

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).

However, if I wrap foo with

Function call_foo(t As String) As Long
call_foo = foo(t)
End Function

and use the formula =call_foo("xyz"), everything works ok.

Any ideas?

Regards,
Matthias

PS. Any other hints to "VBA calls DLL" documentation are appreciated