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

[errorinfo.py] Use WinDLL/OleDLL instead of windll/oledll #755

Merged
merged 1 commit into from
Jan 25, 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
24 changes: 18 additions & 6 deletions comtypes/errorinfo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
from ctypes import *
from ctypes.wintypes import DWORD
from ctypes.wintypes import DWORD, ULONG
from comtypes import IUnknown, HRESULT, COMMETHOD, GUID, BSTR
from comtypes.hresult import *

Expand Down Expand Up @@ -45,26 +45,38 @@ class ISupportErrorInfo(IUnknown):


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

_CreateErrorInfo = _oleaut32.CreateErrorInfo
_CreateErrorInfo.argtypes = [POINTER(POINTER(ICreateErrorInfo))]
_CreateErrorInfo.restype = HRESULT

_GetErrorInfo = _oleaut32.GetErrorInfo
_GetErrorInfo.argtypes = [ULONG, POINTER(POINTER(IErrorInfo))]
_GetErrorInfo.restype = HRESULT

_SetErrorInfo = _oleaut32.SetErrorInfo
_SetErrorInfo.argtypes = [ULONG, POINTER(IErrorInfo)]
_SetErrorInfo.restype = HRESULT


def CreateErrorInfo():
cei = POINTER(ICreateErrorInfo)()
_oleaut32.CreateErrorInfo(byref(cei))
_CreateErrorInfo(byref(cei))
return cei


def GetErrorInfo():
"""Get the error information for the current thread."""
errinfo = POINTER(IErrorInfo)()
if S_OK == _oleaut32.GetErrorInfo(0, byref(errinfo)):
if S_OK == _GetErrorInfo(0, byref(errinfo)):
return errinfo
return None


def SetErrorInfo(errinfo):
"""Set error information for the current thread."""
return _oleaut32.SetErrorInfo(0, errinfo)
return _SetErrorInfo(0, errinfo)


def ReportError(
Expand All @@ -89,7 +101,7 @@ def ReportError(
ei.SetSource(
progid
) # progid for the class or application that created the error
_oleaut32.SetErrorInfo(0, ei)
_SetErrorInfo(0, ei)
return hresult


Expand Down