Board index » delphi » Call DLL error.

Call DLL error.

Hi all,
I created a dll using msvc6.0 which includes a function like:
  int fn(char * filename);
  {
    MessageBox(hwnd, filename, "Name", MB_OK);
    ...
   }
in my delphi, i convert it to:
  function fn(filename: PChar) : Integer; stdcall;
but with the following code:
  Host = 'a.txt';
  PHost = Addr(Host[1]);
  fn(PHost);  

the MessageBox in fn() shows some strange chars not 'a.txt' with
the right title "Name".

Does anyone know where I did wrong?
Thanks very much for any help,
-CZ

 

Re:Call DLL error.


Quote
cz wrote:
> I created a dll using msvc6.0 which includes a function like:
>   int fn(char * filename);
>   {
>     MessageBox(hwnd, filename, "Name", MB_OK);
>     ...
>    }
> in my delphi, i convert it to:
>   function fn(filename: PChar) : Integer; stdcall;

Your Delphi declaration doesn't match your C declaration. C uses the
cdecl calling convention by default, not stdcall.

Quote
> but with the following code:
>   Host = 'a.txt';
>   PHost = Addr(Host[1]);
>   fn(PHost);  

Fix the calling convention and see if that solves the problem. If it
doesn't, then please post your actual code.

--
Rob

Re:Call DLL error.


Thanks Rob. That solves the problem.

I used DRBOB's headconv tool to convert it and found some
complex if-else block and then deleted the cdecl part...
(I looked at Delphi's mmsystem.pas which has stdcall declaration,
but i didn't know the difference then...)

Other Threads