Hi.
I want to call a dll function in Delphi 2010. This function take a string and write it to a printer with USB interface. I do not know in which language the dll is developed with. According to the documentation the syntax of the function is:
int WriteUSB(PBYTE pBuffer,DWORD nNumberOfBytesToWrite);
How can I declare and use my function in Delphi?
I declare the function like this:
...
var
function WriteUSB(myP:pByte;n:DWORD): integer ; external 'my.dll';
Should I use stdcall or cdecl in the declaration?
I call the dll function like this:
procedure myProc;
var
str : string:
begin
str := 'AAAAAAAAAAAAAAAAAAAAA';
WriteUSB(str,DWORD(length(tmp)));
end;
But this code give me exception all the time. I know that the problem is that "String" is Unicode and each charcter > 1 byte. I tried to convert to different string types (Ansichar and Short string) but I failed.
How is the correct way to do this?
BR Delphi user