Hi there.
What's the best way to send/recieve textmasses from/to a Dynamic link library?
You may not use Delphi ShareMem unit.
Should I solve it in another way, or is may way the preferred way
(The way I split First and Lastname can be solved more efficient, but it is'nt the main issue in this case.)
The DLL:
The Testapplication:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-"There is always another way to solve it, but I prefer my way.
What's the best way to send/recieve textmasses from/to a Dynamic link library?
You may not use Delphi ShareMem unit.
Should I solve it in another way, or is may way the preferred way
(The way I split First and Lastname can be solved more efficient, but it is'nt the main issue in this case.)
The DLL:
Code:
library TestDLL;
uses
Dialogs, StrUtils, SysUtils, Classes, Commonclasses;
{$R *.res}
procedure SeparateNames(lpFullName: pChar; lpResultFirstName, lpResultLastName: pChar; MaxLen: Integer); export; stdcall;
var
s: String;
lp1, lp2: pChar;
begin
s := StrPas(lpFullName);
GetMem(lp1, MaxLen);
GetMem(lp2, MaxLen);
try
// Separate First and Last Name
StrPCopy(lp1, Copy(s, 1, Pos(' ', s)-1));
StrPCopy(lp2, Copy(s, Pos(' ', s)+1, Length(s)));
StrLCopy(lpResultFirstName, lp1, MaxLen);
StrLCopy(lpResultLastName, lp2, MaxLen);
finally
FreeMem(lp1);
FreeMem(lp2);
end;
end;
exports
SeparateNames;
begin
end.
The Testapplication:
Code:
procedure CallTheDll;
const
MAX_LEN = 100;
var
DLLHandle: THandle;
SeparateNames: procedure(lpFullName: pChar; lpResultFirstName, lpResultLastName: pChar; MaxLen: Integer); stdcall;
lpFirstName, lpLastName: pChar;
begin
GetMem(lpFirstName, MAX_LEN);
GetMem(lpLastName, MAX_LEN);
try
DLLHandle := LoadLibrary('TestDLL.dll');
if DLLHandle <> 0 then
begin
@SeparateNames := GetProcAddress(DLLHandle, 'SeparateNames');
if @SeparateNames <> nil then
begin
SeparateNames(pChar('FirstName Lastname'), lpFirstName, lpLastName, MAX_LEN);
ShowMessage(StrPas(lpFirstName) +#13#10+ StrPas(lpLastName));
end;
FreeLibrary(DLLHandle);
end;
finally
FreeMem(lpFirstName);
FreeMem(lpLastName);
end;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-"There is always another way to solve it, but I prefer my way.