Python COM Variant problem

A

Annie

I am trying to call a COM object which expects a variant datatype to
be passed in to the COM API object. However, I get "<COMObject
<unknown>>" and the program fails.

Below is my code in Python, and the same code in VB which is working
fine...

I guess this is a variant problem with python? How can I make this
work? Would appreciate if someone can guide me as I am a python
newbie... :)

Thanks very much...

##In Python
def setAddOnValue(oBusObj
oAddOns = oBusObj.AddOns
print oAddOns #returns "<COMObject <unknown>>"
print oAddOns.Count #return 3
for x in range(1, oAddOns.Count):
oAddOn = oAddOns.Item(x) #expects variant datatype for the x
variable



##In VB
Public Function setAddOnValue(oBusObj As Variant, strAddOnLabel As
String, strPropLabel As String, oVal As Variant) As Boolean
Dim x, y
Dim oAddOns As CAddOns
Dim oAddOn As CAddOn
Dim oAddOnValues As CAddOnValues
Dim oAddOnValue As CAddOnValue

setAddOnValue = False
Set oAddOns = oBusObj.AddOns

For x = 1 To oAddOns.Count
Set oAddOn = oAddOns.Item(x)
If oAddOn.AddOnName = strAddOnLabel Then
Set oAddOnValues = oAddOn.AddOnValues
For y = 1 To oAddOnValues.Count
Set oAddOnValue = oAddOnValues.Item(y)
If oAddOnValue.PropertyLabel = strPropLabel Then
setAddOnValue = True
Set oAddOnValue.Data = oVal
Exit For
End If
Next y
End If
If setAddOnValue = True Then
Exit For
End If
Next x
End Function
 
R

Roger Upole

Try running makepy on the typelib that contains the objects.
Also, the actual error msg that if fails with would be helpful.
Roger
 
A

Annie

hi Roger,
10s for replying..
i do running the makepy on that typelib. but can u pls teach me on
how to include to my Python program??
10s in advance
 
R

Roger Upole

Normally if you've run makepy, the support should be invoked automatically
when you create an instance. What do you get back when you use
win32com.client.gencache.EnsureDispatch ?
Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top