In my Delphi code I have to call a DLL's function (written in Visual C) with the following prototype:
int PWFunc(LPCSTR szName, int nWidth, int nHeight, LPCSTR szFileName)
How can I convert Delphi AnsiString variables (for Name and FileName) into right type parameters (LPCSTR szName and szFileName) of function call ? I know that VC LPCSTR type corresponds to Delphi PAnsiChar type, but what is the right procedure to convert AnsiString to PAnsiChar ?
PAnsiChar(AnsiString(s))is the answer to your last Q, assuming the encoding is ANSI. If the encoding is UTF-8, different answer! - David HeffernanLPCSTRtype defined... - TLamaPAnsiChar(AnsiString(UTF8Encode(s)))or directlyLPCSTR(AnsiString(UTF8Encode(s))), if you define the prototype by usingLPCSTRdata type. Or even without the conversion toAnsiString, likePAnsiChar(UTF8Encode(s))orLPCSTR(UTF8Encode(s)). - TLama