Need help calling a proprietary C DLL from Python

sturlamolden sturlamolden at yahoo.no
Thu Mar 20 18:26:23 EDT 2008


On 20 Mar, 19:09, Craig <craigm3... at gmail.com> wrote:

> The following is the C++ prototype for one of the functions:
> short FAR PASCAL VmxOpen(BSTR    *Filespec,
>                          LPSHORT  lpLocatorSize,
>                          LPSHORT  lpOmode,
>                          LPHANDLE lphwmcb,
>                          BSTR    *Password);


import ctypes
import comtypes

LPBSTR = ctypes.POINTER(comtypes.BSTR)
HANDLE = ctypes.POINTER(ctypes.POINTER(ctypes.c_long))
LPHANDLE = ctypes.POINTER(HANDLE)
LPSHORT = ctypes.POINTER(ctypes.c_short)

VmxOpen = ctypes.windll.vbis5032.VmxOpen
VmxOpen.restype = c_short
VmxOpen.argtypes = [LPBSTR, LPSHORT, LPSHORT, LPHANDLE, LPBSTR]


Filespec = comtypes.BSTR('blahblahblah')
LocatorSize = ctypes.c_short(256)
Omode = ctypes.c_short(1)
hwmcb = HANDLE()
Password = comtypes.BSTR('blahblahblah')


res = WmxOpen( byref(Filespec), byref(LocatorSize),
   byref(Omode), byref(hwmcb), byref(Password) )


or if that fails:

pFilespec = ctypes.pointer(Filespec)
pLocatorSize = ctypes.pointer(LocatorSize)
pOmode = ctypes.pointer(Omode)
phwmcb = ctypes.pointer(hwmcb)
pPassword = ctypes.pointer(Password)

res = WmxOpen( pFilespec, pLocatorSize, pOmode, phwmcb, pPassword )

















More information about the Python-list mailing list