SEARCH YOUR SOLUTION HERE  

Parameters & dll

My D7 app calls a dll to read memories from a radio. The dll produces a string, and
the length of the string. Calling one function in the dll works fine, but other
functions, using the same parms don't. It's the length that loses it.

procedure TfrmClone.SpeedButtonReadClick(Sender: TObject);
var
i, p: integer;
GetFreq: TGetFreq; //function(s: PChar; var slen: DWORD): LongBool; stdcall;
begin
dllFunc := 'GetFreq';
if ProcHandle 0 then
begin
GetFreq := GetProcAddress(ProcHandle, dllFunc);
if @getFreq nil then
begin
for i := 1 to LoopCtr do
begin
l := 0;
setlength(s,11); // s now contains some random garbage
if GetFreq(pChar(s),l, i) then // s is a global string, l is a global dword
RetFreq := s;
RetMode := GoForMode; // go get mode
..
..
..
end;

function TfrmClone.GoForMode: Shortstring;
var
GetMode: TGetMode; //function(s: PChar; var slen: DWORD): LongBool; stdcall;
begin
result := '';
dllFunc := 'GetMode';
if ProcHandle 0 then
begin
getMode := GetProcAddress(ProcHandle, dllFunc );
if @getMode nil then
begin
l := 0;
if GetMode(pChar(s),l) then
result := s;
end;
end;
end;

=========== In the dll ==============
function GetFreq(s: PChar; var slen: DWORD; chSet: integer): LongBool; stdcall;
//slen is 0
var
fr: string;
begin
result := false;
if chSet > 0 then
dll.SetChannel(chSet);
fr := dll.pollradio;
slen := length(fr); //slen is 7
if length(fr) > 0 then
begin
result := true;
strPLCopy(s, fr, slen);
end;
end;

function GetMode(s: PChar; var slen: DWORD):LongBool; // slen is Inaccessible here
var
mode: string;
begin
result := false;
mode := dll.PollRadio;
slen := length(mode); //AV
if slen > 0 then
begin
result := true;
strPLCopy(s, mode, slen);
end;
end;

Posted On: Friday 21st of September 2012 06:29:22 AM Total Views:  372
View Complete with Replies




Related Messages:

Using dll files   (407 Views)
Its been a while since I've use dlls for any projects, but recently after acquiring a Velleman USB board I decided I'd like to make use of it. The problem is, previously I experimented using eraserext.dll (from eraser) within a plugin for another program and it didn't seem to get along very well. Can dll's be used from other dll's or plugins generally - I've assumed no from past experience but I'd really like to create a plugin for an existing program using Max components TPlugin which will make use of the USB hardware. Unfortunately the only way to communicate with the hardware is through a dll file! Is this possible or am I going to end up chasing my tail round in circles