Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

load resources from dll

Help
2004-10-05
2013-04-15
  • Hi!
    I write dll with a function which create win32guid-window. Then I call this function from exe and get a problem here:

    file "defs.hpp" line 142
    inline HINSTANCE default_instance() { return (HINSTANCE)::GetModuleHandle(0); }

    The default_instance() returns 0. And that's right: required resources are in dll, not in exe!
    Is it a bug?

    I work around this problem in a such way (VC 7.1):

    extern "C" void * _ReturnAddress();
    #pragma intrinsic(_ReturnAddress)

    static HINSTANCE GetCurrentInstance()
    {
        MEMORY_BASIC_INFORMATION mem;
        if (VirtualQuery(_ReturnAddress(), &mem, sizeof(mem)))
        {
            assert(mem.Type == MEM_IMAGE);
            assert(mem.AllocationBase != NULL);
            return (HINSTANCE)mem.AllocationBase;
        }
        return NULL;
    }

    but I am afraid it's not portable code.

    P.s. Thanks a lot for a beautiful library!
    Best regards,
    dv

     
    • P.s. Sorry, I forgot most important line in the above code :)

      inline HINSTANCE default_instance()
      {
          return GetCurrentInstance();
      }

       
    • John Torjo
      John Torjo
      2004-10-05

      Hi,

      Could you please send me the smallest example which exibits this behavior? Thanks.

      Send it to john at torjo dot com

      Best,
      John