Results 1 to 5 of 5

How to pass strings from Excel VBA to a Delphi DLL

Threaded View

  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:

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

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