title: Crash when calling virtual function
body: <p>Ok this is a really weird problem. I wanna start off by saying that I'm not a beginner in c++ and I'm certainly not advanced. I'm somewhere in the middle. What I'm trying to do is make a C++ OOP wrapper library (dll) of the Win32 API. Here are the classes of my library. I compiled it with Mingw using the command:</p>
  
  <pre><code>g++ -shared -o bin\win32oop.dll src\Application.cpp src\Form\Form.cpp -Wall
  </code></pre>
  
  <p>src\Application.h:</p>
  
  <pre><code>#ifndef WOOP_APPLICATION_H_
  #define WOOP_APPLICATION_H_
  
  namespace Woop
  {
   class Application
   {
   public:
    bool Init(void);
    virtual bool OnInit(void);
   };
  }
  
  #endif // WOOP_APPLICATION_H_
  </code></pre>
  
  <p>src\Application.cpp</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include "Application.h"
  #include "Form\Form.h"
  
  LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  
  namespace Woop
  {
   bool Application::Init(void)
   {
    WNDCLASSEX wc;
  
    wc.cbSize        = sizeof(WNDCLASSEX);
    wc.style         = 0;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = GetModuleHandle(NULL);
    wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = "woop";
    wc.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
  
    if(RegisterClassEx(&amp;wc) == 0)
    {
     MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
     return false;
    }
  
    this-&gt;OnInit();
  
    return true;
   }
  
   bool Application::OnInit(void)
   {
    return true;
   }
  }
  
  LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  {
      Woop::Form *wnd = 0;
  
      if (uMsg == WM_NCCREATE) 
   {   
          SetWindowLong (hwnd, GWL_USERDATA, long((LPCREATESTRUCT(lParam))-&gt;lpCreateParams));
      }
  
   wnd = (Woop::Form *)(GetWindowLong (hwnd, GWL_USERDATA));
  
      if (wnd) return wnd-&gt;WndProc(hwnd, uMsg, wParam, lParam);
  
      return ::DefWindowProc (hwnd, uMsg, wParam, lParam);
  }
  </code></pre>
  
  <p>src\Form\Form.h</p>
  
  <pre><code>#ifndef WOOP_FORM_FORM_H_
  #define WOOP_FORM_FORM_H_
  
  namespace Woop
  {
   class Form
   {
   public:
    bool Show(void);
    virtual LRESULT WndProc(HWND, UINT, WPARAM, LPARAM);
   protected:
    HWND _handle;
   };
  }
  
  #endif // WOOP_FORM_FORM_H_
  </code></pre>
  
  <p>src\Form\Form.cpp</p>
  
  <pre><code>#include &lt;windows.h&gt;
  #include "Form.h"
  
  namespace Woop
  {
   bool Form::Show(void)
   {
    _handle = CreateWindowEx(WS_EX_CLIENTEDGE, "woop", "", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, GetModuleHandle(NULL), this);
  
    if(_handle == NULL)
    {
     MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
     return false;
    }
  
    ShowWindow(_handle, SW_SHOWNORMAL);
  
    return true;
   }
  
   LRESULT Form::WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
   {
    switch(uMsg)
    {
     case WM_DESTROY:
      PostQuitMessage(0);
     break;            
    }
    return DefWindowProc(hwnd, uMsg, wParam, lParam);
   }
  }
  </code></pre>
  
  <p>Here is a the program that I'm testing the library with:</p>
  
  <pre><code>class SampleApp : public Woop::Application
  {
   bool OnInit(void)
          {
           Form form;
           form.Show();
  
           return true;
          }
  };
  
  INT APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
  {
   SampleApp application;
   if(application.Init() == false) return 0;
  
   MSG Msg;
   while(GetMessage(&amp;Msg, NULL, 0, 0) &gt; 0)
      {
          TranslateMessage(&amp;Msg);
          DispatchMessage(&amp;Msg);
      }
  
   return 0;
  }
  </code></pre>
  
  <p>Alright, now the problem. Do you see that virtual Window Procedure in the Form class? If I remove the virtual from the declaration, the program compiles and runs fine. But when I add it back, it crashes. The infamous "Don't Send" dialog comes up. I'm not sure when it crashes, i'll try to figure that out using MessageBox() (lol, it's what I get for not learning how to debug with gdb). I'm trying to make it so that I can make a class such as LoginForm and derive from Form and override the Window Procedure. I hope I explained the problem well enough :D. This might be a compiler bug or my stupidity :P. Anyways, thanks in advance.</p>