python调用c++开发的动态库
此处列举一下python调用Windows端动态库。
# *- coding=utf-8 -*
import ctypes
from ctypes import *
import os objdll = ctypes.windll.LoadLibrary("xxx.dll") nRet = objdll.Init()
print("Init = " + str(nRet)) objdll.ResetImageData() # 这个家伙返回值是void类型
# print("ResetImageData = "+str(nRet)) nRet = objdll.LoadImageToMemory("xxx.jpg", 0)
print("LoadImageToMemory = " + str(nRet)) nRet = objdll.Set(xxx, byref(c_int(xxx)), 1)
print("Set = " + str(nRet)) objdll.SetParameter(0, xxx) # 函数SetParameter返回值类型为void
# print("SetParameter = "+str(nRet)) nRet = objdll.SetProcessType(x, x)
print("SetProcessType = " + str(nRet)) nRet = objdll.SetLanguage(0)
print("SetLanguage = " + str(nRet)) nRet = objdll.Recog()
print("Recog = " + str(nRet)) nIndex = 0
strResult = c_wchar_p('') strFieldName = c_wchar_p('')
if nRet > 0:
for nIndex in range(7):
nFieldLenth = 1000
nRet = objdll.GetName(nIndex, strFieldName, byref(c_int(nFieldLenth)))
print("GetFieldName = ")
print(strFieldName.value)
if nRet == 3:
break
if nRet == 0:
nResultLenth = 1000
nRet = objdll.GeResult(nIndex, strResult, byref(c_int(nResultLenth)))
print("GetRecogResult = " + str(nRet))
print(nIndex)
print(strResult.value) nRet = objdll.SaveHeadImage("xxx.jpg");
print("SaveHeadImage = " + str(nRet)) os.system("pause")
重点需要说明的是:
1、支持中文需要:
#*- coding=utf-8 -*
2、python调用dll需要:
import ctypes
from ctypes import *
3、C++接口中参数为LPTSTR在python ctypes中对应:
strResult = c_wchar_p('')
strFieldName = c_wchar_p('')
4、C++接口中的引用,在python ctypes中对应:
byref(c_int(nFieldLenth))
以上代码仅供参考,这些都是很具体的例子,使用中转化成自己需要的。
python调用c++开发的动态库的更多相关文章
- Linux 下Python调用C++编写的动态库
在工程中用到使用Python调用C++编写的动态库,结果报如下错误: OSError: ./extract_str.so: undefined symbol: _ZNSt8ios_base4InitD ...
- 分享:写了一个 java 调用 C语言 开发的动态库的范例
分享:写了一个 java 调用 C语言 开发的动态库的范例 cfunction.h 代码#pragma once#ifdef __cplusplusextern "C" {#e ...
- ios 开发中 动态库 与静态库的区别
使用静态库的好处 1,模块化,分工合作 2,避免少量改动经常导致大量的重复编译连接 3,也可以重用,注意不是共享使用 动态库使用有如下好处: 1使用动态库,可以将最终可执行文件体积缩小 2使用动态库, ...
- java调用dll或so动态库文件(c++/c)
java调用dll或so动态库文件(c++/c) 博客分类: 工作 CC#C++JavaEclipse java调用dll或so动态库文件(c++/c)开发平台:Eclipse3.3.1.1+CD ...
- Qt打开外部程序和文件夹需要注意的细节(Qt调用VC写的动态库,VC需要用C的方式输出函数,否则MinGW32编译过程会报错)
下午写程序中遇到几个小细节,需要在这里记录一下. ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 QProcess *process = new QProcess(this ...
- Delphi调用C# 编写dll动态库
Delphi调用C# 编写dll动态库 编写C#dll的方法都一样,首先在vs2005中创建一个“类库”项目WZPayDll, using System.Runtime.InteropServices ...
- python中调用C++写的动态库
一.环境:Windows XP + Python3.2 1. dll对应的源文件(m.cpp): #include <stdio.h> extern "C" { _de ...
- c++动态库封装及调用(1、动态库介绍)
1.一个程序从源文件编译生成可执行文件的步骤: 预编译 --> 编译 --> 汇编 --> 链接 (1)预编译,即预处理,主要处理在源代码文件中以“#”开始的预编译指令,如宏展开 ...
- iOS 开发新版 动态库framework
0. 参考 http://www.cocoachina.com/industry/20140613/8810.html framework+xib参考 : http://blog.csdn.net/x ...
随机推荐
- 2019牛客多校第七场 F Energy stones 树状数组+算贡献转化模拟
Energy stones 题意 有n块石头,每块有初始能量E[i],每秒石头会增长能量L[i],石头的能量上限是C[i],现有m次时刻,每次会把[s[i],t[i]]的石头的能量吸干,问最后得到了多 ...
- 切换目录命令 - cd
1) 命令名称:cd 2) 英文原意:change directory 3) 命令所在路径:shell 内置命令 4) 执行权限:所有用户 5) 功能描述:切换目录 6) 语法: cd[目录名] 例子 ...
- python3练习100题——014
这题卡了我一整天,然后还是看答案撸了一遍- 原题链接:http://www.runoob.com/python/python-exercise-example14.html 题目:将一个正整数分解质因 ...
- 刷题75. Sort Colors
一.题目说明 题目75. Sort Colors,给定n个整数的列表(0代表red,1代表white,2代表blue),排序实现相同颜色在一起.难度是Medium. 二.我的解答 这个是一个排序,还是 ...
- AOP使用
package com.googosoft.db.aspect; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lan ...
- EAC3 enhanced channel coupling
Enhanced channel coupling是一种spatial coding 技术,在传统的channel coupling的基础上添加了phase compensation, de-corr ...
- (c#)奇数值单元格的数量
题目 解
- springboot引入Oracle依赖
最近学习spring boot,在网上找一些项目学习,有的项目引入了oracle驱动包,自己搭建一直不成功,百度发现说是权限问题无法下载. 然后参考下面博客终于解决:springboot引入Oracl ...
- noobSTL-0-开题报告
noobSTL-0-开题报告 STL介绍 STL是Standard Template Library的简称,中文名标准模板库. STL是一种泛型编程.面向对象编程关注的是编程的数据方面,而泛型编程关注 ...
- c#逐行读取文件到数组
/// <summary> /// 逐行读取文件到泛型数组 /// </summary> /// <param name="FilePath"> ...