Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Problem of Unloading Managed C++ DLL...

Problem of Unloading Managed C++ DLL...

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharpc++dotnetvisual-studiodebugging
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chandrap
    wrote on last edited by
    #1

    I am having problem to delete a Managed C++ DLL that was used in a pure C# DLL even in the following scenario. 1. Launch the application. This applicatio has its own default applicaiton domain. 2. Create a new Application Domain. 3. Load the Pure C# DLL in the new applicaiton domain. This C# DLL uses managed C++ DLL. 4. Create a Proxy object using CreateInstanceAndUnwrap for the wrapper object which is a wrapper for the class used from the pure C# DLL. This wrapper object is exported from a seperate DLL. DLL Configuration:- Wrapper for C# DLL, C# DLL, Managed C++ DLL. The wrapper C# is used so that the main C# will not be loaded into the default application domain when creating a Proxy object using the menthod CreateInstanceAndUnwrap. The application domain talks with only the wrapper DLL. If we do not have wrapper class, then the main C# DLL will also be loaded into the default application. The sideeffect of this is that, even when the new application is unloaded, we will not be able to delete the main C# DLL. Wrapper is just a call frowader to the C# DLL class. 5. Give the class name exported from C# DLL to the wrapper object and ask it to create an instance of the class. The wrapper class creates the the class and initializes its membet to it, so that it can forward call requests. 6. From the default application domain, call a method on the wrapper object. This call on the wrapper object calls the method on the C# class. This C# class uses a function exported from a managed C++ DLL. 7. After executing the methods, unload the new application domain. 8. Now try to delete C# DLL, Mananged C++ DLL. I was able to delete C# DLL, but not MC++ DLL. After further investigation I found that the Visual Studio "Output" window has the following two lines:- 'Application.exe': Loaded 'C:\DLL1\Debug\MCPP.dll', Symbols loaded.----> LOADING FIRST TIME 'Application.exe' (Managed): Loaded 'C:\DLL1\Debug\MCPP.dll', Symbols loaded. ----> LOADING SECOND TIME When the method on C# class is getting executed, the output log file contains the above two lines. The .NET framework is loading it twice. Once as Native C++ DLL, second time as Managed DLL. Does any one know how to delete the MC++ DLL.

    L 1 Reply Last reply
    0
    • C chandrap

      I am having problem to delete a Managed C++ DLL that was used in a pure C# DLL even in the following scenario. 1. Launch the application. This applicatio has its own default applicaiton domain. 2. Create a new Application Domain. 3. Load the Pure C# DLL in the new applicaiton domain. This C# DLL uses managed C++ DLL. 4. Create a Proxy object using CreateInstanceAndUnwrap for the wrapper object which is a wrapper for the class used from the pure C# DLL. This wrapper object is exported from a seperate DLL. DLL Configuration:- Wrapper for C# DLL, C# DLL, Managed C++ DLL. The wrapper C# is used so that the main C# will not be loaded into the default application domain when creating a Proxy object using the menthod CreateInstanceAndUnwrap. The application domain talks with only the wrapper DLL. If we do not have wrapper class, then the main C# DLL will also be loaded into the default application. The sideeffect of this is that, even when the new application is unloaded, we will not be able to delete the main C# DLL. Wrapper is just a call frowader to the C# DLL class. 5. Give the class name exported from C# DLL to the wrapper object and ask it to create an instance of the class. The wrapper class creates the the class and initializes its membet to it, so that it can forward call requests. 6. From the default application domain, call a method on the wrapper object. This call on the wrapper object calls the method on the C# class. This C# class uses a function exported from a managed C++ DLL. 7. After executing the methods, unload the new application domain. 8. Now try to delete C# DLL, Mananged C++ DLL. I was able to delete C# DLL, but not MC++ DLL. After further investigation I found that the Visual Studio "Output" window has the following two lines:- 'Application.exe': Loaded 'C:\DLL1\Debug\MCPP.dll', Symbols loaded.----> LOADING FIRST TIME 'Application.exe' (Managed): Loaded 'C:\DLL1\Debug\MCPP.dll', Symbols loaded. ----> LOADING SECOND TIME When the method on C# class is getting executed, the output log file contains the above two lines. The .NET framework is loading it twice. Once as Native C++ DLL, second time as Managed DLL. Does any one know how to delete the MC++ DLL.

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      led mike

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups