I have a Dll function with this signature:
UInt32 Authenticate(uint8 *Key);
I’m doing this on Delphi:
function Authenticate(Key:string) : UInt32; external 'mylib.dll' name 'Authenticate';
But always, the function return 10 (error code) and the application brakes :\
There is a way to do this right?
UPDATE: thanks guys! you’re the best!
There are some problems with your code.
1)
uint8is the equivilent ofBytein Delphi, notString.2) the C code is using the compiler’s default calling convention, which is usually
__cdecl. Delphi’s default calling convention, on the other hand, isregisterinstead. They are not compatible with each other. If you mismatch the calling convention, the stack and CPU registers will not be managed correctly during the function call at runtime.A literal translation of the C code would be this instead:
However, assuming the function is actually expecting a null-terminated string then do this instead:
I would stick with the first declaration, as it matches the original C code. Even if the function is expecting a null-terminated string as input, you can still pass it in using
PBytevia a type-cast:Or, if the function allows NULL input for empty strings: