Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 帮助ctypes.windell.dnsapi.DnsQuery\u A_Python_Winapi_Dns_Ctypes - Fatal编程技术网

Python 帮助ctypes.windell.dnsapi.DnsQuery\u A

Python 帮助ctypes.windell.dnsapi.DnsQuery\u A,python,winapi,dns,ctypes,Python,Winapi,Dns,Ctypes,我在[DnsQuery](API,*ppQueryResultsSet参数方面遇到了问题。有人能给我举个例子,说明如何在python中进行正确的DLL调用吗 import ctypes from ctypes import wintypes from windns_types import DNS_RECORD, IP4_ARRAY #declared here http://pastebin.com/f39d8b997 def DnsQuery(host, type, server, op

我在[DnsQuery](API,*ppQueryResultsSet参数方面遇到了问题。有人能给我举个例子,说明如何在python中进行正确的DLL调用吗

import ctypes
from ctypes import wintypes
from windns_types import DNS_RECORD, IP4_ARRAY #declared here http://pastebin.com/f39d8b997


def DnsQuery(host, type, server, opt=0):
    server_arr = IP4_ARRAY()
    rr = DNS_RECORD()
    server_arr.AddrCount=1
    server_arr.AddrArray[0] = ctypes.windll.Ws2_32.inet_addr(server)
    ctypes.windll.dnsapi.DnsQuery_A(host, type, opt, server_arr, rr, 0)
    # WindowsError: exception: access violation reading 0x00000001

    return rr

print DnsQuery("www.google.com", 1, "208.67.222.222")

它不是指向
DNS\u记录的指针吗?
?这意味着您必须将rr初始化为
指针(DNS\u记录)(
),并通过引用传递它:
ctypes.byref(rr)


更新:但我认为您看到的问题是传递
服务器arr
:您传递的结构的第一个字段是
0x00000001
,而不是引用此结构,因此C代码尝试取消对
AddrCount
字段的引用,并给您访问冲突。同样的技术应该用于
server_arr
也是。

@ChristopheD,我真的很想,但看起来没有人回答。为什么是
ctypes.POINTER(DNS_记录)(
不是
ctypes.POINTER(DNS_记录())
?看起来仍然存在访问冲突读取0x00000001I C world分配一个指向结构的指针和分配一个结构并获取指向它的指针是不同的。虽然
ctypes.pointer(DNS_RECORD())
也应该工作,但我不确定这是正确的方法。