I want to call a DLL function in Delphi 2010. This function takes a string and writes it to a USB printer. I do not know what language the DLL is developed. According to the documentation, the syntax of the function:
int WriteUSB(PBYTE pBuffer, DWORD nNumberOfBytesToWrite);
How can I declare and use my function in Delphi?
I declare the function as follows:
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 as follows:
procedure myProc; var str : string: begin str := 'AAAAAAAAAAAAAAAAAAAAA'; WriteUSB(str,DWORD(length(tmp))); end;
But this code gives me an exception all the time. I know that the problem is that String is Unicode and each character> 1 byte. I tried converting to different types of strings ( AnsiChar and ShortString ), but I failed.
What is the right way to do this?
source share