1

I've been working with win32 in Python standard library when I came across PyHANDLE objects but I couldn't to find its module for annotation purposes. Does anyone know its module? Thanks in advance.

Megacodist
  • 132
  • 5
  • I think that my answer is correct, but it might be out of context. You are saying that you " came across `PyHANDLE` objects" but you didn't add a reference. Can you please add links or examples to the places where you came across it? – Rotem Jun 13 '23 at 06:59

1 Answers1

0

According to the documentation of pywin32, PyHANDLE is and object of type pywintypes.HANDLE.

PyHANDLE Object
A Python object, representing a win32 HANDLE.

Comments
This object wraps a win32 HANDLE object, automatically closing it when the object is destroyed. To guarantee cleanup, you can call either PyHANDLE::Close, or win32api::CloseHandle. Most functions which accept a handle object also accept an integer - however, use of the handle object is encouraged.

The following post quatutes the above documentation.

The following documentation page shows how to create the PyHANDLE object (but misses the import statement).


Example for creating PyHANDLE object (including the import statement):

import pywintypes

PyHANDLE = pywintypes.HANDLE()

It seems that PyHANDLE is a naming convention for an object of type pywintypes.HANDLE().

I suppose the true use case is for wrapping an Windows handle that returned as an integer.

Example:

import pywintypes
import win32gui
import cv2
import numpy as np

cv2.imshow('window', np.zeros((100, 100), np.uint8))

hwnd = win32gui.FindWindow(None, "window")  # Return handle as an integer

PyHANDLE = pywintypes.HANDLE(hwnd)  # Wrap the integer with HANDLE object
Rotem
  • 30,366
  • 4
  • 32
  • 65