Skip to content

Windows: Avoid GetModuleHandle(NULL) #2300

@AronParker

Description

@AronParker

The library makes extensive use of GetModuleHandle(NULL) to obtain the instance handle. This is discouraged, as it does not work for targets that are not executables, such as DLLs.

A possible solution for this would be to use the __ImageBase linker pseudovariable, which is intended for static libraries as described here.

This trick has also been used in the Windows Implementation Library for C++ which has extensive usage:

https://github.com/microsoft/wil/blob/master/include/wil/win32_helpers.h#L513-L514

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions