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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:56:48+00:00 2026-05-29T09:56:48+00:00

i’ve been experimenting with wrapping some basic win32 functionality in classes while i work

  • 0

i’ve been experimenting with wrapping some basic win32 functionality in classes while i work with d3d, and am stumped for why the CreateWindowEx function fails saying a class doesn’t exist AFTER i create a valid class with RegisterClassEx, no errors to speak of :\ . I get the feeling i’m missing some silly little thing, but i can’t find it. Here is some of the code:

I have a class that extends WNDCLASSEX like this, so that it has a normal std::string for a class name and a simplified constructor:

#ifndef WINDOWCLASS_H
#define WINDOWCLASS_H

#include <Windows.h>
#include <string>
#include "WindowAbstract.h"
using namespace std;

class WindowClass : public WNDCLASSEX
{
public:
    WindowClass(string className, WindowAbstract * window);
    ~WindowClass();

    bool Register();
    string ClassName() {return m_className;}

    friend class WindowAbstract;

private:
    string m_className;
};

#endif

And here is the constructor for the class:

WindowClass::WindowClass(string className, WindowAbstract * window)
{

    cbSize        = sizeof(WNDCLASSEX);
    style         = 0;
    lpfnWndProc   = window->WndProc;
    cbClsExtra    = 0;
    cbWndExtra    = 0;
    hInstance     = hInstance;
    hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    hCursor       = LoadCursor(NULL, IDC_ARROW);
    hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    lpszMenuName  = NULL;
    lpszClassName = className.c_str();
    hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    m_className = className;
}

here is the register function to be called after it’s constructed:

bool WindowClass::Register()
{
    if(RegisterClassEx(this) == 0)
        return false;

    return true;
}

The WindowAbstract class contains the window procedure and is created first, to pass the pointer to it’s function to the WindowClass object.

#ifndef WINDOWABSTRACT_H
#define WINDOWABSTRACT_H

#include <Windows.h>
#include <string>
using namespace std;

class WindowAbstract
{

public:
    WindowAbstract();
    ~WindowAbstract();

    bool Create(string windowTitle, string className, DWORD styles, DWORD extendedStyles, int top, int left, int bot, int right, HWND parent, HMENU id);
    void Show();

    friend class WindowClass;

private:
    static LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
    HWND m_hwnd;

};

#endif

And here is the create function:

bool WindowAbstract::Create(string windowTitle, string className, DWORD styles, DWORD extendedStyles, int top, int left, int bot, int right, HWND parent, HMENU id)
{
    m_hwnd = CreateWindowEx(extendedStyles, className.c_str() , windowTitle.c_str(), styles, top, left, bot, right, parent, id, GetModuleHandle(NULL), NULL);
    if(!m_hwnd)
        return false;

    return true;
}

so after seeing all that, here is the actual winmain where i test it out:

#include "WindowAbstract.h"
#include "WindowClass.h"


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
    DWORD error;
    bool result;
    char buffer[100];

    WindowAbstract * window = new WindowAbstract();
    WindowClass * myClass = new WindowClass("myClass", window);

    result = myClass->Register();
    if(!result)
    {
        error = GetLastError();
        sprintf_s(buffer, "error: %i", error);
        MessageBox(NULL, buffer, "Registration Failed!", MB_OK);
    }

    result = window->Create("my Window", myClass->ClassName(), WS_OVERLAPPEDWINDOW, WS_EX_CLIENTEDGE, 20, 20, 200, 200, NULL, NULL);
    if(!result)
    {
        error = GetLastError();
        sprintf_s(buffer, "error: %i", error);
        MessageBox(NULL, buffer, "Window Creation Failed!", MB_OK);

    }

    window->Show();

    MSG msg;
    while(GetMessage(&msg, NULL, 0, 0) > 0)
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    if(window)
    {
        delete window;
        window = 0;
    }

    if(myClass)
    {
        delete myClass;
        myClass = 0;
    }

    return msg.wParam;
}

so, in conclusion, this is so confusing because the Register function of the WindowClass object returns fine, but the create function fails in the WindowAbstract object because there is no valid class,(error 1407), with that name? Whuh?

  • 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-29T09:56:48+00:00Added an answer on May 29, 2026 at 9:56 am

    I think the problem is lpszClassName = className.c_str() in the WindowClass constructor. In general, you shouldn’t rely on the value returned from c_str() being available for any length of time.

    In this case, you’re (effectively) taking the address of a local variable which may have ceased to exist by the time you call RegisterClassEx. So RegisterClassEx is succeeding, but who knows what name it is seeing?

    lpszClassName = m_className.c_str() would probably work (if you assigned m_className first) but it’s still sketchy. Better to call c_str() immediately before you call RegisterClassEx.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I have some data like this: 1 2 3 4 5 9 2 6
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.