An example of a dynamic module that doesn't have an HINSTANCE RRS feed

  • Question

  • I want to use Marshal.GetHINSTANCE() to get a handle for the currently running module, I'm confused my the remark from MSDN:


    "When dynamic or in-memory, modules do not have an HINSTANCE."

    Can you provide an example of when this happens? I assumed this would be if the assembly was brought in via Assembly.Load(), however this doesn't seem to be the case, I still get a handle to it. When would I not get a handle?

    My code is:

    IntPtr hMod = Marshal.GetHINSTANCE(typeof(MyClass).Module);


    Saturday, October 30, 2010 12:00 AM


All replies

  • e.g. when you do not ship xml serializer dlls with your dll, the dlls will be generated on demand and loaded dynamically. If you have an asp.net web project each page generates a dynamic assembly.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Saturday, October 30, 2010 12:33 AM
  • Hi,

    Thanks for your post. Assembly.Load() loads the assemblies that physically pre-exist as an assembly files. They are not dynamic assembies. Please take a look at the following references, they address how to create dynamic assembies and what scenario they could fit in.

    1. Dynamic Assemblies: some scenarios where dynamic assemblies fit in.

    2. Creating Dynamic Assembly

    3. Dynamic assembly loading (useful when developing plug-in driven frameworks) : An interesting scenario.

    Please mark the right answer at the right time.
    • Marked as answer by FearTheBeard Monday, November 1, 2010 5:59 PM
    Monday, November 1, 2010 7:56 AM
  • Thanks for the example.
    Monday, November 1, 2010 8:22 PM