Solved

Unloading ActiveX dlls from a vb app whilst it is running.

Posted on 2004-09-27
6
257 Views
Last Modified: 2012-06-21
Hi all,

(note this is related to another question: http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21146311.html)
I'm writing a application that will eventually have little 'agents' that are running on about 70 computers on a WAN.

Basically, I have a central application that via tcp/ip sends xml commands to these agents, which in turn do 'stuff' based on the xml commands and return a result.

Because the only way i have access to these agents is via a ssh tunnel and vnc, i decided that i really dont want to log onto by opening the tunnel and a vnc session 70 times whenever i need to upgrade the exe. Instead, I have a system where dll's are dynamically loaded based on a config file. the idea being i can just send a xml command (and some binary data) to add new dlls and update the config file so the agent knows how to respond to new xml commands (or to fix any problems in existing dlls).

PROBLEM: I need to be able to unload the activex dll (if it is current instantiated) from the current app so that i can replace the dll file.

I am using CreateObject to load the activex dll

Thanks in advance for your help.
0
Comment
Question by:gimmeadrink
  • 3
  • 3
6 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
Comment Utility
You have to set all the object references from this ActiveX dll to nothing, and ensure that you have NO circular references inside the objects keeping them alive. To enforce this, a "DISPOSE" method of the main object(s) should be implemented to tell the object to fully cleanup and close.

CHeers
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
Another gotcha in that area:
if you have a class defined as global in the activeX dll, and added the activexdll in the references of the calling application, you have to remove this, because this is something you won't be able to unload from the vb app...

CHeers
0
 
LVL 2

Author Comment

by:gimmeadrink
Comment Utility
Ok thanks for that, i will try this today.

I have not added it as a reference because, at the time i build the exe, i have no way of knowing which dlls my agent will eventually need.... so i dont think the second part will be a problem

I did set it to nothing, but I do however have references from within the main class to other classes within the same dll. I never thought about thanks a lot.

If i have a terminate sub in the class, will that be called when i set it to nothing? If not, i could just force each class to have another method that does this. Ill give this a go today sometime, thanks for your ideas so far.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 2

Author Comment

by:gimmeadrink
Comment Utility
Ok, i have given it a shot, but i cant get it to work correctly.

I am pretty confident that i have set all objects in the dll to nothing.

I have also set the main object to nothing (gives an error to indicate this if i try and access it again later), but the dll is still not unloaded.

When i try to override it, its gives me a permission error.

any ideas?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
>>If i have a terminate sub in the class, will that be called when i set it to nothing
The Terminate Event of the class will ONLY be called when ALL of the references to the object have been released. Thus if you create 2 objects that reference each other, you cannot get them released easily unless you have the "dispose" function  which will remove the circular reference(s) ...

You might try to send me the code, so I could look at it... (see my profile for the email, don't forget to remove any confidential settings from the code).
CHeers

0
 
LVL 2

Author Comment

by:gimmeadrink
Comment Utility
Thanks for your help angel

Sorry about the long wait in response, being doing a whole bunch of things at once and couldnt get back to this part of the app straight away.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now