python - dll access (ctypes or swig)

Larry Bates larry.bates at websafe.com
Tue Apr 17 17:43:19 EDT 2007


Daniel Watrous wrote:
> Hello,
> 
> I am interested in using python to script access to some hardware for
> which there are existing drivers in the form of DLLs.  The DLLs each
> have four exported functions and a host of COM Properties and COM
> Methods.  The four exported functions are as follows:
> DllCanUnloadNow
> DllGetClassObject
> DllRegisterServer
> DllUnregisterServer
> 
> The COM methods and properties all begin with I, followed by a unique name.
> 
> I am able to load the DLL using ctypes and it can access the exported
> functions, but I'm not sure how to access the COM methods and
> properties.  I have read that ctypes once had support for COM but that
> it has since been separated into its own project.  I couldn't find any
> information about how these work together.
> 
> All help is appreciated.  THANKS in advance...
> 
> Daniel

I recently learned that you can ship COM as either an .EXE or a .DLL (nobody
has yet let me know why).  You don't have a traditional .DLL that you would
use ctypes to call methods in, you have a COM .DLL.  COM methods need to be
access with Win32com

obj=win32com.client.Dispatch("typelib name").

You need to find out the COM dispatch typelib name and make sure the DLL is
registered (regsvr32 your.dll).

-Larry



More information about the Python-list mailing list