CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 1999
    Posts
    3

    HMODULE from HINSTANCE

    I'm loading custom resources in a dll, and I'm trying to figure out the best way to acquire an HMODULE pointer. I can get the HMODULE by doing AfxLoadLibrary("dllname");, but I'd rather not hardcode the dll name into my code. I've noticed that the win32 helper functions that are provided (like ::LoadAccelerators) take the HINSTANCE pointer, but for a custom resource I think I need to use FindResource, which requires an HMODULE. Can anybody point me to a way to get the HMODULE pointer that doesn't require the dll name in a string?


  2. #2
    Join Date
    Apr 1999
    Posts
    24

    Re: HMODULE from HINSTANCE

    // You are right. You can't get HMODULE from HINSTANCE without hardcode of the dll name. See this below

    // I think as you that this is the only way
    HINSTANCE hInstance = LoadLibrary("dllname"); // Mapping module to memory
    HMODULE hModule = GetModuleHandle("dllname"); // Getting module handle

    // If you ever understand any more easy way of this write me please to [email protected].
    // Thanks.



  3. #3
    Join Date
    Apr 1999
    Posts
    3

    Re: HMODULE from HINSTANCE

    Well, I must have done something stupid this morning, because I can apparently use the HINSTANCE in the HMODULE parameter of FindResource(). I don't know if they are equivalent everywhere or not, but you might try using one for the other. I get my HINSTANCE parameter from the dll initialization function (I save it in a static variable and then extern it for future reference.)


  4. #4
    Join Date
    May 1999
    Posts
    123

    Re: HMODULE from HINSTANCE

    An HMODULE and an HINSTANCE are the same thing and you can use them interchangeably.

    For example, if you look at the startup code in the standard library, the hInstance that get's passed to WinMain is obtained with GetModuleHandle(NULL);



    The universe is a figment of its own imagination.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured