dannyguindi
asked on
Problem with DLL parameters
Hello experts,
I am having some difficulty making a call to a dll function that I wrote. I am passing a PChar parameter from my application to the DLL function (to avoid passing strings), but the value is corrupted when it is received by the dll. This is a snapshot of my code:
**********************
Application code....
...
try
Handle := LoadLibrary(test.dll');
@Func1:= GetProcAddress(Handle, Func1);
if @Func1= nil then
exit;
Func1('Parameter');
except
end
...
**********************
DLL code....
...
function Func1(lpszCmdLine :PChar) : Integer; stdcall;
begin
ShowMessage(Parameter: ' + lpszCmdLine);
end;
...
Am I doing something wrong?
Thanks,
dannyguindi
I am having some difficulty making a call to a dll function that I wrote. I am passing a PChar parameter from my application to the DLL function (to avoid passing strings), but the value is corrupted when it is received by the dll. This is a snapshot of my code:
**********************
Application code....
...
try
Handle := LoadLibrary(test.dll');
@Func1:= GetProcAddress(Handle, Func1);
if @Func1= nil then
exit;
Func1('Parameter');
except
end
...
**********************
DLL code....
...
function Func1(lpszCmdLine :PChar) : Integer; stdcall;
begin
ShowMessage(Parameter: ' + lpszCmdLine);
end;
...
Am I doing something wrong?
Thanks,
dannyguindi
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sometimes, I dont even understand why, Pchar sucks... I always prefer PAnsiChar in this type of parameter values..
ASKER
The missing ' were just typos in my snapshot. What was causing the problem was the missing 'stdcall' in my function declaration. It works now!
Thanks geobul.
Thanks geobul.
You are welcome :-)