fischermx
asked on
Calling a function from Delphi 2009 to a C++ Dll
So, I have to use a previously compiled DLL made in C++.
There's a function defined as :
extern "C" SHORT DLLExport WINAPI OpenThisFile(PBYTE cpFileName)
I used to have the next code in Delphi 5,6,7,2005,006 and 2007 which used to work:
OpenThisFile: function(cpFileName: PChar); SmallInt stdcall
But now, in Delphi 2009 that seems broken, it seems from the error messages I'm getting that the C++ function just reads the first character of the filename I'm passing.
How do I do that now in Delphi 2009? (and preferable be backward compatible with Delphi 2007 and older)
There's a function defined as :
extern "C" SHORT DLLExport WINAPI OpenThisFile(PBYTE cpFileName)
I used to have the next code in Delphi 5,6,7,2005,006 and 2007 which used to work:
OpenThisFile: function(cpFileName: PChar); SmallInt stdcall
But now, in Delphi 2009 that seems broken, it seems from the error messages I'm getting that the C++ function just reads the first character of the filename I'm passing.
How do I do that now in Delphi 2009? (and preferable be backward compatible with Delphi 2007 and older)
Try a PByteArray instead of PChar. See if you get more.
ASKER
I know this is a Delphi question, but how do I copy my data from the string to the bytearray?
I have currently have:
var
sFile : String;
pFile : PChar;
begin
sFile := 'test.txt';
pFile := @sFile[1];
OpenThisFile(pFile);
How do I use a byte array here?
I have currently have:
var
sFile : String;
pFile : PChar;
begin
sFile := 'test.txt';
pFile := @sFile[1];
OpenThisFile(pFile);
How do I use a byte array here?
In D2009 a PChar is really a PWideChar which is not the same as the C function declaration. You can use PAnsiChar instead.
ASKER
I already tried PAnsiChar and it behave exactly the same. I changed the parameter and the declaration in Delphi from PChar to PAnsiChar, and the C++ function still see only the first character.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.