python 调用dll 参数_python调用dll
python源码
# 调用ctpes 组件
from ctypes import *
if __name__ == '__main__':
# 调用需要调用的dll, dll中的方法都可以使用了
dll= CDLL("DemoDll.dll")
# python中默认类型是int,可以直接调用 returnAddInt方法
print dll.returnAddInt(1,2)
# float类型demo 多参
#设置返回类型
dll.returnAddFloat.restype=c_float
#设置参数类型(多参可以用小括号表示)
dll.returnAddFloat.argtypes=(c_float,c_float)
print dll.returnAddFloat(1.2,2.3)
#float类型demo 单参
dll.returnFloat.restype = c_float
# 单参数需要使用中括号
dll.returnFloat.argtypes = [c_float]
print dll.returnFloat(1.2)
# char类型demo
dll.returnChar.restype = c_char
dll.returnChar.argtypes = [c_char]
print dll.returnChar("x")
# char* 类型demo
dll.returnPoint.restype = c_char_p
dll.returnPoint.argtypes = [c_char_p]
print dll.returnPoint("xyz")
# 结构体类型 demo
# 定义类名
class MyStruct(Structure):
#定义参数名与参数类型
_fields_=[('value',c_int)]
dll.returnMyStruct.restype =MyStruct
dll.returnMyStruct.argtypes = [c_int]
s=dll.returnMyStruct(2)
print s.value
# int* demo
dll.getIntP.restype=c_int
#定义类型为指针类型
dll.getIntP.argtypes=[POINTER(c_int)]
# 建立 int* 实例
a = c_int(1)
c = POINTER(c_int)(a)
print dll.getIntP(c)
c
#include "DemoDll.h"
char returnChar(char a) {
return a;
}
int returnAddInt(int a, int b) {
return a + b;
}
float returnAddFloat(float a, float b) {
return a + b;
}
float returnFloat(float a) {
return a;
}
char* returnPoint(char * s) {
printf("helloWorld");
return s;
}
struct MyStruct
{
int value;
};
struct MyStruct returnMyStruct(int a) {
struct MyStruct m;
m.value = a;
return m;
}
int getIntP(int* i) {
return i;
}
.h
#pragma once
#include
__declspec(dllexport) char returnChar(char a);
__declspec(dllexport) int returnAddInt(int a, int b);
__declspec(dllexport) float returnFloat(float a);
__declspec(dllexport) float returnAddFloat(float a, float b);
__declspec(dllexport) char* returnPoint(char * s);
__declspec(dllexport) struct MyStruct returnMyStruct(int a);
__declspec(dllexport) int getIntP(int* i);
python 调用dll 参数_python调用dll相关推荐
- python什么模块动态调用链接库_Python调用C/C++动态链接库的方法详解
本文以实例讲解了Python调用C/C++ DLL动态链接库的方法,具体示例如下: 示例一: 首先,在创建一个DLL工程(本例创建环境为VS 2005),头文件: 1 2 3 4 5 6 7 8 9 ...
- python调用c 接口_python调用C接口
5.结构体定义 我们用 fields = [('name1',type1),('name2',type2)]来表示结构体的成员 字节对齐 C结构体中经常会出现按照指定的字节进行对齐结构体,用pack来 ...
- python 方法的实例_python调用自定义函数的实例操作
在python中,想要调用自定义函数必须先声明,然后才能调用.使用函数时,只要按照函数定义的形式,向函数传递必需的参数,就可以调用函数完成相应的功能或者获得函数返回的处理结果. (1)声明函数 pyt ...
- python 接收外部参数_python 接收处理外带的参数方法
python 接收处理外带的参数方法 在执行python 代码的时候,有时候需要传递外面的参数进行处理 这个该怎么实现呢? 需要一个模块 from sys import argv 当然也可以直接只导入 ...
- python中函数参数_Python函数的参数
本章将介绍函数中参数的用法,更多内容请参考:Python学习指南 定义函数的时候,我们把参数的名字和位置确定下来,函数的接口定义就完成了.对于函数的调用者来说,只需要知道传递正确的参数,以及函数就返回 ...
- python自定义函数参数_python自定义函数的参数之四种表现形式
(1)def a(x,y):print x,y 这是最常见的定义方式,调用该函数,a(1,2)则x取1,y取2,形参与实参相对应,如果a(1)或者a(1,2,3)则会报错 (2)def a(x,y=3 ...
- python函数可变参数_python中函数的可变参数
知识回顾: 1.函数关键字参数 2.函数的参数的默认值.必须从右边写到左边. 本节视频教程 文字教程开始: 一.[其实已经用过]可变参数 回顾系统自带的可变参数函数print #系统自带的可变参数函数 ...
- python获取命令行参数_Python获取命令行参数的正确方法,案例详解
最近编写一个python程序的时候,需要去获取python命令行的参数,因此这里记录下如何获取命令行参数的方法. 一.sys 模块 在 Python 中,sys 模块是一个非常常用且十分重要的模块,通 ...
- python 命令行 参数_Python命令行参数
python 命令行 参数 Python Command line arguments are input parameters passed to the script when executing ...
最新文章
- java jtextpane插入图片_java中怎么在JTextArea中添加图片?
- Java对象排序、中文排序、SortedSet排序使用和源码讲解
- 黑白树(牛客网+树形dp)
- JEECG再创新举,开辟支付宝服务窗开发新时代,业内独家培训 《支付宝服务窗实战培训》
- MicrosoftFixit50688 [Windows7事件ID10,WMI错误的解决方法
- 【Android】Mac安装EasyTether导致无法识别设备的问题
- 中望CAD的引线标注格式怎么改_大神总结的CAD设计五个段位 快来看看你在哪个阶段...
- lb开金矿 QDUOJ 数论
- 44款最适合海报设计的英文字体
- spss20安装许可证代码_Spss 23软件下载与安装
- 常用计算机操作技巧与方法ppt,相见恨晚的20个常用PPT小技巧
- 体育新闻html模板,HTML5响应式体育新闻资讯类门户网站模板源码+自适应移动端...
- ROS2.9.27架设网吧软路由实战篇之端口映射与回流
- 网络子系统32_网桥设备的开启与关闭
- 如何捕获电脑病毒样本
- 使用cmd命令行查看Windows系统激活信息
- 在MATLAB中采用M文件实现对Simulink中的S函数程序实现自动调参数
- 普通话读音 - 平舌音 / 前舌音 / 舌尖前音 - 翘舌音 / 卷舌音 / 舌尖后音
- 压铸件浇口去除导致裂纹与缺料问题的分析与解决
- realplayer java,不同浏览器调用realplayer插件在线播放视频的有关问题,请大神们进来看看...