Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-10-2001, 07:15 PM
xrayted xrayted is offline
Junior Member
 
Join Date: Jan 2001
Posts: 1
Default passing by reference to a DLL call.

Hello,

I have a dll that has a function as follows:

int process( char *toBeProcessed, char *returnMessage );

I want to call this from within Delphi and have done the following:

function process( toBeProcessed : PChar; var message : PChar
):Integer; external 'mydll.dll';


procedure callTheDllFunction();
var
resp : integer;
msg : PChar;
begin

resp := process( 'whatiwanttoprocess', msg );

....
doSomethingWithMsg(msg);
...
end;

I was hoping that msg would contain the return message but all I get
is an 'invalid varient type conversion'

Any suggestions?

regards
Reply With Quote
  #2  
Old 01-10-2001, 09:49 PM
PoseFant PoseFant is offline
Senior Member
 
Join Date: Jan 2001
Posts: 1,002
Default RE: passing by reference to a DLL call.

I think you shold be more specific when you explain your problem ... I can see that you are switching between Char and PChar several times, and this may affect on the memory handling routines.

As far as I can see you hav a "C/C++" declared function :

INT Process(
Char * ToBeProcessed,
Char * ReturnMessage
);

As far as I know (I'm not a C/C++ expert) I think you need a reference pointer to the ReturnMessage Variable ...

INT Process(
Char * ToBeProcessed,
[out] Char * ReturnMessage
);

Ok, lets say it is declared this way ... )

What to declare in Delphi ...

Function Process(ToBeProcessed : PChar; Var ReturnMessage : PChar) : LongInt; StdCall; External 'YourDLL.dll';

As you can see we have a little var reference before the returning parameter, and a StdCall convention ...

The Conventions directs the parameter handling to functions, and perhaps this should help you out ... )

Another directive is CDecl, also used for C/C++ typical functions...

Ok ... so far so good ... I hope ... )


How to call it within your application ...

Var
Resp : Integer;
Begin
Resp := Process(@ToBeProcessed, @Msg);
End;

Try with and without the @ ...

To get the error result form your function call ...

Right after the function :

ShowMessage(SysErrorMessage(GetLastError));


Good Luck ...


Regards


/Filip
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 03:09 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.