Module handle in C++/CLI library

How can I found current module handle (HMODULE) in C++/CLI Class Library. I need it to load data from Dll resources.
My guess is that it is possible to do using Marshal::GetHINSTANCE(Module^) function, so I need to find Module of current Dll.


Answer this question

Module handle in C++/CLI library

  • Arild Fines

    Hi,

    I think that code should looke like this:

    IntPtr ptr=Marshal::GetHINSTANCE(Assembly::GetAssembly(this->GetType())->GetModule("MyDll.dll"));

    There are some other methods in the Assembly class that allow you to get the same result without using name, like for instance:

    Assembly::GetAssembly(this->GetType())->GetModules()[0]

    Max



  • DennisV

    Thanks, using Type class is much better, doesn't require module name:

    Module^ module = this->GetType()->Module;


  • Module handle in C++/CLI library