此处列举一下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. 安装python3并新建python3的虚拟环境

    安装依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel -y 下载P ...

  2. Mahmoud and Ehab and the message

    Mahmoud wants to send a message to his friend Ehab. Their language consists of n words numbered from ...

  3. Shashlik Cooking

    Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simu ...

  4. Java传(2)

    __________________________夜夜都是魂牵梦绕. 题目: 有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月有生一对兔子,假如兔子都不死,问每个月的兔子 ...

  5. linux安装Zookeeper及redis集群

    亲测有效: 1.linux下安装zookeeper:https://www.cnblogs.com/zuolun2017/p/8186254.html 2.linux下安装redis集群:https: ...

  6. 参考 ZTree 加载大数据量。加载慢问题解析

    参考 ZTree 加载大数据量. 1.一次性加载大数据量加载说明 1).zTree v3.x 针对大数据量一次性加载进行了更深入的优化,实现了延迟加载功能,即不展开的节点不创建子节点的 DOM. 2) ...

  7. IntelliJ IDEA 2017.3尚硅谷-----配置 Maven

  8. 普及C组第三题(8.13)

    2334. [NOIP普及组T2]战斗 (File IO): input:fight.in output:fight.out 时间限制: 1000 ms  空间限制: 524288 KB 开始贴图:. ...

  9. C++-POJ1988-Cube Stacking[数据结构][并查集]

    int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);} #include <set> #include <map> #inc ...

  10. Virtual Judge POJ 2251 Dungeon Master

    三维数组加宽搜 #include <stdlib.h> #include <string.h> #include <stdio.h> ; int c, k, h; ...