That's simple and intersting, I mistakenly thought it was being passed as a
C structure with the python class as wrapper for it. Thank you.

On Thu, Sep 3, 2009 at 2:21 PM, Tim Roberts <t...@probo.com> wrote:

> Steve Bonam wrote:
> >
> > 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)
> >
>
> I get an error when I run this:
>
> C:\tmp>x.py
> Traceback (most recent call last):
>  File "C:\tmp\x.py", line 32, in <module>
>    pointer(pcchbufferSize), dwFlags)
> ValueError: Procedure probably called with too many arguments (20 bytes
> in excess)
>
> The reason is that Python is trying to pass the elements of the tuple as
> individual parameters, resulting in too many arguments. You need
> "pointer(pCounterPathElements)".
>
> After that, pcchbufferSize is 89 for me.
>
> --
> Tim Roberts, t...@probo.com
> Providenza & Boekelheide, Inc.
>
> _______________________________________________
> python-win32 mailing list
> python-win32@python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to