ObjPtr not reliable on first use
- From: bainsworld@xxxxxxxxx
- Date: 6 Mar 2007 23:15:59 -0800
I am writing a class module in VBA so that I can more easily manage
automation clients from Access 2002. I need to open Excel workbooks
and wanted to centralise the error handling that can occur which
requires the Excel client to be terminated and restarted (e.g. when an
Excel workbook is corrupt).
In the AppStateMgr class I use a collection to keep track of each
automation client instance and how many objects are referencing the
instance. As suggested instead of keeping a reference to the object
in the collection, I use the ObjPtr function to generate the key for
accessing the collection.
My problem is that when I first call the function to open an instance
of the application, I pass an object parameter ByRef which is Nothing
at the time. Within the function I check if the object is Nothing and
either set it to GetObject or CreateObject depending on whether the
app is actually already running or not. I then calculate the index
value to add some data about the app into my AppState collection using
CStr(ObjPtr(obj)). That is fine.
However when this object reference is passed back from the function
and I calculate CStr(ObjPtr(obj)) again, I get a different value! I
thought that ObjPtr returns the pointer to the interface referenced by
an object variable. Can someone explain to me what is happening here
so I can find someway to make this class work?
.
- Follow-Ups:
- Re: ObjPtr not reliable on first use
- From: Ralph
- Re: ObjPtr not reliable on first use
- Prev by Date: RE: WMP 11 Download Songs from URGE
- Next by Date: Re: Overflowing a Long
- Previous by thread: RE: WMP 11 Download Songs from URGE
- Next by thread: Re: ObjPtr not reliable on first use
- Index(es):
Relevant Pages
|