Answered at the bottom. Thanks!
The compiler caught error C2039 and C2065 correctly in Release version;
I'm just curious why the same code CAN pass compile in Debug version?
Is it a known Microsoft bug?
I know DECLARE_DYNAMIC/IMPLEMENT_DYNAMIC will solve the issue. However, without them, why Microsoft passed compile in my debug version? This is the question.
Known the reason. Michael's answer is exactly correct. _AFXDLL is only defined on my Debug configuration. So on Debug version it is using CObject::GetThisClass when expand the macro RUNTIME_CLASS.
So following code will be caught compiler error for both Release and Debug version if DECLARE_DYNAMIC/IMPLEMENT_DYNAMIC were not declared:
CRuntimeClass* p = (CRuntimeClass*) (&XXX::classXXX);
But following code will only fail if _AFXDLL is not pre-defined.
p->IsKindOf(RUNTIME_CLASS(XXX))
Thanks