by G. van den Hoven (3 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating:
(2 Votes)
The code was made by me because i did not find any information about how to pass a VB string to a delphi dll function (accepting strings) hope this code helps.
This code shows how to call a delphi DLL and how to code the Delphi dll to accept strings from VB. The code (2 demo projects, 1 in VB and 1 in Delphi) are pretty simple, but you get the idea.
FEEL FREE TO VOTE FOR ME!
Assumes
The code can be easily adjusted to implement full DELPHI applications (e.g. if you want some things done in Delphi, from within a VB application)
-------------------
VB CODE:
(START A NEW PROJECT, REPLACE THE EXISTING CODE WITH THIS:)
-------------------
Option Explicit
Private Declare Function CountLetters Lib "..\delphi\project1.dll" (ByVal Str As String) As Long
Private Sub Form_Load()
Call CountLetters("This is a teststring, passed to a function in a delphi DLL")
End Sub
-------------------
DELPHI CODE
(START A NEW LIBRARY, REPLACE THE EXISTING CODE WITH THIS:)
-------------------
library Project1;
uses
Windows,
SysUtils;
function CountLetters(pData : PChar) : Cardinal; export; stdcall;
var
Handle : Integer;
tMsg : String;
begin
tMsg := 'The string passed by you; "' + pData + '" is counting ' + IntToStr(Length(pData)) + ' letters.';
MessageBoxA(Handle, pChar(tMsg), 'Delphi DLL', MB_OK);
end;
exports
CountLetters name 'CountLetters' resident;
begin
end.