Problem mapping VB com code to Python

A

Ahmed MOHAMED ALI

Hello,

try this

obj = win32com.client.Dispatch("QBFC2_1.QBSessionManager")

Ahmed
 
M

max

I am trying to use a sdk to access quickbooks, the sdk provided a COM
interface and I think it installed the com server files/dlls. A VB
code example is provided, but I can't figure out how to map "Dim
sessionManager As New QBFC2_1Lib.QBSessionManager"
into a corresponding Python statement, when I try
obj = win32com.Client.Dispatch("QBFC2_1Lib.QBSessionManager") I get
traceback Shown below.

I have been able to run makepy and it generates a lovely file. I can
find a Type Library, but need a little help mapping this to be able to
access the com object and call its methods.

I have included a snipit of the sample VB code and the traceback from
my attempt to create a client com object ?

Any help much appreciated,

max



=======Traceback =============Traceback (most recent call last):
File "<interactive input>", line 1, in ?
File "C:\Python23\lib\site-packages\win32com\client\__init__.py",
line 95, in Dispatch
dispatch, userName =
dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Python23\lib\site-packages\win32com\client\dynamic.py",
line 84, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Python23\lib\site-packages\win32com\client\dynamic.py",
line 72, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
pythoncom.IID_IDispatch)
com_error: (-2147221005, 'Invalid class string', None, None)




========= Sample VB code ==========
Option Explicit

Public Sub Main()

On Error GoTo ErrHandler

'Establish a communication channel with QuickBooks

'Create the session manager object, and initiate a conversation
with QuickBooks
Dim sessionManager As New QBFC2_1Lib.QBSessionManager
sessionManager.OpenConnection " ", "QBFC Developer's Guide"
sessionManager.BeginSession "", omDontCare


'Build a set of requests - in this case, containing only one
request

'Create the request set (the message set request object)
Dim requestSet As QBFC2_1Lib.IMsgSetRequest
'Create a qbXML version 2.1 message
Set requestSet = sessionManager.CreateMsgSetRequest(2, 1)

'Add a request to the request set.
Dim customerAdd As QBFC2_1Lib.ICustomerAdd
'AppendCustomerAddRq is called only once here, even though two
values are being set.
Set customerAdd = requestSet.AppendCustomerAddRq
customerAdd.Name.SetValue "Joe"
customerAdd.CustomerTypeRef.FullName.SetValue "East Coast"

'Indicate that all requests should be processed, even if one has
an error
requestSet.Attributes.OnError = roeContinue


'Send the request set to QuickBooks

Dim responseSet As QBFC2_1Lib.IMsgSetResponse
Set responseSet = sessionManager.DoRequests(requestSet)
 
M

max

No luck, I have tried all possible case combinations and permutations
of what I see in the com brouser. The only place I have found
references to the com module qbFC2_1Lib is in the "Registered Type
Libraries".

Is there another way to access the com module then client.Dispatch()?

What is the mapping of the VB statememnt
" Dim sessionManager As New QBFC2_1Lib.QBSessionManager"
does this imply something other than late binding.

When I ran makepy it generated a file containing lots of information
about the module, I don't know how to figure out what it means.

How is the output of makepy used, can it tell me something about how
to connect to the corresponding COM module>

I am really at a loss here, I don't understand enough about COM or VB
to figure this out.

max
 
M

Mark Hammond

max said:
No luck, I have tried all possible case combinations and permutations
of what I see in the com brouser. The only place I have found
references to the com module qbFC2_1Lib is in the "Registered Type
Libraries".

Is there another way to access the com module then client.Dispatch()?

What is the mapping of the VB statememnt
" Dim sessionManager As New QBFC2_1Lib.QBSessionManager"
does this imply something other than late binding.

This is VB using early binding, and using vtable interfaces rather than
IDispatch.

I'm really not sure why this is failing for you though - if the problem
was that the object did not support IDispatch, I would expect an
"unsupported interface" exception. It may just be that you have to find
the correct progID for use in this context. Can you find VB code that
uses CreateObject() on the object?

Mark.
 
P

Paul Paterson

I had a similar problem with a different library that would early bind in VB
but wouldn't work with win32com.client.Dispatch. IIRC I got around it by
hunting in the registry with regedit for likely looking class ID's
("SomeLibrary.SomeObject"). It is also possible that the VBP file will
contain the GUID which you can then use in a registry search to find a class
ID.

It may be a shot in the dark but in my case when the VB code was,

Dim S As MYLIB.Server
Set S = MYLIB.DefaultServer

the corresponding Python ended up being,

c = win32com.client.Dispatch("MYLIB.MYLIB")
s = c.DefaultServer

I'm not sure if this will work in your case but I think if you search the
registry for "QBFC" you might turn something up.

Paul
 
M

max

Thanks to you and Mark, you were both correct, I simply needed to find
the correct invocation of the ProgId :)

max
 

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

No members online now.

Forum statistics

Threads
474,173
Messages
2,570,937
Members
47,481
Latest member
ElviraDoug

Latest Threads

Top