I have a rather simple Pascal program, that is to call some C functions I have written.
My C code:
void connect_default(int* errorcode)
{
// Connects the default user and places any error code in errorcode
}
void connect(char user[129], char password[129], int* errorcode)
{
// Connects the given user and places any error code in errorcode
}
I'm trying to call these two functions in my Pascal application. This works fine:
program pascaltest(INPUT, OUTPUT);
procedure connect_default(var errorcode: integer); external;
var
errorcode : integer := 0;
begin
connect_default(errorcode);
if errorcode <> 0 then
writeln('Failed to connect with error code ', errorcode);
end.
But I have a hard time finding out what data type to use in Pascal, that corresponds to a null terminated char array in C. A Pascal string does not seem to be it, because this passes nothing to the C function.
program pascaltest(INPUT, OUTPUT);
procedure connect(user : string, password : string, var errorcode: integer); external;
var
errorcode : integer := 0;
begin
connect('MyUser', 'MyPassword', errorcode);
if errorcode <> 0 then
writeln('Failed to connect with error code ', errorcode);
end.
What datatype in Pascal corresponds to a null terminated C char array? My environment is a HP OpenVMS machine and not Free Pascal, meaning that I do not have access to the types pchar and ansistring that I have read about.
The C functions need to stay as general as possible and I cannot make any changes to them, creating custom structs (like what is described here Declaring Pascal-style strings in C), as the C functions are already successfully called by similar programs written in C, Fortran and Cobol, where I managed to find the data types needed.