Re: Class object creation and managing automation references




<hooksie2@xxxxxxxxxxx> wrote in message
news:1129041337.573014.300410@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>I have created a class module which handles exchange of data and
> commands between xl and a third party software via an automation server
> (hope I have the correct terminology here!). When an instance of the
> class is initialised it automatically creates a reference to the server
> object using 'CreateObject(...)'
>
> However, I have now found that the "server" does not handle multiple
> references very well. In some situations both programs simply hang and
> I can't even go into break mode my xl vba code.
>
> What I would prefer however is if I could somehow check whether a
> server instance already exists from within my class object and if it
> does simply reference that existing reference, ie. something like:
> Private Sub Class_Initialize()
> On Error Resume Next
> Set m_objServer = GetObject(,"PX32.OpenServer.1")
> If Err.Number <> 0 Then
> Set m_objServer = CreateObject("PX32.OpenServer.1")
> End If
> End Sub
>
> However, GetObject always gives an error - even when I know I have
> already created a reference. Is there any other way to do this?
> Should this work or have I misunderstood something?
>

As I read the documentation on GetObject, it would return an error when the path
argument is omitted only if the class was registered as single use:
"If an object has registered itself as a single-instance object, only one
instance of the object is created, no matter how many times CreateObject is
executed. With a single-instance object, GetObject always returns the same
instance when called with the zero-length string ("") syntax, and it causes an
error if the pathname argument is omitted."

I am guessing here, since you haven't given the details, but I suspect that
A. You have an activex.exe, that is, an out of process server;
B. It is marked to be a single instance, that is, the class or classes have
Instancing = SingleUse;
C. You are actually creating only one instance of the server object, and
referencing it several times;
D. The problem is not with this setup, but in the way you use the class in
various places.


.



Relevant Pages


Loading