Skip to content

Commit

Permalink
[server\localserver.py] Use OleDLL instead of oledll
Browse files Browse the repository at this point in the history
  • Loading branch information
moi15moi committed Jan 25, 2025
1 parent 8977aa4 commit a7cc4d5
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions comtypes/server/localserver.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging
import queue
import sys
from ctypes import byref, c_ulong, c_void_p, oledll
from ctypes import HRESULT, POINTER, OleDLL, Structure, byref, c_ulong, c_void_p
from ctypes.wintypes import DWORD, LPDWORD
from typing import TYPE_CHECKING, Any, Literal, Optional, Sequence, Type

import comtypes
from comtypes import hresult
from comtypes._post_coinit.unknwn import IUnknown
from comtypes.GUID import GUID
from comtypes.server import IClassFactory

if TYPE_CHECKING:
Expand All @@ -21,6 +23,17 @@
REGCLS_SUSPENDED = 4 # register it as suspended, will be activated
REGCLS_SURROGATE = 8 # must be used when a surrogate process

_ole32 = OleDLL("ole32")

REFCLSID = POINTER(GUID)
_CoRegisterClassObject = _ole32.CoRegisterClassObject
_CoRegisterClassObject.argtypes = [REFCLSID, POINTER(Structure), DWORD, DWORD, LPDWORD]
_CoRegisterClassObject.restype = HRESULT

_CoRevokeClassObject = _ole32.CoRevokeClassObject
_CoRevokeClassObject.argtypes = [DWORD]
_CoRevokeClassObject.restype = HRESULT


def run(classes: Sequence[Type[comtypes.COMObject]]) -> None:
classobjects = [ClassFactory(cls) for cls in classes]
Expand Down Expand Up @@ -52,7 +65,7 @@ def _register_class(self) -> None:
ptr = self._com_pointers_[comtypes.IUnknown._iid_]
clsctx = self._cls._reg_clsctx_
clsctx &= ~comtypes.CLSCTX_INPROC # reset the inproc flags
oledll.ole32.CoRegisterClassObject(
_CoRegisterClassObject(
byref(comtypes.GUID(self._cls._reg_clsid_)),
ptr,
clsctx,
Expand All @@ -62,7 +75,7 @@ def _register_class(self) -> None:
self.cookie = cookie

def _revoke_class(self) -> None:
oledll.ole32.CoRevokeClassObject(self.cookie)
_CoRevokeClassObject(self.cookie)

def CreateInstance(
self,
Expand Down

0 comments on commit a7cc4d5

Please sign in to comment.