Mario Marinato
Mario Marinato

Reputation: 4617

ActiveX communication

I'm developing an ActiveX EXE that exposes an specific class to a third-party software. This third-party software instanciates an object of this class and uses its methods.

Strangely, this third-party software destroys its object of my exposed class as soon as it calls an specific method, but I have no idea why this happens.

The only clue I have is that this method is the only one that returns a value. All the other ones are simple 'subs' that do not return any value, and when they are called nothing wrong happens.

I'm using VB6.

Do you guys have any idea of why it's happening?

Upvotes: 0

Views: 548

Answers (2)

dummy
dummy

Reputation: 4284

As Jan stated in COM it is normal, that your object is terminated if no one is referencing it. If you would like to do some kind of caching (e.g. keep the DB connection open), you can use a global variable defined in a bas-module.

basGlobal.bas

Global AGlobalVariable As Object

Connector.cls

Public Function GetFoo() As Object
  If AGlobalVariable Is Nothing then
    Set AGlobalVariable = ...
  End If 
  Set GetFoo = AGlobalVariable
End Function

Upvotes: 0

Jan
Jan

Reputation: 16042

Your object gets "destroyed" when the last reference to it is deleted. Thats normal COM behavior. Or is your object dying unexcepted and the third-party app is getting an activex error?

Some more questions:

  • I don't know what you mean with "data server"?
  • Do you have access to the source code of the third-party app?
  • Are you sure, the third-party app holds a reference to your object?
  • Is your objects Class_Terminate Method called?

EDIT: OK, when Class_Terminate is getting called its obvious, that the third-party app has dropped its reference to your object.

Upvotes: 1

Related Questions