Thread: failing RegisterClass

  1. #1
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396

    failing RegisterClass

    This is my first go at unicode and I thought I may as well do a little windows skeleton so I wouldn't have to keep recreating it. Well here is my attempt but It always gives me the message box "This program requires Windows NT"
    What did I do incorrectly? I have been looking this over all evening and still can't find anything wrong with this. Hopefully it is something painfully obvious!
    I'm using MSVC 2003 on XP Pro.

    Code:
    #define UNICODE
    #define _UNICODE
    
    #include <windows.h>
    
    HINSTANCE hInstance;
    HDC hdc;
    PAINTSTRUCT ps;
    
    LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpszCmdLine, int iCmdShow)
    {
        static TCHAR szAppName[] = TEXT ("Win32Skeleton");
        HWND        hwnd;
        MSG            msg;
        WNDCLASS    wndclass;
    
        wndclass.style            = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc    = WndProc;
        wndclass.cbClsExtra        = 0;
        wndclass.cbClsExtra        = 0;
        wndclass.hInstance        = hInstance;
        wndclass.hIcon            = LoadIcon (NULL, IDI_APPLICATION);
        wndclass.hCursor        = LoadCursor (NULL, IDC_CROSS);
        wndclass.hbrBackground    = (HBRUSH) GetStockObject (WHITE_BRUSH);
        wndclass.lpszMenuName    = NULL;
        wndclass.lpszClassName    = szAppName;
    
        if(!RegisterClass (&wndclass))
        {
            MessageBox(NULL, TEXT ("This program requires Windows NT!")
                , szAppName, MB_ICONERROR);
            return 0;
        }
    
        hwnd = CreateWindow(szAppName, TEXT ("SkeletonDoesn'tWork")
            , WS_OVERLAPPEDWINDOW
            , CW_USEDEFAULT, CW_USEDEFAULT
            , CW_USEDEFAULT, CW_USEDEFAULT
            , NULL, NULL, hInstance, NULL);
    
        ShowWindow(hwnd, iCmdShow);
        UpdateWindow(hwnd);
    
        while (GetMessage (&msg, NULL, 0, 0))
        {
            TranslateMessage (&msg);
            DispatchMessage (&msg);
        }
        return (int) msg.wParam;
    }
    
    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch(message)
        {
        case WM_CREATE:
            return 0;
        }
    
        return DefWindowProc (hwnd, message, wParam, lParam);
    }
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You should be able to set/unset unicode in your project properties. I think it's under the general category just above debugging.

    Check your project properties as well to fix the other issue. I'm not sure why it's saying that right off hand.

  3. #3
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Call GetLastError() to get more error information. This might lead you to the problem.

  4. #4
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    I set it up for UNICODE in my project options.

    GetLastError:
    RegisterClass failed with error 87 The parameter is incorrect

    Thanks for your help but I still don't get it! How can the parameter be incorrect?
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  5. #5
    Registered User Bajanine's Avatar
    Join Date
    Dec 2001
    Location
    The most peaks over 10,000 feet!
    Posts
    396
    I fixed it by using:
    Code:
    ZeroMemory(&wndclass,sizeof(WNDCLASS));
    Thanks for you help!
    Favorite Quote:

    >For that reason someone invented C++.
    BLASPHEMY! Begone from my C board, you foul lover of objects, before the gods of C cast you into the void as punishment for your weakness! There is no penance for saying such things in my presence. You are henceforth excommunicated. Never return to this house, filthy heretic!



  6. #6
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's always a good idea to zero out structs so you don't send junk data to APIs and functions.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    I always prefer this method:
    Code:
    WNDCLASS    wndclass = {0}; //No silly crt memset function
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 09-23-2008, 03:32 AM
  2. pointer comparison failing
    By Bleech in forum C Programming
    Replies: 4
    Last Post: 08-11-2007, 06:33 PM
  3. CreateDevice failing
    By MadCow257 in forum Game Programming
    Replies: 6
    Last Post: 03-14-2006, 09:03 PM
  4. initializes all components of failing to false
    By romeoz in forum C++ Programming
    Replies: 21
    Last Post: 08-01-2003, 09:30 PM