DELPHI调用VC写的动态链接库问题

mabinde 2003-07-01 10:43:46
我用VC写了个动态链接库:
t.h:
extern "C" _declspec(dllexport) int caul(int i);
t.cpp
#include "stdafx.h"
#include "t.h"

extern "C" _declspec(dllexport) int caul(int i)
{
return i++;
}
delphi调用:
unit2.pas
unit Unit2;

interface
function caul(i:Integer):Integer; stdcall;

implementation

function caul;external 'd.DLL' name 'caul';
end.
unit1.pas
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
begin
i:=2;
edit1.Text:=inttostr(caul(i));
end;
为什么每次运行的时候都告诉我非法操作啊,哪位知道啊,谢谢拉

...全文
68 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
mabinde 2003-07-02
  • 打赏
  • 举报
回复
我把stdcall改成cdecl就好了。
还有动态连接库里面可不可以有VC的类的啊
Behard 2003-07-01
  • 打赏
  • 举报
回复
是不是别的地方出错呀
我的从来没有出错的
firetoucher 2003-07-01
  • 打赏
  • 举报
回复
function caul(i:Integer):Integer; stdcall;external 'd.DLL' name 'caul';
Eastunfail 2003-07-01
  • 打赏
  • 举报
回复
HOHO~~这个无所谓.....只是你用MFC APPWizard(DLL)的话,你应该懂得MFC.而用Win32 Dynamic-link Library就没有必要懂MFC了.

stdcall和cdecl是函数的调用约定(Calling Convention),相关的还有register,pascal,safecall.
可以看Delphi的帮助(关键字:stdcall):

Directive Parameter order Clean-up Passes parameters in registers?
register Left-to-right Routine Yes
pascal Left-to-right Routine No
cdecl Right-to-left Caller No
stdcall Right-to-left Routine No
safecall Right-to-left Routine No
mabinde 2003-07-01
  • 打赏
  • 举报
回复
我在建VC的动态链接库的时候,要在DELPHI中调用,是建MFC APPWizard(dll),还是WIN32 Dynamic-link Library,这两个有什么不一样啊。
动态连接库里面可不可以有VC的类的啊
mabinde 2003-07-01
  • 打赏
  • 举报
回复
怎么用DEF文件导出啊?
还有firetoucher(风焱) 说的stdcall和outer2000(天外流星) 加的cdecl有什么不一样啊
Eastunfail 2003-07-01
  • 打赏
  • 举报
回复
楼上的说法不正确.
external 引用的文件名是跟操作系统相关的,而不是具体的编程语言,而MS的操作系统文件名是大小写不敏感的,所以即使写成
function caul;external 'D.DlL' name 'caul';
也不会错,但是
function caul;external 'd.dll' name 'cauL';
就会错,就算是Delphi生成的DLL,对于函数的导出名一样是大小写敏感的
星星 2003-07-01
  • 打赏
  • 举报
回复
function caul;external 'd.DLL' name 'caul';

改为
function caul;external 'd.dll' name 'caul';


注意大小写,VC是大小写敏感的!
outer2000 2003-07-01
  • 打赏
  • 举报
回复
function caul(i:Integer):Integer; cdecl;external 'd.DLL' name 'caul';
flyingkiller 2003-07-01
  • 打赏
  • 举报
回复
加上stdcall
李_军 2003-07-01
  • 打赏
  • 举报
回复
在VC中导出dll,一定要用.def文件导出,否则delphi找不到函数入口
nzh517 2003-07-01
  • 打赏
  • 举报
回复
用DELPHI调VC的写DLL应该问题不是很大,至少能调,但用VC调DELPHI写的DLL问题大了,,

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