Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 830459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:02:50+00:00 2026-05-15T04:02:50+00:00

I am now working on a some sort of a game engine and I

  • 0

I am now working on a some sort of a game engine and I had an idea to put everything engine-related into a static library and then link it to my actual problem.

Right now I achieved it and actually link that library and every functions seem to work fine, except those, which are windows-related.

I have a chunk of code in my library that looks like this:

   hWnd = CreateWindow(className, "Name", WS_OVERLAPPED | WS_CAPTION | WS_EX_TOPMOST,
              0, 0, 
              800, 600,
              NULL, NULL, GetModuleHandle(NULL), this);

   if (hWnd) {
      ShowWindow(hWnd, SW_NORMAL);
      UpdateWindow(hWnd);
   } else {
      MessageBox(NULL, "Internal program error", "Error", MB_OK | MB_ICONERROR);
      return;
   }

When this code was not in the library, but in the actual project, it worked fine, created the window and everything was ok. Right now (when I’m linking to my library that contains this code) CreateWindow(...) call returns NULL and GetLastError() returns “Operation succesfully completed” (wtf?).

Could anybody help me with this? Is it possible to create a window and display it using a static library call and why could my code fail?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:02:51+00:00Added an answer on May 15, 2026 at 4:02 am

    Ah, maybe you’ve run into this problem described in an MSDN blog:

    If you’re writing a static library, you may have need to access the HINSTANCE of the module that you have been linked into. You could require that the module that links you in pass the HINSTANCE to a special initialization function, but odds are that people will forget to do this.

    If you are using a Microsoft linker, you can take advantage of a pseudovariable which the linker provides.

    EXTERN_C IMAGE_DOS_HEADER __ImageBase;
    #define HINST_THISCOMPONENT ((HINSTANCE)&__ImageBase)
    

    The pseudovariable __ImageBase represents the DOS header of the module, which happens to be what a Win32 module begins with. In other words, it’s the base address of the module. And the module base address is the same as its HINSTANCE.

    So there’s your HINSTANCE.

    So, instead of passing GetModuleHandle(NULL) to CreateWindow, try ((HINSTANCE)&__ImageBase) (make sure it is declared as shown in the blog first).

    Edit:

    From the comments in that blog entry, one mentions the use of GetModuleHandleEx(), perhaps this is a more Compiler/Linker-agnostic approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on a foundational c++ library for some time now, and there
Imagine you have a library for working with some sort of XML file or
I am working on a 3d game engine which requires some maths, but i
Every now and then some JavaScript function I'm working on would just quit quietly,
I'm working through some android tutorials right now in preparation for a two week
I have created some tests in my WPF application. Right now I am working
A while ago I did some work in Qt for C++; now I'm working
We've been working with a Subversion repository for some time now for a research
I have been working on this for some time now and just cant quite
I have been working in C++ for some time now, but I am unsure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.