[python-win32] Using COM DLL

Tim Roberts timr at probo.com
Wed Aug 13 08:00:32 CEST 2014


On Aug 12, 2014, at 4:28 AM, Christiaan B v Zyl <christiaanvanzyl at gmail.com<mailto:christiaanvanzyl at gmail.com>> wrote:
I have a DLL, it is an SDK for the Pastel Partner accounting system. Using Dependency Walker I can see that the DLL has the following methods: DllRegisterServer, DllUnregisterServer, DllGetClassObject

With the library there came a sample VB program that referenced the DLL and instantiated it like this:
Dim SDK As New PasSDK.PastelPartnerSDK

The only way I've been able to use this library from python is to register it with Windows:
regsvr32 PasSDK.dll

And then use it in python like this:
import win32com.client
sdk = win32com.client.Dispatch(PasSDK.PastelPartnerSDK")
sdk.SetLicense(...)
etc...

However, is there a way to use this library directly without registering it first? Something like:
from ctypes import *
sdk = cdll.LoadLibrary('PasSDK.dll')

When I do this I can see that sdk.DllGetClassObject is a function, but how do I instantiate it like the VB program, is it possible?

Are you saying that the VB program works correctly without registering the DLL first?

COM servers are always accessed through the registry.  The only way the operating system know where to look for the DLL is by looking in the registry.  From the “PasSDK.PastelPartnerSDK” class name, it finds the COM class GUID.  From the GUID, it finds the path to the DLL.

Now, regsvr32 does nothing except load the DLL and call DllRegisterServer.  So, you could, in fact, do this:
    sdk = cdll.LoadLibrary(‘PasSDK.dll’)
    sdk.DllRegisterServer()

and then call Dispatch.  I’m not sure this is any better than, for example:
    os.system(‘regsvr32 passdk.dll’)

--
Tim Roberts, timr at probo.com<mailto:timr at probo.com>
Providenza & Boekelheide, Inc.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20140812/f14c8aca/attachment.html>


More information about the python-win32 mailing list