免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: Heaice
打印 上一主题 下一主题

python调用DLL问题(急) [复制链接]

论坛徽章:
0
1 [报告]
发表于 2009-01-06 11:20 |显示全部楼层
test.DLL中封装了几个函数
int A()
int B(int Handle, ref long Len_s1, ref long Len_s2)

python中调用
from ctypes import *

test = CDLL("test")

A = test.A
A.restype = c_int

B = test.B
B.restype = c_int
B.argtypes = [c_int, c_void_p, c_void_p]

#然后通过引用来调用
va1 = 0
va2 = 0
s2 = B( A(), byref(va1), bref(va2) )

论坛徽章:
0
2 [报告]
发表于 2009-01-07 10:30 |显示全部楼层
#! /usr/env/python
from ctypes import *
test = CDLL("testdll"
A = test.A
A.restype = c_int
B = test.B
B.restype = c_int
B.argtypes = [c_int, c_void_p, c_void_p]
va1 = c_int()
va2 = c_int()

s2 = B(A(), byref(va1), byref(va2) )
print s2, va1, va2


// 测试dll的头文件
#ifndef  TEST_DLL_H
#define  TEST_DLL_H
#define DLLPORT __declspec(dllexport)
extern "C" DLLPORT int A();
extern "C" DLLPORT int B(int handle, int *s1, int* s2);
#endif

// 测试dll的实现文件
#include "testdll.h"
int A()
{
return 1;
}
int B(int handle, int *s1, int* s2)
{
*s1 = 76;
*s2 = 88;
return handle;
}

BOOL APIENTRY DllMain( HANDLE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
      )
{
    return TRUE;
}


# 输出结果:
1 c_long(76) c_long(8

因此,你应该仔细查看你的dll返回值是否正确,而不是去判断python的代码是否有问题!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP