Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[server\__init__.py] Use OleDLL instead of oledll #769

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)