Problem mapping VB com code to Python

max max at theslimmers.net
Tue Dec 23 21:36:04 EST 2003


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

max

"Paul Paterson" <paulpaterson at users.sourceforge.net> wrote in message news:<vKQFb.249398$do1.161168 at twister.austin.rr.com>...
> > "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)
> >
> 
> 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




More information about the Python-list mailing list