来自dll的回调函数传递垃圾字符串?

Callback function from dll pass garbage string?

我正在使用 EPSON Advanced Printer Driver,当我打开状态时 API 我将打印机名称作为参数传递给 DLL,当我读取 Checks it return 结果作为回调过程时( GetMicrDataEx) 和我传递给 BiOpenMonPrinter 的打印机名称。 一切正常,除了回调函数中的打印机名称就像垃圾数据。

BiOpenMonPrinter:函数(nType:LongInt;pName:PAnsiChar):LongInt; cdecl; // pName :指定打印机名称(例如:"EPSON TM-H6000II Receipt")。

    @BiMICRSetReadBackEx:= getprocaddress(libraryhnd,PAnsiChar('BiMICRSetReadBackFunctionEx'));

//BiMICRSetReadBackEx Lib 'EpsStmApi.Dll" 
BiMICRSetReadBackEx:Function( nHandle : LongInt;{int} CallBack:TProcedurePortName; {int}
             Var readBuffSize : Integer; {LPBYTE} readCharBuff : Pointer; {LPBYTE}
             pStatus : Pointer; pDetail : Pointer): LongInt; Stdcall;

我将 GetMicrDataEx 作为回调过程传递。 问题是当我收到回调时,打印机名称是带有垃圾章程的长字符串

Procedure GetMicrDataEx(sPrintername:PAnsiChar); 
begin
//I receive garbage for printer name
end;

BiOpenMonPrinter:

Makes Status API available for the printer and returns the handle.

BiMICRSetReadBackFunctionEx:

Executes reading of checks by BiMICRReadCheck and registers the address of the callback function when the results are notified as well as the memory addresses where each type of information read from the check is set.

非常感谢你的帮助 谢谢

这很可能是因为调用约定不匹配。您的 GetMicrDataEx 回调使用 register 调用约定。 DLL 可能需要一个使用 stdcall 的函数。让GetMicrDataExstdcall解决问题

请注意,我不得不做出很多猜测才能写出这个答案,因为这个问题只涉及互操作界面的一侧。对于此类问题,您确实需要包括互操作界面的两侧。