Hi all,
I have a 32bit VB6 DLL which has two functions. I want to access those functions from my 32bit version of python. First issue is that I can't seem to see the functions when I load the dll:
from ctypes import *
dll = WinDLL("ARB_Library.dll")
dll.ARB_Value
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python_32bit\lib\ctypes\__init__.py", line 387, in __getattr__
func = self.__getitem__(name)
File "C:\Python_32bit\lib\ctypes\__init__.py", line 392, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'ARB_Value' not found
I know that the function is in the DLL by inspecting OLE/COM Object Viewer:
// Generated .IDL file (by the OLE/COM Object Viewer)
// typelib filename: ARB_Library.dll
[
uuid(D1DA3979-1AFE-493E-A6FD-AB5466C226A6),
version(1.0),
custom(50867B00-BB69-11D0-A8FF-00A0C9110059, 8964)
]
library ARB_Library
{
// TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
importlib("stdole2.tlb");
// Forward declare all types defined in this typelib
interface _clsARB_Library;
[
odl,
uuid(98414811-7EE4-44A3-8AFF-7B9B6789D7A4),
version(1.0),
hidden,
dual,
nonextensible,
oleautomation
]
interface _clsARB_Library : IDispatch {
[id(0x68030001), propget]
HRESULT ARB_Value(
[in, out] double* PdblListedP,
[in, out] double* PdblNewP,
[in, out] DATE* PdateValDate,
[in, out] DATE* PdatePastDate,
[in, out] short* PintTripNumber,
[in, out] VARIANT_BOOL* PbolPayment,
[out, retval] double* );
I understand that you can access the function by using the ordinal and so I tried the following:
func = dll[0x68030001]
func
<_FuncPtr object at 0x035129C8>
This gives a pointer to *a* function (the function?) ... so I am hoping that I am on the right path. But I am unable to see anything in this function to confirm whether it is the ARB_Value function that I am after.
The next step is to then try to call the function, but despite using various combinations of inputs including pointers (only one example given below), I cannot get anything back other than "nan". So I suspect that the function is not the one that I am after.
prototype = WINFUNCTYPE(
c_double,
POINTER(c_double), POINTER(c_double), POINTER(c_double), POINTER(c_double), POINTER(c_short), POINTER(VARIANT_BOOL))
paramflags = (1, "PdblListedP", 0), (1, "PdblNewP", 0), (1, "PdateValDate", 0), (1, "PdatePastDate", 0), (1, "PintTripNumber", 0), (1, "PbolPayment", 0))
dll_api = prototype((1745027073, dll), paramflags)
PdblListedP = c_double(28)
PdblNewP = c_double(27.02)
PdateValDate = c_double(41052)
PdatePastDate = c_double(42147)
PintTripNumber = c_short(1)
PbolPayment = VARIANT_BOOL(0)
answer = dll_api(byref(PdblListedP), byref(PdblNewP), byref(PdateValDate), byref(PdatePastDate), byref(PintTripNumber), byref(PbolPayment))
Any suggestions as to how I can access the ARB_value function in this DLL, and then how to pass the correct variables to it so that it returns a value?
Thanks!
What I have tried:
Using comtypes to generate the code for me, but this did not help in accessing the function.