473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with Win32 RegisterClass() runtime call

Hi,

I have an unusual situation whereby we create a Window during initialisation. We have used this code for many years and have found one unusual case with a customer when the RegiterClass fails and then the following CreateWindow also fails, making our process timeout and fail.

My real problem is trying to understand what is causing the RegisterClass to fail and I believe that this function does not set the last error so GetLastError() either reports OK or the error to a previous call (not ReisterClass call).

My feeling is that I am running out of system resources, but I cannot prove this unless I get sensible error returned from RegisterClass(). Below is my code and also tracing output when the process is running.

Does anyone have any suggestions how I may find out what is the underlying cause here, or why RegisterClass fails?
Expand|Select|Wrap|Line Numbers
  1. HWND CreateWindow( void )
  2. {
  3.    WNDCLASSEX        tWc;            /* Windows Class structure */
  4.    LPTSTR            lpMsgBuf;       /* Windows O/S Error Buffer */
  5.    PCXAChar          sClassName = "WndProc";
  6.    DWORD             dError;
  7.    HMODULE           tModule = GetModuleHandle(NULL);
  8.  
  9.    /* Only need to create a single Event window no matter how many sockets */
  10.    if ( tcp_g.hWSA_IO_comp_window != NULL )
  11.    {
  12.       return tcp_g.hWSA_IO_comp_window;
  13.    }
  14.  
  15.    if (!GetClassInfoEx(tModule, sClassName, &tWc))
  16.    {
  17.       dError = GetLastError();
  18.  
  19.       /* Get error Details */
  20.       FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  21.          NULL,
  22.          dError,
  23.          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
  24.          (LPTSTR)&lpMsgBuf,
  25.          0,
  26.          NULL );
  27.  
  28.       /* display socket stats */
  29.       TRACE("CcreateWindow - GetClassInfoEx Error %s \n", lpMsgBuf);
  30.  
  31.       /* Free the buffer */
  32.       LocalFree( lpMsgBuf );
  33.  
  34.       /* Initialize Window Class structure to describe Window. */
  35.       tWc.cbSize        = sizeof(WNDCLASSEX);
  36.       tWc.style         = 0;         /* Class style - Local */
  37.       tWc.cbClsExtra    = 0;         /* Class extra data.   */
  38.       tWc.cbWndExtra    = 0;         /* Window extra data.  */
  39.       tWc.hCursor       = NULL;
  40.       tWc.hbrBackground = NULL;
  41.       tWc.lpszMenuName  = NULL;
  42.       tWc.hIcon         = NULL;
  43.       tWc.hIconSm       = NULL;
  44.       tWc.hInstance     = tModule;
  45.       tWc.lpszClassName = sClassName;          /* Window Class Name    */
  46.       tWc.lpfnWndProc   = (WNDPROC)WndProc_WIN;
  47.  
  48.       /* windows of this class. */
  49.       /* Register the window class and get Class Atom Id */
  50.       if(!RegisterClassEx(&tWc))
  51.       {
  52.          dError = GetLastError();
  53.  
  54.          /* Get error Details */
  55.          FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  56.             NULL,
  57.             dError,
  58.             MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
  59.             (LPTSTR)&lpMsgBuf,
  60.             0,
  61.             NULL );
  62.  
  63.          /* display socket stats */
  64.          TRACE( "CreateWindow - RegisterClassEx Error %s \n", lpMsgBuf);
  65.  
  66.          /* Free the buffer */
  67.          LocalFree( lpMsgBuf );
  68.       }
  69.    }
  70.  
  71.    /* Create Winsock Event Window */
  72.    tcp_g.hWSA_IO_comp_window = CreateWindowEx( 
  73.       0,                                         /* Extended window style */
  74.       sClassName,                                /* Class Name */
  75.       tSymbolicProcessId,                        /* Window title bar ( Use Symbolic ID)   */
  76.       WS_OVERLAPPEDWINDOW,                       /* Window style.                         */
  77.       CW_USEDEFAULT,                             /* Default horizontal position.          */
  78.       CW_USEDEFAULT,                             /* Default vertical position.            */
  79.       CW_USEDEFAULT,                             /* Default width.                        */
  80.       CW_USEDEFAULT,                             /* Default height.                       */
  81.       NULL,                                      /* Overlapped windows have no parent.    */
  82.       NULL,                                      /* Use the window class menu.            */
  83.       tModule,                                   /* Application instance owns this window */
  84.       NULL                                       /* Pointer to window creation Data       */ );
  85.  
  86.    if ( tcp_g.hWSA_IO_comp_window == NULL )
  87.    {
  88.       dError = GetLastError();
  89.  
  90.       /* Get error Details */
  91.       FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  92.          NULL,
  93.          dError,
  94.          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
  95.          (LPTSTR)&lpMsgBuf,
  96.          0,
  97.          NULL );
  98.  
  99.       /* display socket stats */
  100.       TRACE( "CreateWindow - CreateWindowEx Error %s \n", lpMsgBuf);
  101.  
  102.       /* Free the buffer */
  103.       LocalFree( lpMsgBuf );
  104.    }
  105.  
  106.    /* Return Window Handle */
  107.    return tcp_g.hWSA_IO_comp_window;
  108. }
  109.  
