[python-win32] Passing Arrays by Reference

Jens B. Jorgensen jens.jorgensen@tallan.com
Wed, 06 Nov 2002 15:03:37 -0600


This is a cryptographically signed message in MIME format.

--------------ms040203090507080900080005
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Things seem to work fine for me. I created a test ActiveX DLL in VB with 
a single object. Here's the code for it:

Public Sub DoArrayThing(larr() As Long)
  Dim i As Long
  For i = LBound(larr) To UBound(larr)
    larr(i) = larr(i) + 1
  Next i

End Sub

Then in python here's what I get:

ActivePython 2.2.1 Build 222 (ActiveState Corp.) based on
Python 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> from win32com.client import Dispatch
 >>> o = Dispatch('TestArray.ArrManip')
 >>> o.DoArrayThing(range(0, 4))
(1, 2, 3, 4)
 >>> a = _
 >>> o.DoArrayThing(a)
(2, 3, 4, 5)
 >>>

So it looks like everything python is doing is all fine and good with 
the arrays.

Erignac, Charles A wrote:

>I am calling a method on a COM object that fills in an array passed by
>reference. The array must be initialized to a given size otherwise the call
>will fail. Currently I am able to complete the call and the array returned
>by the method is the one I passed as a parameter but unfortunately the value
>of the array does not change and it should. For your information the COM
>object I work with is a Position interface maintained by the CATIA COM
>server. The method is Sub GetComponents(CATSafeArrayVariant array). I
>understand that the CATSafeArrayVariant type is equivalent to an array of
>variants.
>The python call looks like this:
>	a = range(0,12)
>	b = myPosition.GetComponents(a)
>	print a # outputs (0,1,2,3,4,5,6,7,8,9,10,11) instead of the actual
>components
>	print b # same output
>
>The call is an early binding thanks to pygen.
>I would appreciate any help regarding this problem. I would like at least to
>know where to look in the win32com code to understand what is going wrong.
>Best regards,
>
>Charles
>
>
>_______________________________________________
>Python-win32 mailing list
>Python-win32@python.org
>http://mail.python.org/mailman/listinfo/python-win32
>  
>

-- 
Jens B. Jorgensen
jens.jorgensen@tallan.com

"With a focused commitment to our clients and our people, we deliver value through customized technology solutions"  


--------------ms040203090507080900080005
Content-Type: application/x-pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature

MIAGCSqGSIb3DQEHAqCAMIACAQExCzAJBgUrDgMCGgUAMIAGCSqGSIb3DQEHAQAAoIIJmjCC
AyswggKUoAMCAQICAwdmRzANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCWkExFTATBgNV
BAgTDFdlc3Rlcm4gQ2FwZTESMBAGA1UEBxMJQ2FwZSBUb3duMQ8wDQYDVQQKEwZUaGF3dGUx
HTAbBgNVBAsTFENlcnRpZmljYXRlIFNlcnZpY2VzMSgwJgYDVQQDEx9QZXJzb25hbCBGcmVl
bWFpbCBSU0EgMjAwMC44LjMwMB4XDTAyMDUwNjE0NDQ0MVoXDTAzMDUwNjE0NDQ0MVowZjES
MBAGA1UEBBMJSm9yZ2Vuc2VuMQ0wCwYDVQQqEwRKZW5zMRcwFQYDVQQDEw5KZW5zIEpvcmdl
bnNlbjEoMCYGCSqGSIb3DQEJARYZamVucy5qb3JnZW5zZW5AdGFsbGFuLmNvbTCCASIwDQYJ
KoZIhvcNAQEBBQADggEPADCCAQoCggEBALpRu41RjbKdgKkVQ4+0r38pZjxYFENSvBSQDup8
NBBC1Dj9oUkuEHuwJYg0jjYO4GdOT2QBhozGP+MUuxqYXQv2Kd0gP9lkSMhCkn+XggvEnWb/
nbs8J8bYV2Od5juy5i+qXvkyTJ1F7wRACInEMyHZIOR5/z0OPycnhxOxLpzHf0bqjJQj5GVj
vig+42VGFM3/p/pialli3DXQWJnkcFIy5sTZKK4ussztU1wBCXyMm0SdXjXTcxXjGnRRBO4D
j+ACe4jn6NsEMvJF+89iA8pyWNQQYch9QiC3gfwxtauUvJPFnPfmYAknQSMpgAuUl1ORUz6p
hHN/R143i5AIeIkCAwEAAaM2MDQwJAYDVR0RBB0wG4EZamVucy5qb3JnZW5zZW5AdGFsbGFu
LmNvbTAM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