晕 函数名写错了.. function test(name1,name2,name3: pChar):Boolean; cdecl; external xxx.DLL';
是这样吗? function test( c:pchar; d:pchar ): boolean; cdecl;external 'Diff.DLL' name 'test';试了一下,的确可以。function test( c:pchar; d:pchar ): boolean; stdcall;external 'Diff.DLL' name 'test';为什么不行呢?能否讲讲stdcall cdecl的区别,如果要用stdcall,vc中应该怎么定义呢?谢谢!
extern "C" double __stdcall MyFunc(int a, double b); extern "C" int CdeclFunc(int a); //By default this is a __cdecl convetionstdcall,cdecl区别是一个是从右边开始出栈,一个是从左边开始
Keyword Stack cleanup Parameter passing __cdecl Caller Pushes parameters on the stack, in reverse order (right to left) __stdcall Callee Pushes parameters on the stack, in reverse order (right to left) __fastcall Callee Stored in registers, then pushed on stack thiscall (not a keyword) Callee Pushed on stack; this pointer stored in ECX 注意有几点不同: 1. 参数入栈方式 2. 堆栈的清理方<有调用方/被调用方> 这些是很重要的 必须一致 否则调用错误。
external xxx.DLL';
function test(name1,name2,name3: pChar):Boolean; cdecl;
external xxx.DLL';
function test( c:pchar; d:pchar ): boolean; cdecl;external 'Diff.DLL' name 'test';试了一下,的确可以。function test( c:pchar; d:pchar ): boolean; stdcall;external 'Diff.DLL' name 'test';为什么不行呢?能否讲讲stdcall cdecl的区别,如果要用stdcall,vc中应该怎么定义呢?谢谢!
extern "C" int CdeclFunc(int a); //By default this is a __cdecl convetionstdcall,cdecl区别是一个是从右边开始出栈,一个是从左边开始
__cdecl Caller Pushes parameters on the stack, in reverse order (right to left) __stdcall Callee Pushes parameters on the stack, in reverse order (right to left) __fastcall Callee Stored in registers, then pushed on stack thiscall (not a keyword) Callee Pushed on stack; this pointer stored in ECX 注意有几点不同:
1. 参数入栈方式
2. 堆栈的清理方<有调用方/被调用方>
这些是很重要的 必须一致 否则调用错误。