Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

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


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();
resp : integer;
msg : PChar;

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


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

Any suggestions?

Reply With Quote
Old 01-10-2001, 10: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 ...

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

Try with and without the @ ...

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

Right after the function :


Good Luck ...


Reply With Quote

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 05:46 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.