News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

ERROR_CANNOT_FIND_WND_CLASS

Started by msmith, July 01, 2006, 04:26:25 AM

Previous topic - Next topic

msmith

The following code is my DLL entry code.


proc !DllEntryPoint, hinstDLL,fdwReason,lpvReserved
enter
mov eax,[hinstDLL]
mov [hInstance],eax
mov [!ControlClass.hInstance],eax
mov [!ControlClass.hIcon],0
invoke LoadCursor,0,IDC_ARROW
mov [!ControlClass.hCursor],eax
mov [!ControlClass.style],0
mov [!ControlClass.lpfnWndProc],!ControlProc
mov [!ControlClass.cbClsExtra],0
mov [!ControlClass.cbWndExtra],4
mov [!ControlClass.hbrBackground],0
mov [!ControlClass.lpszMenuName],0
mov [!ControlClass.lpszClassName],!ControlClassName
invoke RegisterClass,!ControlClass
mov [ControlClassAtom],eax
mov eax,TRUE
endp


When I use this DLL with my calling pgm and try to do a CreateWindowEx, I get an ERROR_CANNOT_FIND_WND_CLASS error and ControlClassAtom is 8C17F.

If I change the !ControlClass.style setting from the 0 shown to CS_GLOBALCLASS, the main pgm blows up (system screen).

Any help please.


Follow-up:

It appears that the original problem is that I need a globlal class and that RegisterClass may not support CS_GLOBALCLASS. Do I need to switch to RegisterClassEx? MSDN mentions that you need to switch to RegisterClassEx if you want support for small icons but makes no mention of CS_GLOBALCLASS.

TNick

Win32 Programmer'ws Reference help file say:

Application Global Classes



An application global class is a window class registered by a dynamic-link library (DLL) and available to all applications in the system. For example, your DLL can call the RegisterClassEx function to register a window class that defines a custom control as an application global class so that all applications can create instances of the custom control.

In Windows, all window classes are process specific. An application can create a global class by creating the window class in a DLL and listing the name of the DLL in the registry under the appropriate keys.
Whenever a process starts, the system loads the specified DLL in the context of the newly started process before calling the main function in that process. The DLL must register the class during its initialization procedure and must specify the CS_GLOBALCLASS style. (For more information about class styles, see Class Styles.) After a
class has been registered, any application can use it to create any number of windows belonging to that class.

Windows does not automatically destroy a class when the DLL that registered it is unloaded. For this reason, the Windows exit procedure of the DLL should call the UnregisterClass function to remove the class.

tenkey

Is !ControlClass defined in the .data section?
If so, you need to change the registering to

invoke RegisterClass,ADDR !ControlClass
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8

msmith

#3
tenkey.

!ControlClass was defined in the .data section. On FASM addr is assumed. Contents are explicitly shown as [var].

The problem was that I needed CS_GLOBALCLASS in the !ControlClass.style setting because the control is a dll.

The next problem I found was that it is possible (I don't know how) for Windows to call the proc with a different handle in the !hwnd arg than this control has. The result of this is to get a bad pointer in the GetWindowLong call. I have now added a "zero test" for the returned ptr from GetWindowLong. If it is a zero pointer, I transfer control to the default window process.

This seems to solve the problem.

Mike

tenkey

The Application Global Class is a window class that can be created by other modules without knowing the hInstance it was registered in. Otherwise, the hInstance in CreateWindowEx must match the hInstance used to register it.
A programming language is low level when its programs require attention to the irrelevant.
Alan Perlis, Epigram #8