I have as class as follows:
#include <Windows.h>
class MyClass
{
void A();
static BOOL CALLBACK proc(HWND hwnd, LPARAM lParam);
};
void MyClass::A()
{
EnumChildWindows(GetDesktopWindow(), MyClass::proc, static_cast<LPARAM>(this));
}
BOOL CALLBACK MyClass::proc(HWND hwnd, LPARAM lParam)
{
// ...
return TRUE;
}
When I attempt to compile this in Visual C++ 2010, I get the following compiler error:
error C2440: 'static_cast' : cannot convert from 'MyClass *const ' to 'LPARAM' There is no context in which this conversion is possible
If I change the definition of MyClass::A
as follows, then the compile succeeds:
void MyClass::A()
{
EnumChildWindows(GetDesktopWindow(), MyClass::proc, (LPARAM)this);
}
What is the explanation for the error in the first example?