Python论坛  - 讨论区

标题:[python-chinese] 请问如何用ctypes进行byte数组的参数传递?

2007年04月03日 星期二 12:08

熊大 damnya在gmail.com
星期二 四月 3 12:08:15 HKT 2007

ÎÒÓÐÒ»¸öcдµÄdll exportÁËÒ»¸ö½âÂ뺯Êý
void DecodeStream£¨unsigned char * szBuffer, unsigned char *szKey, unsigned
long dwKeyLen£©;
Ïëͨ¹ýpythonÀ´µ÷ÓÃÕâ¸öº¯Êý,°´ÍøÉÏÒ»¸ö´«µÝc_doubleÊý×éµÄÀý×ÓдÁËÒ»¶Î´úÂë,ÀÏÊÇͨ¹ý²»ÁË:
FileKey = "1234567890ABCDEF"
hFileIn = open(DataFile, "rb")
BinaryContent = hFileIn.read()
BufLen = BinaryContent
szBuf = [c_byte]*BufLen
szBuf = struct.unpack('s'*BufLen, BinaryContent)

try:
    DecodeBuf = cdll.LoadLibrary("Cipher.dll").DecodeStream
    #cdecl way to call function
    DecodeBuf .argtypes = [POINTER(c_byte), c_int, c_char_p, c_int]
    res = DecodeBuf (szBuf, c_int(BufLen), c_char_p(FileKey), c_int(0x104))
    if res == 1:
        print szBuf
except WindowsError:
        print "Fail to Load Cipher.dll\n"
print "Fail to Decode"

Èç¹û°´ÕâÑùд¾Í»áÌáʾ:
Traceback (most recent call last):
  File "C:\123.py", line 51, in ?
    res = DecodeBuf (szBuf, c_int(BufLen), c_char_p(FileKey), c_int(0x104))
ctypes.ArgumentError: argument 1: exceptions.TypeError: Don't know how to
convert parameter 1

Ó¦¸ÃÔõôÐ޸IJÅÐÐÄØ?
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070403/2a62b397/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号