时间:2021-05-19
今天和同事说到C++模板会使代码膨胀, 可同事觉得不会。
同事的依据是: 如果模板会使代码膨胀, 那么ATL和WTL里为什么还要大量使用模板? 同样功能 ,ATL和WTL编译出的可执行文件可比MFC编译的要小的多。
我当时一愣 ,事实确实如同事所说,难道模板会使代码膨胀的观点是错误的吗?
MFC因为本身代码量和复杂性在那里, 所以它生成比较大的exe无可厚非。我们这里重点关注为什么ATL/WTL使用模板,但是却不会使生成的exe变大。
我们知道使用模板时, 同一模板生成不同的模板实类后会是多份代码 ,比如 vector<int>, vector<char>, vector<double>, 这里总共会生成3份不同的vector代码,这就是我们平时所说的代码膨胀。
那么为什么ATL/WTL就没有代码膨胀的问题呢?
我这里以 ATL里的窗口代码为例来分析这个问题,因为我对WinDbg比较熟悉,下面我会以WinDbg为工具来分析我以前的写得那个俄罗斯方块程序。
首先我们看一下ATL的窗口代码:
复制代码 代码如下:
template <class T, class TBase , class TWinTraits >
class ATL_NO_VTABLE CWindowImpl : public CWindowImplBaseT< TBase, TWinTraits >
{
public:
DECLARE_WND_CLASS(NULL)
static LPCTSTR GetWndCaption()
{
return NULL;
}
HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
DWORD dwStyle = 0, DWORD dwExStyle = 0,
_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL)
{
if (T::GetWndClassInfo().m_lpszOrigName == NULL)
T::GetWndClassInfo().m_lpszOrigName = GetWndClassName();
ATOM atom = T::GetWndClassInfo().Register(&m_pfnSuperWindowProc);
dwStyle = T::GetWndStyle(dwStyle);
dwExStyle = T::GetWndExStyle(dwExStyle);
// set caption
if (szWindowName == NULL)
szWindowName = T::GetWndCaption();
return CWindowImplBaseT< TBase, TWinTraits >::Create(hWndParent, rect, szWindowName,
dwStyle, dwExStyle, MenuOrID, atom, lpCreateParam);
}
};
上面是一个模板类,它应该会生成多份模板实例代码:我们可以用WinDbg的符号搜索命令来做验证:
输入 x HYTeris!ATL::CWindowImpl<* , 搜索所有以 HYTeris!ATL::CWindowImpl< 开头的符号
复制代码 代码如下:
0:000> x HYTeris!ATL::CWindowImpl<*
004592f0 HYTeris!ATL::CWindowImpl<CTsButton,WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
004343a0 HYTeris!ATL::CWindowImpl<CTsMainStatusPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::~CWindowImpl<CTsMainStatusPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
00437c90 HYTeris!ATL::CWindowImpl<CTsMainControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndCaption (void)
00430440 HYTeris!ATL::CWindowImpl<CTsGameMainWnd,ATL::CWindow,ATL::CWinTraits<114229248,262400> >::CWindowImpl<CTsGameMainWnd,ATL::CWindow,ATL::CWinTraits<114229248,262400> > (void)
0041c990 HYTeris!ATL::CWindowImpl<CTsAgentWindow,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndCaption (void)
0044cf50 HYTeris!ATL::CWindowImpl<CTsNextElementContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::~CWindowImpl<CTsNextElementContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
004539a0 HYTeris!ATL::CWindowImpl<CTsMutiScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
00435800 HYTeris!ATL::CWindowImpl<CTsGameMainWnd,ATL::CWindow,ATL::CWinTraits<114229248,262400> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
00434640 HYTeris!ATL::CWindowImpl<CTsKeyEdit,WTL::CEditT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::~CWindowImpl<CTsKeyEdit,WTL::CEditT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> > (void)
00437440 HYTeris!ATL::CWindowImpl<CTsGameMainWnd,ATL::CWindow,ATL::CWinTraits<114229248,262400> >::GetWndCaption (void)
00436020 HYTeris!ATL::CWindowImpl<CTsMainButtonPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
00453f70 HYTeris!ATL::CWindowImpl<CTsNextElementContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndCaption (void)
00424e30 HYTeris!ATL::CWindowImpl<CTsDisplayContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::~CWindowImpl<CTsDisplayContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
004338a0 HYTeris!ATL::CWindowImpl<CTsMainButtonPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::~CWindowImpl<CTsMainButtonPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
0041c4f0 HYTeris!ATL::CWindowImpl<CTsAgentWindow,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
00441b50 HYTeris!ATL::CWindowImpl<CTsKeyEdit,WTL::CEditT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::CWindowImpl<CTsKeyEdit,WTL::CEditT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> > (void)
004365f0 HYTeris!ATL::CWindowImpl<CTsMainControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
00455120 HYTeris!ATL::CWindowImpl<CTsButton,WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::CWindowImpl<CTsButton,WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> > (void)
0040ea20 HYTeris!ATL::CWindowImpl<CTsDisplayContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
00453fa0 HYTeris!ATL::CWindowImpl<CTsSingleScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndCaption (void)
0041abc0 HYTeris!ATL::CWindowImpl<CTsAgentWindow,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::CWindowImpl<CTsAgentWindow,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
00459c20 HYTeris!ATL::CWindowImpl<CTsSubControlContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::CWindowImpl<CTsSubControlContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
0045f640 HYTeris!ATL::CWindowImpl<CTsUserListCtrl,WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
004608a0 HYTeris!ATL::CWindowImpl<CTsSingleControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndClassInfo (void)
0045fed0 HYTeris!ATL::CWindowImpl<CTsSingleControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
00433a70 HYTeris!ATL::CWindowImpl<CTsMainControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::CWindowImpl<CTsMainControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
00437c60 HYTeris!ATL::CWindowImpl<CTsMainStatusPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndCaption (void)
0044fb70 HYTeris!ATL::CWindowImpl<CTsMainDisplayPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::~CWindowImpl<CTsMainDisplayPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
0041acf0 HYTeris!ATL::CWindowImpl<CTsAgentWindow,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::~CWindowImpl<CTsAgentWindow,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
00459510 HYTeris!ATL::CWindowImpl<CTsButton,WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::GetWndCaption (void)
00437a90 HYTeris!ATL::CWindowImpl<CTsMainButtonPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndCaption (void)
00430490 HYTeris!ATL::CWindowImpl<CTsGameMainWnd,ATL::CWindow,ATL::CWinTraits<114229248,262400> >::~CWindowImpl<CTsGameMainWnd,ATL::CWindow,ATL::CWinTraits<114229248,262400> > (void)
00424de0 HYTeris!ATL::CWindowImpl<CTsDisplayContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::CWindowImpl<CTsDisplayContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
00433ac0 HYTeris!ATL::CWindowImpl<CTsMainControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::~CWindowImpl<CTsMainControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
00433850 HYTeris!ATL::CWindowImpl<CTsMainButtonPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::CWindowImpl<CTsMainButtonPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
00433b60 HYTeris!ATL::CWindowImpl<CTsMainStatusPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::CWindowImpl<CTsMainStatusPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
00452050 HYTeris!ATL::CWindowImpl<CTsMutiScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::CWindowImpl<CTsMutiScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
0044f8e0 HYTeris!ATL::CWindowImpl<CTsMainDisplayPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::CWindowImpl<CTsMainDisplayPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
0044cec0 HYTeris!ATL::CWindowImpl<CTsNextElementContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::CWindowImpl<CTsNextElementContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
004340e0 HYTeris!ATL::CWindowImpl<CTsSingleControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::~CWindowImpl<CTsSingleControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
00433ef0 HYTeris!ATL::CWindowImpl<CTsButton,WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::~CWindowImpl<CTsButton,WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> > (void)
004348c0 HYTeris!ATL::CWindowImpl<CTsUserListCtrl,WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::~CWindowImpl<CTsUserListCtrl,WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > > (void)
004535b0 HYTeris!ATL::CWindowImpl<CTsNextElementContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
00454170 HYTeris!ATL::CWindowImpl<CTsMutiScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndCaption (void)
00459c70 HYTeris!ATL::CWindowImpl<CTsSubControlContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::~CWindowImpl<CTsSubControlContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
00451ed0 HYTeris!ATL::CWindowImpl<CTsSingleScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::CWindowImpl<CTsSingleScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
00451f20 HYTeris!ATL::CWindowImpl<CTsSingleScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::~CWindowImpl<CTsSingleScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
0045c4b0 HYTeris!ATL::CWindowImpl<CTsSingleControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::CWindowImpl<CTsSingleControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
00436320 HYTeris!ATL::CWindowImpl<CTsMainStatusPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
004536a0 HYTeris!ATL::CWindowImpl<CTsSingleScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
004604a0 HYTeris!ATL::CWindowImpl<CTsUserListCtrl,WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::GetWndCaption (void)
0040eca0 HYTeris!ATL::CWindowImpl<CTsDisplayContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndCaption (void)
0045ff90 HYTeris!ATL::CWindowImpl<CTsSubControlContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndCaption (void)
00437cc0 HYTeris!ATL::CWindowImpl<CTsMainDisplayPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndCaption (void)
004366e0 HYTeris!ATL::CWindowImpl<CTsMainDisplayPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
0045e620 HYTeris!ATL::CWindowImpl<CTsSubControlContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, void *)
004608d0 HYTeris!ATL::CWindowImpl<CTsSingleControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndCaption (void)
004520a0 HYTeris!ATL::CWindowImpl<CTsMutiScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::~CWindowImpl<CTsMutiScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
0045d210 HYTeris!ATL::CWindowImpl<CTsUserListCtrl,WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::CWindowImpl<CTsUserListCtrl,WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > > (void)
004d84a8 HYTeris!ATL::CWindowImpl<CTsMainControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004d84b8 HYTeris!ATL::CWindowImpl<CTsMainControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Array' = <no type information>
004d7970 HYTeris!ATL::CWindowImpl<CTsAgentWindow,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Array' = <no type information>
004d7960 HYTeris!ATL::CWindowImpl<CTsAgentWindow,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004d914c HYTeris!ATL::CWindowImpl<CTsSubControlContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004d8dd0 HYTeris!ATL::CWindowImpl<CTsMutiScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004d8b04 HYTeris!ATL::CWindowImpl<CTsMainDisplayPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004d8b14 HYTeris!ATL::CWindowImpl<CTsMainDisplayPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Array' = <no type information>
004d8ae8 HYTeris!ATL::CWindowImpl<CTsMainDisplayPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004e31b8 HYTeris!ATL::CWindowImpl<CTsSingleControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > `RTTI Type Descriptor' = <no type information>
004e2980 HYTeris!ATL::CWindowImpl<CTsMainDisplayPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > `RTTI Type Descriptor' = <no type information>
004d88c4 HYTeris!ATL::CWindowImpl<CTsKeyEdit,WTL::CEditT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004d8330 HYTeris!ATL::CWindowImpl<CTsMainButtonPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004d88f0 HYTeris!ATL::CWindowImpl<CTsKeyEdit,WTL::CEditT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Array' = <no type information>
004d88e0 HYTeris!ATL::CWindowImpl<CTsKeyEdit,WTL::CEditT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004d8a40 HYTeris!ATL::CWindowImpl<CTsNextElementContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004e30f0 HYTeris!ATL::CWindowImpl<CTsSubControlContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > `RTTI Type Descriptor' = <no type information>
004d8a5c HYTeris!ATL::CWindowImpl<CTsNextElementContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004d8a6c HYTeris!ATL::CWindowImpl<CTsNextElementContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Array' = <no type information>
004e21d0 HYTeris!ATL::CWindowImpl<CTsMainStatusPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > `RTTI Type Descriptor' = <no type information>
004d8c70 HYTeris!ATL::CWindowImpl<CTsSingleScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004e2e78 HYTeris!ATL::CWindowImpl<CTsButton,WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> > `RTTI Type Descriptor' = <no type information>
004e1f00 HYTeris!ATL::CWindowImpl<CTsGameMainWnd,ATL::CWindow,ATL::CWinTraits<114229248,262400> > `RTTI Type Descriptor' = <no type information>
004d9208 HYTeris!ATL::CWindowImpl<CTsSingleControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004d9218 HYTeris!ATL::CWindowImpl<CTsSingleControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Array' = <no type information>
004e1ad8 HYTeris!ATL::CWindowImpl<CTsDisplayContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > `RTTI Type Descriptor' = <no type information>
004d834c HYTeris!ATL::CWindowImpl<CTsMainButtonPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004d835c HYTeris!ATL::CWindowImpl<CTsMainButtonPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Array' = <no type information>
004d8c9c HYTeris!ATL::CWindowImpl<CTsSingleScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Array' = <no type information>
004d8c8c HYTeris!ATL::CWindowImpl<CTsSingleScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004d856c HYTeris!ATL::CWindowImpl<CTsMainStatusPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Array' = <no type information>
004d855c HYTeris!ATL::CWindowImpl<CTsMainStatusPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004e2bb8 HYTeris!ATL::CWindowImpl<CTsMutiScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > `RTTI Type Descriptor' = <no type information>
004d7fa0 HYTeris!ATL::CWindowImpl<CTsDisplayContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004d7fb0 HYTeris!ATL::CWindowImpl<CTsDisplayContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Array' = <no type information>
004d91ec HYTeris!ATL::CWindowImpl<CTsSingleControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004e2048 HYTeris!ATL::CWindowImpl<CTsMainButtonPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > `RTTI Type Descriptor' = <no type information>
004d8174 HYTeris!ATL::CWindowImpl<CTsGameMainWnd,ATL::CWindow,ATL::CWinTraits<114229248,262400> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004d8184 HYTeris!ATL::CWindowImpl<CTsGameMainWnd,ATL::CWindow,ATL::CWinTraits<114229248,262400> >::`RTTI Base Class Array' = <no type information>
004d8dfc HYTeris!ATL::CWindowImpl<CTsMutiScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Array' = <no type information>
004d8dec HYTeris!ATL::CWindowImpl<CTsMutiScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004e2728 HYTeris!ATL::CWindowImpl<CTsKeyEdit,WTL::CEditT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> > `RTTI Type Descriptor' = <no type information>
004e28c8 HYTeris!ATL::CWindowImpl<CTsNextElementContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > `RTTI Type Descriptor' = <no type information>
004d8fac HYTeris!ATL::CWindowImpl<CTsButton,WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Array' = <no type information>
004d8f9c HYTeris!ATL::CWindowImpl<CTsButton,WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004d848c HYTeris!ATL::CWindowImpl<CTsMainControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004d8f80 HYTeris!ATL::CWindowImpl<CTsButton,WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004d8158 HYTeris!ATL::CWindowImpl<CTsGameMainWnd,ATL::CWindow,ATL::CWinTraits<114229248,262400> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004d8540 HYTeris!ATL::CWindowImpl<CTsMainStatusPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004d7944 HYTeris!ATL::CWindowImpl<CTsAgentWindow,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004d7f84 HYTeris!ATL::CWindowImpl<CTsDisplayContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
004e2aa0 HYTeris!ATL::CWindowImpl<CTsSingleScoreContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> > `RTTI Type Descriptor' = <no type information>
004d9168 HYTeris!ATL::CWindowImpl<CTsSubControlContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Class Hierarchy Descriptor' = <no type information>
004d9178 HYTeris!ATL::CWindowImpl<CTsSubControlContainer,ATL::CWindow,ATL::CWinTraits<1442840576,0> >::`RTTI Base Class Array' = <no type information>
004e1628 HYTeris!ATL::CWindowImpl<CTsAgentWindow,ATL::CWindow,ATL::CWinTraits<1442840576,0> > `RTTI Type Descriptor' = <no type information>
004e2148 HYTeris!ATL::CWindowImpl<CTsMainControlPane,ATL::CWindow,ATL::CWinTraits<1442840576,0> > `RTTI Type Descriptor' = <no type information>
004d95c4 HYTeris!ATL::CWindowImpl<CTsUserListCtrl,WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::`RTTI Base Class Array' = <no type information>
004d95b4 HYTeris!ATL::CWindowImpl<CTsUserListCtrl,WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::`RTTI Class Hierarchy Descriptor' = <no type information>
004e3400 HYTeris!ATL::CWindowImpl<CTsUserListCtrl,WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > > `RTTI Type Descriptor' = <no type information>
004d9598 HYTeris!ATL::CWindowImpl<CTsUserListCtrl,WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::`RTTI Base Class Descriptor at (0,-1,0,64)' = <no type information>
上面的符号可以验证我们多份实例的猜想。
可以看到 CWindowImpl和我们的窗口继承类(T),窗口基类(TBase), 窗口风格(TWinTraits) 相关,所以数量很多 。 那么为什么这么多的符号,也就是这么多的函数代码 ,exe大小没有被撑大?
那时因为CWindowImpl类函数本身很小, 我们从函数的 代码量上就可以看出来。
用同样的方法 ,我们可以继续分析 CWindowImplBaseT
复制代码 代码如下:
template <class TBase = CWindow, class TWinTraits = CControlWinTraits>
class ATL_NO_VTABLE CWindowImplBaseT : public CWindowImplRoot< TBase >
{
public:
WNDPROC m_pfnSuperWindowProc;
CWindowImplBaseT() : m_pfnSuperWindowProc(::DefWindowProc)
{}
static DWORD GetWndStyle(DWORD dwStyle)
{
return TWinTraits::GetWndStyle(dwStyle);
}
static DWORD GetWndExStyle(DWORD dwExStyle)
{
return TWinTraits::GetWndExStyle(dwExStyle);
}
virtual WNDPROC GetWindowProc()
{
return WindowProc;
}
static LRESULT CALLBACK StartWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
HWND Create(HWND hWndParent, _U_RECT rect, LPCTSTR szWindowName,
DWORD dwStyle, DWORD dwExStyle, _U_MENUorID MenuOrID, ATOM atom, LPVOID lpCreateParam = NULL);
BOOL DestroyWindow()
{
ATLASSERT(::IsWindow(m_hWnd));
return ::DestroyWindow(m_hWnd);
}
BOOL SubclassWindow(HWND hWnd);
HWND UnsubclassWindow(BOOL bForce = FALSE);
LRESULT DefWindowProc()
{
const _ATL_MSG* pMsg = m_pCurrentMsg;
LRESULT lRes = 0;
if (pMsg != NULL)
lRes = DefWindowProc(pMsg->message, pMsg->wParam, pMsg->lParam);
return lRes;
}
LRESULT DefWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
#ifdef STRICT
return ::CallWindowProc(m_pfnSuperWindowProc, m_hWnd, uMsg, wParam, lParam);
#else
return ::CallWindowProc((FARPROC)m_pfnSuperWindowProc, m_hWnd, uMsg, wParam, lParam);
#endif
}
virtual void OnFinalMessage(HWND )
{
// override to do something, if needed
}
};
复制代码 代码如下:
0:000> x HYTeris!ATL::CWindowImplBaseT<*
0040f170 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, unsigned short, void *)
0040ec20 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndStyle (unsigned long)
00435970 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<114229248,262400> >::OnFinalMessage (struct HWND__ *)
004604d0 HYTeris!ATL::CWindowImplBaseT<WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::GetWndStyle (unsigned long)
00434a10 HYTeris!ATL::CWindowImplBaseT<WTL::CEditT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::~CWindowImplBaseT<WTL::CEditT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> > (void)
0040ec60 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >::GetWndExStyle (unsigned long)
00461740 HYTeris!ATL::CWindowImplBaseT<WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::WindowProc (struct HWND__ *, unsigned int, unsigned int, long)
0044c040 HYTeris!ATL::CWindowImplBaseT<WTL::CEditT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::WindowProc (struct HWND__ *, unsigned int, unsigned int, long)
004346e0 HYTeris!ATL::CWindowImplBaseT<WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::~CWindowImplBaseT<WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> > (void)
0041c440 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> > (void)
00435940 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<114229248,262400> >::GetWindowProc (void)
00459580 HYTeris!ATL::CWindowImplBaseT<WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::GetWndExStyle (unsigned long)
00461950 HYTeris!ATL::CWindowImplBaseT<WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, unsigned short, void *)
004395b0 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<114229248,262400> >::StartWindowProc (struct HWND__ *, unsigned int, unsigned int, long)
00439ea0 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<114229248,262400> >::DefWindowProcW (unsigned int, unsigned int, long)
00461620 HYTeris!ATL::CWindowImplBaseT<WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::StartWindowProc (struct HWND__ *, unsigned int, unsigned int, long)
004596e0 HYTeris!ATL::CWindowImplBaseT<WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::_U_MENUorID, unsigned short, void *)
0041ced0 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >::WindowProc (struct HWND__ *, unsigned int, unsigned int, long)
0044c370 HYTeris!ATL::CWindowImplBaseT<WTL::CEditT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::UnsubclassWindow (int)
00460510 HYTeris!ATL::CWindowImplBaseT<WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::GetWndExStyle (unsigned long)
00457f70 HYTeris!ATL::CWindowImplBaseT<WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::WindowProc (struct HWND__ *, unsigned int, unsigned int, long)
0045f830 HYTeris!ATL::CWindowImplBaseT<WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::GetWindowProc (void)
00457820 HYTeris!ATL::CWindowImplBaseT<WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::CWindowImplBaseT<WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> > (void)
004374b0 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<114229248,262400> >::GetWndExStyle (unsigned long)
00434ad0 HYTeris!ATL::CWindowImplBaseT<WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::~CWindowImplBaseT<WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > > (void)
004595c0 HYTeris!ATL::CWindowImplBaseT<WTL::CButtonT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::StartWindowProc (struct HWND__ *, unsigned int, unsigned int, long)
004358f0 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<114229248,262400> >::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<114229248,262400> > (void)
00445920 HYTeris!ATL::CWindowImplBaseT<WTL::CEditT<ATL::CWindow>,ATL::CWinTraits<1442840576,0> >::OnFinalMessage (struct HWND__ *)
00461ad0 HYTeris!ATL::CWindowImplBaseT<WTL::CListViewCtrlT<ATL::CWindow>,ATL::CWinTraitsOR<32777,0,ATL::CWinTraits<1442840576,0> > >::DefWindowProcW (unsigned int, unsigned int, long)
0041c4c0 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<1442840576,0> >::OnFinalMessage (struct HWND__ *)
00437470 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<114229248,262400> >::GetWndStyle (unsigned long)
004398e0 HYTeris!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<114229248,262400> >::Create (struct HWND__ *, class ATL::_U_RECT, wchar_t *, unsigned long, unsigned long, class ATL::
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
命名空间是C++非常重要的概念,本文就以实例形式对其进行深入分析,具体内容如下:通常来说,在C++中,命名空间(namespace)的目的是为了防止名字冲突。每
下面摘抄一下源码,深入分析一下他的设计实现思路:复制代码代码如下:functionformat(string){varargs=arguments;varpat
本文实例讲述了C#实现终止正在执行的线程的实现方法,并针对一些容易出错的地方进行了深入分析,具体方法如下:一般来说,很多人都会使用Abort方法来终止线程,其实
本文通过一个C程序实例对C语言中自动隐式转换与类型强制转换的注意点进行深入分析,详情如下:先看一个C程序:#include#include#includedou
当你涉及到C/C++的核心编程的时候,你会无止境地与内存管理打交道。这些往往会使人受尽折磨。所以如果你想深入C/C++编程,你必须静下心来,好好苦一番。现在我们