免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 9088 | 回复: 5
打印 上一主题 下一主题

请教Ctypes调用dll问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-07-17 15:07 |只看该作者 |倒序浏览
dll,很简单,2个函数代码如下:
library Project1;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }

uses
  SysUtils,
  Classes;

{$R *.RES}
function PlusNum(x,y:integer):integer;stdcall;
begin
     result:=x+y;
end;

function MinusNum(x,y:integer):integer;stdcall;
begin
     result:=x-y;
end;

exports
PlusNum index 1,
MinusNum index 2;


begin
end.



在python shell里这样调用
mydll=ctypes.cdll.LoadLibrary('project1.dll')
mydll.PlusNum(1,2)

提示出错,请问该如何调用?
Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
ValueError: Procedure called with not enough arguments (8 bytes missing) or wrong calling convention
>>>

论坛徽章:
0
2 [报告]
发表于 2007-07-17 18:29 |只看该作者
CDLL, WinDLL 调用传递的参数是有区别的。

论坛徽章:
0
3 [报告]
发表于 2007-07-18 08:47 |只看该作者
CDLL ,WinDLL ,能否介绍下区别?使用方法?

我上面的DLL用WinDLL可以使用。谢谢

论坛徽章:
0
4 [报告]
发表于 2007-07-18 09:58 |只看该作者
参数传递是从左到右, 还是从右到左,还有压栈的参数的处理, 具体的用GOOGLE 查查。

论坛徽章:
0
5 [报告]
发表于 2007-07-26 15:36 |只看该作者

回复 #3 jasonnbfan 的帖子

简单的说就是CDLL针对cdecl的函数调用方式,WinDLL针对stdcall的函数调用方式,因为windows api大部分都是__stdcall的

论坛徽章:
0
6 [报告]
发表于 2007-07-26 23:55 |只看该作者
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP