-
Unloading a dll
How do I unload a dll using c#. Basically what I want to is test if a certain dll has been loaded if it has then I want to remove it from memory. The reason is that I want to overwrite the dll file but I can't overwrite it since the dll is being used. The dll that I am trying to unload is written in probably c or c++ so it is unmanaged code.
-
unloading a dll
OK I found how to get the process and the modules that are attached to those modules... now how do I remove these modules from memory... any help will be greatly appreciated...
Code:
private void Form1_Load(object sender, System.EventArgs e)
{
try
{
System.Diagnostics.Process[] ps = Process.GetProcesses();
string s = "";
for(int i = 0; i < ps.Length; i++)
{
s += "\r\n" + ps[i].ProcessName;
try
{
foreach(ProcessModule childModule in ps[i].Modules)
{
s += "\r\n " + childModule.ModuleName;
if(childModule.ModuleName.ToUpper() == "MYDLL.DLL")
{
//OK so I found my module now
//How do I unload this module from memory
}
}
}
catch
{
}
}
MessageBox.Show(s);
}
catch(Exception exc)
{
MessageBox.Show(exc.Message);
}
}