Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global variables (between dll's, exe's) creation

Status
Not open for further replies.

xcata

Programmer
Jun 27, 2001
39
FR
I need to create some global variables accesible from an exe and some activex dll.
I found a solution by creating a class in the main program , register it in ROT(running object table) and after that in each dll I can get the instance of that class and use all his proprierties/methods.
The only drawback is that when we start 2 or more main programs only the first instance may be accessed, so only the firts instance will work good.

I'm looking for anote solution.
Any help will be apreciated,

Thx, Catalin.
 
You could create an own object table (as an ActiveX Server) where the main app has to enter its objectreference on startup and sets it to nothing on closing. Your dlls could access then the stored object-references in there. The trouble will be to handle main-apps that didn't logoff properly from your own object table.

hope this helps
Andreas
 
Thx for yuor response.
For the main-apps that did not logoff propermy I have a solution. Each time I start a instance of main app I can cleanup this table by finding all main windows and eliminating those wich are not.

The problem I see here is how to make the link between an main application and his modules (dll) respectively his instances of each class.

Catalin.
 
As I did understand you, you've got main apps which act as ActiveX-EXEs. If you've got a collection of this ActiveX-EXEs in your object table you have access to every instance of running main app. So you can gain access to the dlls your main apps are using right through your main app itself. As far I don't see your problem right now.
Say you've got the following situation:
main1 main2 main3 objtbl
\ \ `-----------> col(1)
\ `---------------------> col(2)
`------------------------------> col(3)
Now you can get a reference to your objecttable (define it as singleuse, as you don't want several objecttables...) with say Set objTable = new MyObjTbl.clsObjTable.
Then you can have a property in your clsObjTable which gives you access to col with the main apps in it. with a for each obj in objTable.col you can loop through them and you can access everything the main app allow access to...
Btw the problem with not logging off is a bit more complex. Think of a main app not responding any more. You're objecttable gets blocked and your calling routine also...
Could you specify the problem a little more please?

Andreas
 
The original problem was that:
I need a solution for sharing some data between a exe and all of his components (in activex dll's) without passing parameters each time.
I found a very simple sollution by making a class (cGlobal) wich is instantieted in the main app. I add it to ROT and after that with GetObject I can get acces to that instance of cGlobal. It works very good with a single instance of main app. But there are problems when I have more than one instance of main app. The ideea is that the instance of cGlogal is global but a little too global because it's the same for all the instances of main app. Exactly it's not the only one but the only one accesible.
Today I found a teoretical sollution for that. I will have only one insatnce of cGlobal but in the place of a simple property I will have a collection of values. Each item has like key the ThreadId of main app wich originated the appel. The ThreadId is the same in the dll. So, at least in theory, it should work. If I can make that work, it rest a single problem, when the first main app gets blocked, I don't know what to do.

Any other ideea who may help me to acomplish my goal is welcome.

Thx again,
Catalin.
 
Why don't you use a public property in your dlls to assign the global variables to?
In main-App:
Code:
set objDll = New clsDll
set objDll.GlobalObject = objGlobal
In dlls:
Code:
Public Property set GlobalObject(objpGlobal as cGlobal)
  Set mobjGlobal = cGlobal
End Property

Andreas
 
I got your point but this way I must change all dll's to reference that cGlobal class(and I have many). Another problem is that most of the dll's are loaded when a property of a global multiuse class is used. I know it's dangerous for the programmer but that's it.It's dificult to find the load point for each dll, also, I think it's not good to load all of the dll's in main procedure.

Anyway thx for the ideea.

Catalin.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top