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

  • SEARCH
  • Home
  • 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 6544985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:31:53+00:00 2026-05-25T11:31:53+00:00

I’m developing a program that displays graphical windows using the windows API. Below is

  • 0

I’m developing a program that displays graphical windows using the windows API. Below is function I provided as the WndProc when registering the window class – it is a static function inside the class WindowsWindow.

#define BTK_DLL_FUNC __dllspec(dllexport)

class AbstractBackend
{
protected:
  bool FatalWarnings;

public:
  AbstractBackend (bool FatalWarnings=false);
  ~AbstractBackend ();

  virtual void StartMainLoop () = 0;
  virtual void QuitMainLoop () = 0;
};

class WindowsBackend : public Base::AbstractBackend
{
public:
  static HINSTANCE hinstance;
  static WindowsBackend* instance;

public:
  BTK_DLL_FUNC WindowsBackend ();
  BTK_DLL_FUNC ~WindowsBackend ();

  BTK_DLL_FUNC void StartMainLoop ();
  BTK_DLL_FUNC void QuitMainLoop ();
};


void WindowsBackend::StartMainLoop ()
{
  MSG Msg;
  while (GetMessage (&Msg, NULL, 0, 0) > 0)
  {
    TranslateMessage (&Msg);
    DispatchMessage (&Msg);
  }
}

void WindowsBackend::QuitMainLoop ()
{
  PostQuitMessage (0); /* Send a WM_QUIT message, to stop the main loop */
}

LRESULT CALLBACK WindowsWindow::WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
  switch (msg)
  {
  case WM_CREATE:
    break;

  case WM_CLOSE:
    DestroyWindow (hwnd);
    break;

  case WM_DESTROY: /* The window was destroyed */
    {
      WindowsBackend::instance->QuitMainLoop (); /* This doesn't work! */
      break;
    }

  default:
    return DefWindowProc(hwnd, msg, wParam, lParam);
  }
  return 0;
}

Now, here is the part I don’t understand – The QuitMainLoop doesn’t begin and it doesn’t return (I tried the debugger and it showed that the Quit function isn’t being called, and also that any line after that call isn’t being executed). So practically, my program gets stuck after that call.

But, replacing the call to the custom quit function with a direct call to PostQuitMessage works.

Any explanations and/or way to get around this (and be able to call a virtual function) would be highly appriciated.

Edit: Added the exact code

  • 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-25T11:31:54+00:00Added an answer on May 25, 2026 at 11:31 am

    Since you have not posted full code that we can run to reproduce the problem we have to guess.

    The only way that I can see for the call to QuitMainLoop() to fail is if WindowsBackend::instance is somehow corrupted. Have you destroyed it by mistake before calling QuitMainLoop()? Has there been a memory corruption perhaps?

    I would look at this under the disassembly view in the debugger. That should tell you what has gone wrong and then you need to follow the clues to find out why.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.