Windows, Python calls the DLL example to show how to pass the byte stream parameter to the DLL interface

Source: Internet
Author: User

Work on the need to use Python call DLL parsing stream output to a file, how to call DLL many blogs have a description, please refer to the following blog:
How to invoke please refer to:
http://blog.csdn.net/lf8289/article/details/2322550
For Windll and Cdll options, please refer to:

http://blog.csdn.net/jiangxuchen/article/details/8741613

To pass a custom structure, please refer to:

Http://www.jb51.net/article/52513.htm



But how to use a string of strings as a byte-code to pass to the DLL's interface, see the code in this document:


#encoding: Utf-8
‘‘‘
Created on March 5, 2015




@author: Administrator
‘‘‘
Import ctypes,string
if __name__ = = "__main__":
#两个字符代表一个字节的字符串码流
hexstring = ' 000c40808300000600080003404105001a00504f170a16e65b110748100bf664f01080001ff43748065805f070c040115264f01000005c0a005702200 03103e5e03e11035758a6200b601404ef6523021e242ca040080402600400021f025d0104e0c1004300060064f0100000006440080064f0100183bcb0 00864001300060000607c0f4374806 '
Hexstring_len = Len (hexstring)
#接口原型: Pltedllrnlcdecode (ubyte,uint,uint,ubyte*,ubyte,char*)
DLL = cTYPES. Cdll (' Lte_de_000_110729.dll ')
Parser = DLL. Ltedllrnlcdecode
Parser.argtypes = [Ctypes.c_ubyte, Ctypes.c_uint, Ctypes.c_uint, Ctypes.c_char_p, Ctypes.c_uint, Ctypes.c_char_p]
Parser.restypes = ctypes.c_void_p

data_id = Ctypes.c_ubyte ()
Data_id.value = 0

msg_id = Ctypes.c_uint ()
Msg_id.value = 57612

Data_len = Ctypes.c_uint ()
Data_len.value = HEXSTRING_LEN/2


reserved = Ctypes.c_uint ()
Reserved.value = 0


#将码流字符串按2字节转换为byte串
Char_array = [' 0 ']*data_len.value
i = 0
j = 0
While I < hexstring_len:
byte = String.atoi (hexstring[i:i+2],16)
CHAR_ARRAY[J] = Chr (byte)
i = i + 2
j = j + 1
Print Char_array
SS = '. Join (Char_array)
#byte串转成接口需要的byte *
Data_buffer = Ctypes.c_char_p ()
Data_buffer.value = SS

# for I in range (len (ss)):
# Char_array[i]=ord (Ss[i])
# Print Char_array
#buffer = cTYPES. POINTER (Ctypes.c_ubyte)
#buffer. Value =

outfile = Ctypes.c_char_p ()
Outfile.value = "OUT.txt"

Parser (data_id, msg_id, Data_len,data_buffer,reserved,outfile)

Windows, Python calls the DLL example to show how to pass the byte stream parameter to the DLL interface

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.