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 ...
随机推荐
- K-means VS K-NN and 手肘法
1. The difference between classification and clustering. from here. Classification: supervised learn ...
- OpenGL基本图元类型
GL_POINTSGL_LINESGL_LINE_STRIPGL_LINE_LOOPGL_TRIANGLESGL_TRIANGLE_STRIPGL_TRIANGLE_FANGL_QUADSGL_QUA ...
- Lombok(浅看,自用)
Lombok 首先是几个常用的注解(最常用到的方法,超简单的用) @Data @AllArgsConstructor @NoArgsConstructor public class Trial_Pro ...
- JS高级---函数作为返回值使用
函数作为返回值使用 function f1() { console.log("f1函数开始"); return function () { console.log("函数 ...
- 钉钉内网穿透工具在windows的使用。
钉钉内网穿透工具在windows环境下使用 1.WIN+R,然后cmd,调出dos控制台 2.进入内网穿透程序ding.exe所在目录 3.执行 ./ding.exe -config=ding.cfg ...
- 测试理论 - Test Double
概述 简述 test double mock, fake 之类的东西 背景 最近在看 google 软件测试之道 妈的 13 年的老书了 书里有提到 mock, fake, stub 刚好, 我又不太 ...
- Go_sql注入
我们任何时候都不应该自己拼接SQL语句! sqlInjectDemo("xxx' or 1=1#") sqlInjectDemo("xxx' union select * ...
- fader
fader在音频处理中是比较基础的处理.通常用于平滑的调节音量,或是音频的渐入和渐出效果. 比较常见的fader有line和cubic线型的fader. line fader即fader的渐变过程是线 ...
- EAC3 Transient Pre-Noise Processing
Transient pre-noise processing用于减少pre-noise的长度,pre-noise产生于low bitrate 编码存在transient matiral的场景. 当使用 ...
- 使用datatable动态添加的顺序与存储的顺序不一致
原因是datatable在展示数据的时候帮助我们排序了 将其禁止排序即可:"ordering":false