RegisterClassEx fails on Win95

This is a discussion on RegisterClassEx fails on Win95 within the Windows Programming forums, part of the Platform Specific Boards category; The program works fine on my Win2k machine, but on Win95 the following happens: I'm creating an app, creating the ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    329

    RegisterClassEx fails on Win95

    The program works fine on my Win2k machine, but on Win95 the following happens:
    I'm creating an app, creating the main window works fine, but when i try to create the child windows, the registerclassex function fails. GetLastError() returns 0.
    Any clues??
    Code for child window:
    Code:
    int questWnd(HINSTANCE hThisInstance, HWND hWndOwner){
    	WNDCLASSEX wincl;		// Data structure for the windowclass 
    	MSG messages;	
    
    	if(!GetClassInfoEx(hThisInstance, "ddqWnd", &wincl)){	// Sjekk om klassen er registrert fra før
    		// The Window structure 
    		wincl.hInstance = hThisInstance;
    		wincl.lpszClassName = "ddqWnd";
    		wincl.lpfnWndProc = formProc;	// This function is called by windows 
    		wincl.style = CS_DBLCLKS;			// Catch double-clicks 
    		wincl.cbSize = sizeof(WNDCLASSEX);
    
    		// Use default icon and mouse-pointer 
    		wincl.hIcon = LoadIcon (NULL, IDI_ASTERISK);
    		wincl.hIconSm = LoadIcon (NULL, IDI_ASTERISK);
    		wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    		wincl.lpszMenuName = NULL;                 // No menu 
    		wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    		wincl.cbWndExtra = 0;                      /* structure or the window instance */
    		/* Use Windows's default color as the background of the window */
    		wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    		if(!RegisterClassEx(&wincl)){
    			achBuf=NEW char[100]; sprintf(achBuf, "GetLastError=%lu", GetLastError());b(achBuf);
    			return(0);
    		}
    	}

  2. #2
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753
    From MSDN:

    Windows 95/98/Me: All window classes registered by a dynamic-link library (DLL) are unregistered when the .dll is unloaded.

    Windows NT/2000/XP: No window classes registered by a DLL are unregistered when the DLL is unloaded. A DLL must explicitly unregister its classes when it is unloaded.

    Windows 95/98/Me: RegisterClassEx fails if the cbWndExtra or cbClsExtra member of the WNDCLASSEX structure contains more than 40 bytes.

    Windows 95/98/Me: RegisterClassExW is supported by the Microsoft® Layer for Unicode (MSLU). To use this version, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    I am familiar with that, and as you can see from the code, i set the cbClsExtra & wincl.cbWndExtra to 0.
    The program is an .Exe.

    The strange thing is that it worked earlier. I'm subclassing some edit boxes and buttons to capture keystrokes, and using functions from sql.h. I'm wondering if there could be any of these functions that mess up the program...?

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    I figured it out:
    GetClassInfoEx(hThisInstance, "className", &wincl)
    always returned 0, hence the class was registered each time i opened the window..
    Can anyone explain this to me?

  5. #5
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    If you Register a Class, it shouldn't be unloaded until the process is killed. I suggest you post your code up here. I recently overcame some problems with class creation, so I could quite possible help you.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    329
    The first posting contains the code. It uses GetClassInfoEx(hThisInstance, "ddqWnd", &wincl) to check if the class is registered... This function aleays returns 0 in my code...

    Code:
    WNDCLASSEX wincl;
    	static BOOL classRegistered(FALSE);
    
    	if(!GetClassInfoEx(hThisInstance, "ddWndCls", &wincl)){
    		classRegistered=TRUE;
    		wincl.cbSize = sizeof(WNDCLASSEX);
    		wincl.hInstance = hThisInstance;
    		wincl.lpszClassName = "ddWndCls";
    		wincl.lpfnWndProc = windowProc;
    		wincl.style = CS_DBLCLKS;
    		wincl.hIcon = LoadIcon (NULL, IDI_ASTERISK);
    		wincl.hIconSm = LoadIcon (NULL, IDI_ASTERISK);
    		wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    		wincl.lpszMenuName = NULL;
    		wincl.cbClsExtra = 0;
    		wincl.cbWndExtra = 0;
    		wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;
    		if(!RegisterClassEx(&wincl))
    			return 0;
    	}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 21
    Last Post: 06-24-2009, 09:49 AM
  2. This works fine with IP 127.0.0.1 but fails with my REAL IP.
    By azjherben in forum Networking/Device Communication
    Replies: 15
    Last Post: 05-19-2009, 10:28 PM
  3. Mac - File locking with fcntl() fails on shared volumes!?
    By idelovski in forum Linux Programming
    Replies: 3
    Last Post: 11-10-2008, 06:37 PM
  4. Replies: 0
    Last Post: 05-23-2005, 11:39 AM
  5. Beginner Question: CreateWindowEx Fails.
    By dicky in forum Windows Programming
    Replies: 4
    Last Post: 05-30-2004, 08:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21