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 6160147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:15:05+00:00 2026-05-23T21:15:05+00:00

I am confused why the second static pointer pthis won’t initialize? What I did

  • 0

I am confused why the second static pointer pthis won’t initialize? What I did is I subclass a window procedure through a static function. The first static pointer lpProcess was initialize in the main procedure. However, the second one won’t even call its own constructor (I used debugger to determine this problem). Somehow, it simply skips the construction. At first, I doubt I was misunderstanding some points on static variable. However, seeing that the first one works, why not the second? Perhaps, I guess that this has something to do with deep recursion or calling static function?

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static QProcessor* lpProcess = new QProcessor(hwnd); //Initialized without any error

    switch(msg)
    {

    case WM_CREATE:
        {
            lpProcess->SetFixed(322,200); //Set window size through the container
            lpProcess->Update(); //Update members
            if(!lpProcess->CreateChild()) //Create all controls
            {
                Error(); //print error
                ::DestroyWindow(hwnd); //terminate the window
            }
            QMonitor::Attach(hwnd); //Attach Monitor Window to current window

        }
....




void QMonitor::Attach(HWND hwnd)
{
    QMonitor::classdata = (LPVOID)::SetWindowLong(hwnd,GWL_WNDPROC,(LONG)QMainProc); //subclass procedure
}




LRESULT CALLBACK QMainProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    static QMonitor* pthis = new QMonitor(hwnd); //Won't initialize??

    switch(msg)
        {
        case WM_MOVE:
            {
                pthis->OnMove();
            }
            break;
        case WM_SIZE:
            {
                pthis->OnSize();
            }
            break;
        case WM_COMMAND:
            break;
        case WM_DESTROY:
            delete pthis;
            break;
        }
        return ::CallWindowProc(pthis->GetAttachWndProc(),hwnd,msg,wParam,lParam);
}
  • 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-23T21:15:06+00:00Added an answer on May 23, 2026 at 9:15 pm

    Most C++ compilers emit a small code `preamble’ for procedures that have static data like this. This preamble checks a (hidden) boolean flag, and initialises/constructs the statics if it’s clear. The boolean flag is then set to indicate that the statics shouldn’t be initialized again.

    Not all compilers manage these flags in a thread-safe way, so multiple threads trying to initialize the same statics can cause chaos…

    If your constructor isn’t being called, maybe this boolean is being corrupted by something else in your code?

    Sorry I can’t solve the problem directly, but hopefully this will help you understand some of assembly code you see being executed in the debugger…

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

Sidebar

Related Questions

This code really made me confused. The first and second time I ran it,
I confused when i want to take single pointer and when should i take
I am reading through Jon Skeet's C# in Depth, first edition (which is a
I am a bit confused about this piece of code. public static void Foo(A
I am confused at the following: <>; print; vs. while(<>){print;} The first one does
First off, I'm not asking for anyone to do my homework. I'm simply confused
Sooo I started taking my second computer science class ever! For my first class
I'm reading Effective Java Second Edition by Joshua Bloch and im confused by below
I apologize for a second question on the same topic, but I'm confused. Is
I'm a bit confused about the following code. If I comment out the second

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.