此处列举一下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++开发的动态库的更多相关文章

  1. Linux 下Python调用C++编写的动态库

    在工程中用到使用Python调用C++编写的动态库,结果报如下错误: OSError: ./extract_str.so: undefined symbol: _ZNSt8ios_base4InitD ...

  2. 分享:写了一个 java 调用 C语言 开发的动态库的范例

    分享:写了一个 java 调用 C语言 开发的动态库的范例 cfunction.h   代码#pragma once#ifdef __cplusplusextern "C" {#e ...

  3. ios 开发中 动态库 与静态库的区别

    使用静态库的好处 1,模块化,分工合作 2,避免少量改动经常导致大量的重复编译连接 3,也可以重用,注意不是共享使用 动态库使用有如下好处: 1使用动态库,可以将最终可执行文件体积缩小 2使用动态库, ...

  4. java调用dll或so动态库文件(c++/c)

    java调用dll或so动态库文件(c++/c) 博客分类:  工作 CC#C++JavaEclipse  java调用dll或so动态库文件(c++/c)开发平台:Eclipse3.3.1.1+CD ...

  5. 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 ...

  6. Delphi调用C# 编写dll动态库

    Delphi调用C# 编写dll动态库 编写C#dll的方法都一样,首先在vs2005中创建一个“类库”项目WZPayDll, using System.Runtime.InteropServices ...

  7. python中调用C++写的动态库

    一.环境:Windows XP + Python3.2 1. dll对应的源文件(m.cpp): #include <stdio.h> extern "C" { _de ...

  8. c++动态库封装及调用(1、动态库介绍)

    1.一个程序从源文件编译生成可执行文件的步骤: 预编译 -->  编译 -->  汇编 --> 链接 (1)预编译,即预处理,主要处理在源代码文件中以“#”开始的预编译指令,如宏展开 ...

  9. iOS 开发新版 动态库framework

    0. 参考 http://www.cocoachina.com/industry/20140613/8810.html framework+xib参考 : http://blog.csdn.net/x ...

随机推荐

  1. INEQUALITY BOOKS

    来源:这里 Bất Đẳng Thức Luôn Có Một Sức Cuốn Hút Kinh Khủng, Một Số tài Liệu và Sách Bổ ích Cho Việc Học ...

  2. switch case理解

    第一个:分类的思想  ;  第二个就是灵活切换到那一路分支的作用

  3. [AHOI2013] 差异 - 后缀数组,单调栈

    [AHOI2013] 差异 Description 求 \(\sum {len(T_i) + len(T_j) - 2 lcp(T_i,T_j)}\) 的值 其中 \(T_i (i = 1,2,... ...

  4. 最近手机价格全线暴跌真的只是因为5G要来了吗?

    等等党,是一群数量颇大的消费群体.他们的消费习性是绝不买刚上市的新品,而是一直等.等到他们认为产品的价格已经跌无可跌,或者性价比十足的时候再出手.不得不说,与早买早享受的尝鲜消费群体相比,等等党代表了 ...

  5. 【转载】Pig语法进阶

    转自:http://www.cnblogs.com/siwei1988/archive/2012/08/06/2624912.html Pig Latin是一种数据流语言,变量的命名规则同java中变 ...

  6. window环境下获取python安装的路径

    1.cmd + win  打开命令行 2.where python

  7. c#中convert.toInt32和int.parse()和强制类型转换的区别

    string a="123"; int i=(int)a; 这是会出现错误因为:强制类型转换只能转换值类型不能转换引用类型 string属于引用类型    强制类型转换时如果值类型 ...

  8. 抽象语法树 Abstract syntax tree

    什么是抽象语法树? 在计算机科学中,抽象语法和抽象语法树其实是源代码的抽象语法结构的树状表现形式 在线编辑器 我们常用的浏览器就是通过将js代码转化为抽象语法树来进行下一步的分析等其他操作.所以将js ...

  9. 为什么需要激活函数 为什么需要归一化 python内置函数:enumerate用法总结

    为什么需要激活函数 为什么需要归一化 python内置函数:enumerate用法总结 待办 激活函数的用途(为什么需要激活函数)? 如果不用激励函数(其实相当于激励函数是f(x) = x),在这种情 ...

  10. Python | 字符串拆分和拼接及常用操作

    一.字符串拆分 str = "hola ha1 ha2 china ha3 " # partition 从左侧找到第一个目标,切割成三组数据的[元组] str1 = str.par ...