我进入电影交流写的DLL函数,原型为:调用DLL函数
#include "extcode.h"
#pragma pack(push)
#pragma pack(1)
#ifdef __cplusplus
extern "C" {
#endif
void __stdcall PSA_Send_BO(char hostname[], char BO_NumberIn[],
char BO_NumberOut[], int16_t *Status, char Error_text[], int32_t *Error_code,
int32_t *length_BO_NumberOut, int32_t *length_error_text);
long __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);
#ifdef __cplusplus
} // extern "C"
#endif
#pragma pack(pop)
我的Delphi代码:
procedure Aaa(HostNaam: PChar; BO_To: PChar; BO_From: PChar; ErrorText: PChar;
var OutputLength: LongInt; var ErrorLength: LongInt;
var ErrorNumber: Longint
) ; far; stdcall; external 'aaa.dll'
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
BO_From, ErrorText: Array[0..999] of Char;
ErrorLength, BoLength, ErrorNumber: LongInt;
begin
Aaa(PChar(edtHostName.Text), PChar(edtBoNumber.Text), BO_From, ErrorText, BoLength, ErrorLength, ErrorNumber);
Label1.Caption := 'BO_From = ' + BO_From ;
Label2.Caption := 'BoLength = ' + IntToStr(BoLength);
Label3.Caption := 'ErrorText = ' + ErrorText;
Label4.Caption := 'ErrorLength = ' + IntToStr(ErrorLength);
Label5.Caption := 'ErrorNumber = ' + IntToStr(ErrorNumber);
end;
当我运行这个例子中,返回的字符串BO_From
和ErrorText
是空的,所有其他返回的参数都可以。
当我注释其中一行显示返回的参数时,字符串显示的很好! 使用调试器进入代码具有类似的效果。 在显示它们之前复制所有返回的参数不起作用。 返回的字符串的长度远低于声明的大小。
有人有任何线索吗?
在此先感谢您的帮助,
屌
感谢您的回复。 已经尝试过你的建议,问题依然存在... – user415496 2010-08-09 20:52:37
哎呀,你不错! 我现在已经解决了问题,是的,我必须提前设置ErrorLength和BoLength。 谢谢唐老师的建议! – user415496 2010-08-16 07:33:38