BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Error sending PChar to C DLL from Delphi

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General)
View previous topic :: View next topic  
Author Message
Muhammad Ali
Guest





PostPosted: Mon Apr 16, 2007 7:11 pm    Post subject: Error sending PChar to C DLL from Delphi Reply with quote



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.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi (General) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.