一个用VC写的dll,导出如下函数:
BOOL WINAPI Ini (char * ID, char * IP);
void WINAPI Stop();
BOOL WINAPI SI(int i, char* Str,Char* PStr, int iCN,int iCS);
BOOL WINAPI Check();
BOOL WINAPI CF();
BOOL WINAPI F1();
BOOL WINAPI F6();我在delphi中写了对应的函数(如下),为什么在VC调用出错?
BOOL WINAPI Ini (char * ID, char * IP);
function Ini (ID :pchar; IP:pchar):boolean;stdcall;export;void WINAPI Stop();
procedure Stop();stdcall;export;BOOL WINAPI SI(int i, char* Str,Char* PStr, int iCN,int iCS);
function SI(i:integer; Str:pchar;PStr:pchar; iCN:integer;iCS:integer ):boolean;stdcall;export;BOOL WINAPI Check();
function Check():boolean;stdcall;export;BOOL WINAPI CF();
function CF():boolean; stdcall;export;BOOL WINAPI F1();
function F1():boolean; stdcall;export;BOOL WINAPI F6();
function F6():boolean; stdcall;export;请大侠指点。我在google及delphibbs的离线数据库找过了,都不能解决问题。我把上面的stdcall先后换成了cdecl、pascal、safecall,也不行
BOOL WINAPI Ini (char * ID, char * IP);
void WINAPI Stop();
BOOL WINAPI SI(int i, char* Str,Char* PStr, int iCN,int iCS);
BOOL WINAPI Check();
BOOL WINAPI CF();
BOOL WINAPI F1();
BOOL WINAPI F6();我在delphi中写了对应的函数(如下),为什么在VC调用出错?
BOOL WINAPI Ini (char * ID, char * IP);
function Ini (ID :pchar; IP:pchar):boolean;stdcall;export;void WINAPI Stop();
procedure Stop();stdcall;export;BOOL WINAPI SI(int i, char* Str,Char* PStr, int iCN,int iCS);
function SI(i:integer; Str:pchar;PStr:pchar; iCN:integer;iCS:integer ):boolean;stdcall;export;BOOL WINAPI Check();
function Check():boolean;stdcall;export;BOOL WINAPI CF();
function CF():boolean; stdcall;export;BOOL WINAPI F1();
function F1():boolean; stdcall;export;BOOL WINAPI F6();
function F6():boolean; stdcall;export;请大侠指点。我在google及delphibbs的离线数据库找过了,都不能解决问题。我把上面的stdcall先后换成了cdecl、pascal、safecall,也不行
Delphi中的声名格式:
Function ShowDialog( hMainWnd:THandle; Msg:PChar ):integer; stdcall;
输出到Dll文件中时,名称不分裂。VC中的调用格式: extern "C" __declspec(dllimport) int __stdcall ShowDialog( HWND hwnd,char* Msg );.如带有__stdcall,则要求Lib文件中对应函数名称分裂,可有以下步骤生成Lib文件:
.用Impdef.exe生成def文件,格式为:Impdef def文件名 dll文件名
.手工调制def文件参数,如ShowDialog改为ShowDialog@8
.用Lib.exe生成lib文件,格式为:Lib /def:def文件名
.如声名中无__stdcall,默认调用格式仍为stdcall,但不要求名称分裂,用以下批处理文件MkLib.bat可生成Lib文件:
@echo off
if %1.==. goto error
impdef %1.def %1.dll
lib /def:%1.def
goto end
:error
echo Usage: MkLib DllName
echo Note: Don't add extension ".dll" to parameter "DllName"
:end
Program: G:\zgs\test\debug\test.exe
Module:
File:i386\chkesp.c
Line :42 The value of ESP was not properly saved across a function call. This is usually a result Of calling a function declared with one calling convention with a function pointer declared with a different calling convention. (press Retry to debug the application)
dll文件放在程序目录或者windows目录system下。
同志,你是调用还是改写??
你本来有VC的dll,用vc调用,怎么还要用delphi再费事地改一遍?
是用delphi写dll让vc调用。已经是在程序目录,其他用得到的dll我也放到程序目录了。引用“你本来有VC的dll,用vc调用,怎么还要用delphi再费事地改一遍?”
一言难尽啊,上头说要,我就做了,没法。小兵一个,没法知道太多。to:all
我又试了用delphi调用原来的vc做的dll,没问题,可以成功调用。说明给我的文档没问题
还有什么
我写的delphi dll代码如下:library Project1;//uses
// SysUtils,
// Classes;{$R *.RES}
function Ini(ID:pchar; IP:pchar):boolean;stdcall;
begin
//todo something;
result:=true;
end;procedure Stop();stdcall;
begin
end;
function SI(i:longint; Str:pchar;PStr:pchar; iCN:longint;iCS:longint):boolean;stdcall;
begin
Result:=true;
end;function Check():boolean;stdcall;
begin
Result:=true;
end;function CF():boolean;stdcall;
begin
result:=true;
end;function F1():boolean;stdcall;
begin
result:=true;
end;function F6():boolean;stdcall;
begin
result:=true;
end;exports
Ini,
Stop,
SI,
Check,
CF,
F1,
F6;begin
end.
unit XXXXXXXXXXXX;
interface
uses
function Ini(ID: PChar;
IP: PChar): Bool stdcall ;procedure Stop stdcall ;function SI(i: Integer;
Str: PChar;
PStr: PChar;
iCN: Integer;
iCS: Integer): Bool stdcall ;function Check: Bool stdcall ;function CF: Bool stdcall ;function F1: Bool stdcall ;function F6: Bool stdcall ;
implementationfunction Ini; external 'A.DLL';
procedure Stop; external 'A.DLL';
function SI; external 'A.DLL';
function Check; external 'A.DLL';
function CF; external 'A.DLL';
function F1; external 'A.DLL';
function F6; external 'A.DLL';end.
原因是index值与原dll不一样。
改为:
exports
ini index 1,
...就可以了。