Unloading a dll

This is a discussion on Unloading a dll within the C# Programming forums, part of the General Programming Boards category; How do I unload a dll using c#. Basically what I want to is test if a certain dll has ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    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.
    zMan

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    223

    Question 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);
          }
    }
    zMan

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. non-MFC DLL with MFC app question.
    By Kempelen in forum Windows Programming
    Replies: 10
    Last Post: 08-20-2008, 07:11 AM
  2. dll communicating between each other
    By cloudy in forum C++ Programming
    Replies: 5
    Last Post: 06-17-2005, 02:20 AM
  3. DLL and std::string woes!
    By Magos in forum C++ Programming
    Replies: 7
    Last Post: 09-08-2004, 12:34 PM
  4. .lib vs .h vs .dll
    By Shadow12345 in forum C++ Programming
    Replies: 13
    Last Post: 01-01-2003, 04:29 AM
  5. unloading a dll
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 04-18-2002, 06:03 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21