[python-win32] Ctypes and PdhMakeCounterPath

Steve Bonam sbonam at gmail.com
Thu Sep 3 19:28:00 CEST 2009


I'm trying to learn ctypes so I figured I'd reproduce something I did
earlier with pywin32 but it seems I fail it.
I'm sure I'm missing something here

PdhMakeCounterPath Doc on msdn:
http://msdn.microsoft.com/en-us/library/aa372649%28VS.85%29.aspx

[code]

from ctypes import *
from ctypes.wintypes import *

pdh = windll.pdh

class PDH_COUNTER_PATH_ELEMENTS_A(Structure):

    _fields_ = [("szMachineName",LPSTR),
                ("szObjectName",LPSTR),

                ("szInstanceName", LPSTR),
                ("szParentInstance",LPSTR),

                ("dwInstanceIndex", DWORD),
                ("szCounterName",LPSTR)]

pCounterPathElements = PDH_COUNTER_PATH_ELEMENTS_A(LPSTR(None),
LPSTR('Network Interface'), LPSTR("Realtek RTL8168C[P]_8111C[P] Family
PCI-E GBE NIC") , LPSTR(None), DWORD(-1), LPSTR("Bytes Received/sec"))
szFullPathBuffer = LPCSTR(0)
pcchbufferSize = DWORD(0)
dwFlags = DWORD(0)

result = pdh.PdhMakeCounterPathA(pCounterPathElements,

                                 pointer(szFullPathBuffer),
                                 pointer(pcchbufferSize), dwFlags)

#szFullPathBuffer = create_string_buffer(pcchbufferSize.value)
#result = pdh.PdhMakeCounterPathA(pCounterPathElements,
#                                 pointer(szFullPathBuffer),
#                                 pointer(pcchbufferSize), dwFlags)

[/code]

this is where I am stuck:
>>> result
-2147481646 or 0x800007d2L Which is PDH_MORE_DATA
but pcchbufferSize does not change (i'm pretty sure it's supposed to
be updated with the correct amount to allocate for szFullPathBuffer)
and upon running the function again python freezes and windows kills
it (probably access violation?).



-- 

-steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20090903/0d3684e8/attachment.htm>


More information about the python-win32 mailing list