+ Reply to Thread
Results 1 to 5 of 5

How to pass strings from Excel VBA to a Delphi DLL

  1. #1
    Registered User
    Join Date
    09-27-2010
    Location
    Tehran, Iran
    MS-Off Ver
    Excel 2003
    Posts
    3

    Lightbulb How to pass strings from Excel VBA to a Delphi DLL

    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:

    Please Login or Register  to view this content.
    exports Test;

    -------------

    In VBA:


    Please Login or Register  to view this content.
    -------------

    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?
    Last edited by romperstomper; 09-28-2010 at 06:44 AM. Reason: code tags for newbie

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: How to pass strings from Excel VBA to a Delphi DLL

    Did you add the reference to this library in the VBEditor ? (menubar/Extra/references)



  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: How to pass strings from Excel VBA to a Delphi DLL

    I remember almost nothing about the little Delphi I ever learned, but don't you need:
    Please Login or Register  to view this content.
    on the end of your procedure line? I also think you should pass the strings ByVal. (and probably post your question in a Delphi forum!)
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Registered User
    Join Date
    09-27-2010
    Location
    Tehran, Iran
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: How to pass strings from Excel VBA to a Delphi DLL

    Thanks romperstomper, I hadn't used stdcall model, it's OK now.

  5. #5
    Registered User
    Join Date
    11-22-2013
    Location
    Sveti Duh
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: How to pass strings from Excel VBA to a Delphi DLL

    I made the same and also work. PWideChar is correct type for transfer string from Excel VBA to Delpfi. My test function:

    Function BB(L: PWideChar; Filter: PWideChar): Double; stdcall;
    begin
    Result := Length(L);
    end;

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1