Board index » delphi » PChar and char *

PChar and char *

Hello,
i have a function in my DLL whose header is :

SOCKET Connect(char *server,unsigned int port);

when i declare it in my application in Delphi (using the DLL written in
VC++, where there is the function Connect), i put :
function Connect(server: PChar;port: Word): SOCKET; external 'BDD.dll';

but when i call my function Connect :

procedure TForm1.Button1Click(Sender: TObject);
var
  result:integer;
  port:Word;
  server:PChar;
begin
   port:=3001;
   server:='192.168.3.202';
   result:=Connect(server,port);
   if (result=-1) then
     ShowMessage(IntToStr(ReadError));
end;

however, when my function Connect shows me the variable server given in
argument, it's not at all '192.168.3.202' ....

hence my question : what is the equivalent of char * in Delphi ?

thxs

++
DJ

 

Re:PChar and char *


You may need to declare the function using the "cdecl" calling
convention as follows:

function Connect(server:PChar; port:Word):SOCKET; cdecl; external
'BDD.dll';

Hope this helps.

-Rich

Quote
"DJ" <Despatis.Jer...@ec-lille.fr> wrote:
>Hello,
>i have a function in my DLL whose header is :

>SOCKET Connect(char *server,unsigned int port);

>when i declare it in my application in Delphi (using the DLL written in
>VC++, where there is the function Connect), i put :
>function Connect(server: PChar;port: Word): SOCKET; external 'BDD.dll';

>but when i call my function Connect :

>procedure TForm1.Button1Click(Sender: TObject);
>var
>  result:integer;
>  port:Word;
>  server:PChar;
>begin
>   port:=3001;
>   server:='192.168.3.202';
>   result:=Connect(server,port);
>   if (result=-1) then
>     ShowMessage(IntToStr(ReadError));
>end;

>however, when my function Connect shows me the variable server given in
>argument, it's not at all '192.168.3.202' ....

>hence my question : what is the equivalent of char * in Delphi ?

>thxs

>++
>DJ

Re:PChar and char *


Rich Walker <r...@texas.net> a crit dans le message :
6lh3fs8o47mrjsskt707m7lvr7t1mmd...@4ax.com...

Quote
> You may need to declare the function using the "cdecl" calling
> convention as follows:

> function Connect(server:PChar; port:Word):SOCKET; cdecl; external
> 'BDD.dll';

> Hope this helps.

> -Rich

AHHHH YESSSSSS !!!!
I love u Rich :))

++
DJ

Other Threads