项目中delphi程序调用c语言的dll一切正常,退出时出现错误access violation at 0x...
网上查到貌似与调用约定有关,试验将delphi声明中copy过来的stdcall换成cdecl,成功解决。
dll函数声明:
interface
type
AnotherRecord = record
chars : array[0 .. 511] of char;
end;
PAnotherRecord = ^AnotherRecord;
function echo(ptr:PAnotherRecord) : Integer; cdecl; //stdcall;
implementation
const
YetAnother = 'YetAnother.dll';
function echo; external YetAnother name 'echo';
end.
dll调用:
var ar : AnotherRecord;
ar.chars := 'i can call this shit in dll';
echo(@ar);
c头文件:
typedef struct STR{
char chars[MaxSz];
}STR;
int echo(STR *str);
函数实现:
int echo(STR *str){
printf("%s\n", str->chars);
return 0;
}
网上查到貌似与调用约定有关,试验将delphi声明中copy过来的stdcall换成cdecl,成功解决。
dll函数声明:
interface
type
AnotherRecord = record
chars : array[0 .. 511] of char;
end;
PAnotherRecord = ^AnotherRecord;
function echo(ptr:PAnotherRecord) : Integer; cdecl; //stdcall;
implementation
const
YetAnother = 'YetAnother.dll';
function echo; external YetAnother name 'echo';
end.
dll调用:
var ar : AnotherRecord;
ar.chars := 'i can call this shit in dll';
echo(@ar);
c头文件:
typedef struct STR{
char chars[MaxSz];
}STR;
int echo(STR *str);
函数实现:
int echo(STR *str){
printf("%s\n", str->chars);
return 0;
}