Hi everyone. I'm trying to use some of my Delphi functions in Excel VBA, among which, many have "String" parameters. I'm compiling my functions into a Delphi DLL and to avoid using "BORLNDMM.DLL", I'm defining the string types as PChar in Delphi. Now I can't seem to find a way to call any of my functions (passing strings to them) from within VBA without getting the "Bad DLL Calling Convention" error message from Excel. An example of my code is:
-------------
In Delphi:
Procedure Test (InputStr1: PWideChar);
begin
ShowMessage (InputStr1);
end;
exports Test;
-------------
In VBA:
Private Declare Sub Test Lib "Test.dll" (ByRef InputString As String)
Sub DLL_Test ()
Dim S as String
S = "Test String"
Call Test (S)
End Sub
-------------
I have tried PChar and PWideChar in Delphi, Variant and String and also ByVal and ByRef in VBA but so far, I've been out of luck. Any ideas?
Bookmarks