Skip to content

Commit

Permalink
[server\__init__.py] Use OleDLL instead of oledll (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
moi15moi authored Jan 29, 2025
1 parent d305713 commit b7e5bcc
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions comtypes/server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import ctypes
from ctypes import HRESULT, POINTER, byref
from ctypes import HRESULT, POINTER, OleDLL, byref, c_void_p
from ctypes.wintypes import DWORD, LPVOID
from typing import TYPE_CHECKING, Any, Optional, Type

import comtypes
import comtypes.client
import comtypes.client.dynamic
from comtypes import GUID, STDMETHOD, IUnknown
from comtypes.automation import IDispatch
from comtypes.GUID import REFCLSID

if TYPE_CHECKING:
from ctypes import _Pointer
Expand Down Expand Up @@ -67,7 +69,23 @@ def LockServer(self, fLock: int) -> hints.Hresult: ...
ACTIVEOBJECT_STRONG = 0x0
ACTIVEOBJECT_WEAK = 0x1

oleaut32 = ctypes.oledll.oleaut32
_oleaut32 = OleDLL("oleaut32")

_RegisterActiveObject = _oleaut32.RegisterActiveObject
_RegisterActiveObject.argtypes = [
c_void_p,
REFCLSID,
DWORD,
POINTER(DWORD),
]
_RegisterActiveObject.restype = HRESULT

_RevokeActiveObject = _oleaut32.RevokeActiveObject
_RevokeActiveObject.argtypes = [
DWORD,
LPVOID,
]
_RevokeActiveObject.restype = HRESULT


def RegisterActiveObject(comobj: comtypes.COMObject, weak: bool = True) -> int:
Expand All @@ -78,9 +96,9 @@ def RegisterActiveObject(comobj: comtypes.COMObject, weak: bool = True) -> int:
else:
flags = ACTIVEOBJECT_STRONG
handle = ctypes.c_ulong()
oleaut32.RegisterActiveObject(punk, byref(clsid), flags, byref(handle))
_RegisterActiveObject(punk, byref(clsid), flags, byref(handle))
return handle.value


def RevokeActiveObject(handle: int) -> None:
oleaut32.RevokeActiveObject(handle, None)
_RevokeActiveObject(handle, None)

0 comments on commit b7e5bcc

Please sign in to comment.