Problem mapping VB com code to Python

Ahmed MOHAMED ALI ahmedmo at wanadoo.fr
Fri Dec 19 13:01:18 EST 2003


Hello,

try this

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

Ahmed

"max" <max at theslimmers.net> wrote in message
news:4f55e45a.0312191451.73b8f84b at posting.google.com...
> 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 =============
> >>> o = win32com.client.Dispatch("QBFC2_1Lib.QBSessionManager")
> 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)






More information about the Python-list mailing list