Discussion:
GetClassInfoEx( ) fails in a DLL
(too old to reply)
unknown
2009-12-03 13:05:20 UTC
Permalink
XP SP3
VS 2005

I've tried to use the code below in a dll at DLL_PROCESS_ATTACH:
It works on Vista but not XP.
(Well, it used to work and I don't know what has changed.)
The returned error is 1411, "Class does not exist"
I pasted the code into another app and it worked fine so it seems that it
has something to do with the dll.

A little later ...
I can't step into the dll at all now.
All I get is an error: "The application failed to initialize properly
(0xc0000142).
Any pointers on what to look for because I just seem to be digging a bigger
hole for myself.

[code]
WNDCLASSEX wcx;
ZeroMemory(&wcx,sizeof(WNDCLASSEX));
wcx.cbSize=sizeof(WNDCLASSEX);
if(!GetClassInfoEx(GetModuleHandle(NULL),"Edit",&wcx))
{
DWORD err=GetLastError();
return 0;
}
[/code]

Regards,
Ron Francis
www.RonaldFrancis.com
unknown
2009-12-05 13:30:47 UTC
Permalink
Post by unknown
XP SP3
VS 2005
It works on Vista but not XP.
(Well, it used to work and I don't know what has changed.)
The returned error is 1411, "Class does not exist"
I pasted the code into another app and it worked fine so it seems that it
has something to do with the dll.
[code]
WNDCLASSEX wcx;
ZeroMemory(&wcx,sizeof(WNDCLASSEX));
wcx.cbSize=sizeof(WNDCLASSEX);
if(!GetClassInfoEx(GetModuleHandle(NULL),"Edit",&wcx))
{
DWORD err=GetLastError();
return 0;
}
[/code]
Just bumping this along a little.
As I said, GetClassInfoEx returns an error "Class does not exist" if called
from inside DLL_PROCESS_ATTACH.
On further reading at MSDN, it seems that calling any functions from within
the entry point that don't reside in kernel32.dll aren't safe.
As GetClassInfoEx is in user32.dll, I guess I can assume that this is what
is causing the error?
What was confusing me was that it worked with some Apps and not others.

Can I ask a few questions?

Is it OK to store static variables like an ATOM and a pointer to a WNDPROC
in a DLL?
Is it OK to call UnregisterClass in DLL_PROCESS_DETACH ?
Just on that point, if there were multiple processes attached, would I have
to implement a counter to determine when to unregister the class?

I would like to register a class based on the 'Edit' class and have the
window procedure in the DLL.
Should the pointer to the window procedure be static?
I don't really like the idea of having to initialize from an EXE, so would
it be reasonable practice to initialize on the first call to a function and
set a bool so it only gets initialized once?

Thanks in advance.

Ron.
Igor Tandetnik
2009-12-05 14:02:37 UTC
Permalink
Post by unknown
Is it OK to store static variables like an ATOM and a pointer to a WNDPROC
in a DLL?
Yes.
Post by unknown
Is it OK to call UnregisterClass in DLL_PROCESS_DETACH ?
I'm not sure, but note that it's usually not necessary to call UnregisterClass at all.
Post by unknown
Just on that point, if there were multiple processes attached, would I have
to implement a counter to determine when to unregister the class?
No. RegisterClass and UnregisterClass are per-process.
Post by unknown
I would like to register a class based on the 'Edit' class and have the
window procedure in the DLL.
Should the pointer to the window procedure be static?
Why do you need a pointer to a window procedure in a separate variable, static or otherwise? I guess I don't understand the question, it doesn't make much sense to me.
Post by unknown
I don't really like the idea of having to initialize from an EXE, so would
it be reasonable practice to initialize on the first call to a function and
set a bool so it only gets initialized once?
Beware of concurrent calls from multiple threads.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
unknown
2009-12-05 23:00:53 UTC
Permalink
Post by Igor Tandetnik
Post by unknown
I would like to register a class based on the 'Edit' class and have the
window procedure in the DLL.
Should the pointer to the window procedure be static?
Why do you need a pointer to a window procedure in a separate variable,
static or otherwise? I guess I don't understand the question, it doesn't
make much sense to me.
This is purely to store a pointer to the original editbox procedure.
I guess the only time I would use it would be to set the editbox back to its
original state.
The long way round would be calling GetClassInfoEx again.
Post by Igor Tandetnik
Post by unknown
I don't really like the idea of having to initialize from an EXE, so would
it be reasonable practice to initialize on the first call to a function and
set a bool so it only gets initialized once?
Beware of concurrent calls from multiple threads.
Would CreateMutex be suitable here?

Thanks Igor.

Loading...