Christo
Christo

Reputation: 411

call function in epanet2.dll

I am converting code from Delphi 7 to XE3 for Epanet. My issue is to do with the *char in a dll compiled in C.

The code within the dll is as follow:

int DLLEXPORT ENopen(char *f1, char *f2, char *f3)
/* Check that file names are not identical */
....
   if (strcomp(f1,f2) || strcomp(f1,f3) || strcomp(f2,f3))
   {
        writecon(FMT04);
        return(301);
   }
 ....

In delphi 7 is works correctly like this:

function ENopen(F1: PChar, F2 : PChar, F3 : PChar) : Integer; stdcall;

In XE3 301 is returned. I have tried to change PChar to PAnsiChar without any luck.

Upvotes: 0

Views: 221

Answers (1)

crefird
crefird

Reputation: 1610

Basically your problem is that EPANET2.DLL is not Unicode.

First, change all PChar in EPANET2.PAS to PAnsiChar, like the following

function ENopen(F1: PAnsiChar, F2 : PAnsiChar, F3 : PAnsiChar) : Integer; stdcall;

Then change the arguments in the calls to EPANET2 entry points to use PAnsiChar. Either of the following approaches will work since none of the entry points return strings.

-- Using strings --

var
  rc : integer;
  F1, F2, F2 : string;
…
  rc := ENopen(PAnsiChar(AnsiString(F1)), PAnsiChar(AnsiString(F2)),
    AnsiChar(AnsiString(F3)));

-— Using AnsiStrings --

var
  rc : integer;
  F1, F2, F2 : AnsiString;
…
  rc := ENopen(PAnsiChar(F1), PAnsiChar(F2), PAnsiChar(F3));

Upvotes: 3

Related Questions