5

I have a VB6 COM DLL with a function declared as follows:

Public Function testFunc(ByRef v1 As Long) As Boolean

When I try to call this from Python2.7 using:

var1 = c_long()
VB6DLL.testFunc(X1)

If X1 is var1, then I get the exception: "int() argument must be a string or number, not 'c_long'"

If X1 is yref(var1), then I get the exception: "int() argument must be a string or number, not 'cArgObject'"

If the VB6 function uses ByVal parameters and I send correct parameters from Python, all is well. So how do I send references, since I would like the DLL to modify the values? Why is the ByRef argument becoming an int()?

tosa
  • 411
  • 1
  • 3
  • 23
  • 1
    Well, I found something very interesting... When called by Python2.7, the VB6 COM DLL function returns a tuple of the return value and all ByRef parameters. The ByRef parameters don't even need to be passed in (unless you want to use their values in the function). So this in essence gives the solution, but is this correct, and where is it documented? – tosa Feb 25 '12 at 02:44
  • I don't know much about python, but is there a difference between signed and unsigned longs in Python? – Derek Tomes Feb 25 '12 at 09:26
  • 1
    have you tried passing ctypes.byref(var1) ? I don't have access to VB6 to test. – RuiDC Jul 26 '12 at 15:49
  • I'm not sure how many bytes a c_long() is in Python, but in VB6 a Long is 4 bytes or the equivalent of an int in most other languages. Also a 32-bit vs. 64-bit OS may play a role in the size of a c_long(). – Jim Billig Feb 01 '15 at 07:59
  • can VB6 export functions? that is new for me. – milevyo Dec 02 '15 at 10:22

0 Answers0