![]() |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|