0

I like to use a unregistered COM DLL within my Python application. The COM DLL functions should be able to load at runtime without using regsrv32.exe before. I tried the approach pointed out here. https://flylib.com/books/en/2.9.1.219/1/

from ctypes import oledll, windll, cdll
import win32com.client

dll_oledll = oledll[r'myCOM.dll']
result_oledll = dll_oledll.DllRegisterServer()

Unfortunately this leads to the following access denied error.

result_oledll = dll_oledll.DllRegisterServer()
  File "_ctypes/callproc.c", line 948, in GetResult
PermissionError: [WinError -2147024891]

What does this error mean, what do I do wrong here?

Lama
  • 83
  • 7
  • PermissionError, -2147024891 is E_ACCESSDENIED. Try run this as admin. – Simon Mourier Sep 06 '21 at 07:40
  • Many thanks for your hint. Runing the code as admin would work. Now I'm basically at the same problem using regsrv32.exe. I would like to avoid using admin rights because the code should be used from users without admin rights. Any ideas how to accomplish this? – Lama Sep 06 '21 at 18:58
  • It depends how the dll is coded. A COM dll can register in HKLM (the usual default) or HKCU (rare). If it's coded for HKLM, there's nothing you can do. – Simon Mourier Sep 07 '21 at 05:43
  • I know that the same COM DLL will used within a C++ application where the DLL will loaded without registration using DllGetClassObject(). Unfortnuately I don't have the code. I guess it is done like mentioned here: https://stackoverflow.com/questions/2187425/how-do-i-use-a-com-dll-with-loadlibrary-in-c Now I wonder if that can be achieved within Python? – Lama Sep 10 '21 at 10:09
  • If this dll supports direct call using DLL export, then yes, you don't have to register and should be able to use it directly (I don't known enough python for that) – Simon Mourier Sep 10 '21 at 11:01

0 Answers0