0

I am new to python Ctypes, i use GetDevicePowerState function I don't know how to input hDevice ?

https://learn.microsoft.com/zh-TW/windows/win32/api/winbase/nf-winbase-getdevicepowerstate

import ctypes as ct
from ctypes import wintypes as w

Kernel32 = ct.WinDLL('Kernel32')

Kernel32.GetDevicePowerState.argtypes = w.HANDLE,w.BOOLEAN
Kernel32.GetDevicePowerState.restype = w.BOOLEAN

hDevice = 'USB'
pfOn = True

result = Kernel32.GetDevicePowerState(hDevice,pfOn)

print(result)
Mark Tolonen
  • 166,664
  • 26
  • 169
  • 251
  • See: https://stackoverflow.com/q/20047647/437212 (This is a suggestion that you could have done a little more research, here and on the internet.) –  May 27 '22 at 14:54
  • I don't understand the meaning of handles – user19212551 May 29 '22 at 02:48
  • You might need to research Windows API "handles" then, and then ask _that_ question. Handles are not limited to this API, but are a Windows programming API concept. For USB you can get a device handle back from another call. See https://learn.microsoft.com/en-us/windows-hardware/drivers/wdf/working-with-usb-devices –  May 31 '22 at 15:32
  • It turned out to be handle but I don't know how to write it I'm a newbie – user19212551 May 31 '22 at 17:17
  • This is a fundamental Win32 concept best researched in the usual places. SO is not really a good place for tutorials. –  Jun 01 '22 at 16:58

0 Answers0