Python:
使用
ctypes
库调用外部
DLL
一
、
Python
之
ctypes
ctypes
是
Python
的
一
个
外
部
库
,
提
供
和
C
语
言
兼
容
的
数
据
类
型
,
可
以
很
方
便
地
调
用
C DLL
中
的
函
数
。
在
Python2.5
官
方
安
装
包
都
带
有
ctypes 1.1
版
。
ctypes
的
官
方
文
档
在
这
里
。
ctypes
的
使
用
非
常
简
明
,
如
调
用
cdecl
方
式
的
DLL
只
需
这
样
:
view sourceprint?1 from ctypes import *;
2 h=CDLL('msvcrt.dll')
3 h.printf('a=%d,b=%d,a+b=%d',1,2,1+2);
以
上
代
码
运
行
后
输
出
a=1,b=2,a+b=3
。
二、加载库和普通函数的调用
官方
API
提供的库中有几个主要的函数:
view sourceprint?01 //
初始化
02
int
DCSPCLIENTDLL
InitInterface(
const
char
*pCenterIP,
const
unsigned
short
nUpLinkSvrPort,const unsigned short nDownLinkSvrPort );
03
04 //
释放资源
05 int DCSPCLIENTDLL FiniInterface( void );
06
07 //
登录
08
int
DCSPCLIENTDLL
Login(
const
unsigned
int
uiBranchPlatformID,
const
unsigned
int
nUserID,
const char *pPassword );
09 //
注销