and output from various runs.....


sample 1
--------
CreateWindow - RegisterClass Error The operation completed successfully.
CreateWindow - CreateWindow Error Cannot find window class.

sample 2
--------
CreateWindow - CreateWindowEx Error Not enough storage is available to complete this operation.

sample 3
--------
CreateWindow - RegisterClassEx Error Class already exists.
CreateWindow - CreateWindowEx Error Not enough storage is available to complete this operation.

So as you can see, the error messages and results don't make sense....

Thanks.
Jul 24 '07 #1
1 5592
weaknessforcats
9,208 Expert Mod 8TB
One thing I see is the incorrect use of tchar.h mappings. RegisterClassEx is a macro that resolves to RegisterClassA or RegisterClassW depending upon the character set used on the build. Ditto for CreateWindowEx().

I assume you are compiling in ASCII because this code won't work in Unicode.

I'm not sure it works now. For example, the class name required by CreateWindow() is an LPCTSTR and you are providing a PCXAChar instead (whatever that is).

I would have thought you would:

LPCTSTR sClassName = TEXT("WndProc");


I recommend you adhere strictly to the tchar.h mappings and then see of the problem persists.
Jul 24 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Chris | last post by:
Hi. I'm trying to make a python program that can recieve WM_COPYDATA messages. Not ideal, but the application I'll be receiving them from will only send it that way. So I wrote a small program...
9
by: Rajat Tandon | last post by:
Hello there, I am relatively new to the newsgroups and C#. I have never been disappointed with the groups and always got the prompt replies to my queries.This is yet another strange issue, I am...
0
by: Gianluca | last post by:
Anyone knows if the bug in NativeWindow.RegisterClass and the class names list being case sensitive is scheduled to be fixed or already fixed? In short, NativeWindow.RegisterClass keeps a list of...
4
by: Madhu Gopinathan | last post by:
Hi All, I am faced with a horrible hang problem. I have a COM exe server that executes some tasks. The task execution manager is a thread that manages the pool of threads, which is 4 per processor....
1
by: Günther Rühmann | last post by:
Hi, I´m not sure if i´m right int this group... My problem: I made a vb .net application that reads from AD via System.Directoryservices.Directoryentry. The appliocation enumerates group...
3
by: fong01 | last post by:
See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box. ************** Exception Text ************** System.Net.Sockets.SocketException: No...
0
by: Andreas | last post by:
Extension: --------------- pyshapelib 0.3 with Python 2.4 Problem: ------------- D:\Python24\Lib\site-packages\shapelib\setup>pytest.py Traceback (most recent call last): File...
21
by: Paul Edwards | last post by:
I have written a public domain (not GPL etc) C runtime library (PDPCLIB) for DOS, OS/2 and MVS. You can see it here: http://sourceforge.net/projects/pdos/ I now wish to port it to Win32, so...
1
by: codercoder | last post by:
I have on method call another method NotificationWndProc to create a notification window, which will receive messages. At the first time, things are running OK, but in the second time, it returns...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.