Muhammad Ali Guest
|
Posted: Mon Apr 16, 2007 7:11 pm Post subject: Error sending PChar to C DLL from Delphi |
|
|
I have been working on DLL which is to be called from DELPHI. The dll
is made in VC 2005. There are couple of functions which i am calling,
the first 2 functions are being called without any problem, however i
am having problem in Third function.
The prototype of those function in C are
__declspec (dllexport ) void WINAPI SetFilePath(char * filepath)
I mapped it on DELPHI as
TDllSetFilePath = procedure (path : PChar); stdcall;
{rest declatrations}
DllSetFilePath : TDllSetFilePath; {in private section}
{...}
procedure SetFilePath (FilePath : PChar); {a public method to be
called in delphi}
implementation
procedure TDllOtengoCore.SetFilePath(FilePath: PChar);
begin
if initCalled = false then
begin
init; {ensures that dll is loaded}
end;
if @DllSetFilePath = nil then
begin
@DllSetFilePath := GetProcAddress(dllHandle, _SetFilePath);
{_Setfile path is defined globally to cover name mangling}
end;
DllSetFilePath(FilePath);
end;
Similarly i was able to call "start" method as well of dll which
accept no parameter.
But when i am trying to call another method, I am having problems.
C Prototype
__declspec (dllexport)
void WINAPI Authenticate(char * emailaddrs, char * password, BOOL
isnated, HWND loginwindowhandle)
In delphi,
{Type define}
TDllAuthenticate = procedure(mailId, mailPass: PChar;
isNated:LongBool; loginWindowHandle:HWND);
{in private}
DllAuthenticate : TDllAuthenticate;
{public method for dll forms}
procedure Authenticate (mailId, mailPass: PChar;
isNated:LongBool; loginWindowHandle:HWND);
{implementation}
procedure TDllOtengoCore.Authenticate(mailId, mailPass: PChar;
isNated: LongBool; loginWindowHandle: HWND);
begin
if initCalled = false then
begin
init;
end;
if @DllAuthenticate = nil then
begin
@DllAuthenticate := GetProcAddress(dllHandle, _Authenticate);
end;
DllAuthenticate(mailId, mailPass, 0, loginWindowHandle);
end;
When i called this method, i debuged the C version of dll with Delphi
generated EXE file. In first function, the SetFilePath of C receive
the exact string to it's Char * to pointer, which i am sending via
Delphi.
But in Authenticate method, when i send "mailID", "password" i am
receiving "BAD POINTER" or some "GARBAGE" value. I have tried so many
alternates but failed, can you people help me to figure out the
problem. |
|