1 // Windows Template Library - WTL version 8.0
2 // Copyright (C) Microsoft Corporation. All rights reserved.
4 // This file is a part of the Windows Template Library.
5 // The use and distribution terms for this software are covered by the
6 // Microsoft Permissive License (Ms-PL) which can be found in the file
7 // Ms-PL.txt at the root of this distribution.
15 #error ATL requires C++ compilation (use a .cpp suffix)
19 #error atlapp.h requires atlbase.h to be included first
24 #error WTL requires Windows version 4.0 or higher
27 #if (_WIN32_IE < 0x0300)
28 #error WTL requires IE version 3.0 or higher
32 #ifdef _ATL_NO_COMMODULE
33 #error WTL requires that _ATL_NO_COMMODULE is not defined
34 #endif // _ATL_NO_COMMODULE
36 #if defined(_WIN32_WCE) && defined(_ATL_MIN_CRT)
37 #pragma message("Warning: WTL for Windows CE doesn't use _ATL_MIN_CRT")
38 #endif // defined(_WIN32_WCE) && defined(_ATL_MIN_CRT)
41 #if !defined(_ATL_MIN_CRT) && defined(_MT) && !defined(_WIN32_WCE)
42 #include <process.h> // for _beginthreadex
45 #if (_ATL_VER < 0x0800) && !defined(_DEBUG)
51 #pragma comment(lib, "comctl32.lib")
60 // We need to disable this warning because of template class arguments
61 #pragma warning(disable: 4127)
64 ///////////////////////////////////////////////////////////////////////////////
67 #define _WTL_VER 0x0800
70 ///////////////////////////////////////////////////////////////////////////////
71 // Classes in this file:
81 // AtlGetDefaultGuiFont()
82 // AtlCreateBoldFont()
83 // AtlInitCommonControls()
86 ///////////////////////////////////////////////////////////////////////////////
87 // Global support for Windows CE
91 #ifndef SW_SHOWDEFAULT
92 #define SW_SHOWDEFAULT SW_SHOWNORMAL
93 #endif // !SW_SHOWDEFAULT
95 // These get's OR-ed in a constant and will have no effect.
96 // Defining them reduces the number of #ifdefs required for CE.
97 #define LR_DEFAULTSIZE 0
98 #define LR_LOADFROMFILE 0
101 #define SM_CXCURSOR 13
104 #define SM_CYCURSOR 14
107 inline BOOL
IsMenu(HMENU hMenu
)
109 MENUITEMINFO mii
= { sizeof(MENUITEMINFO
) };
111 BOOL bRet
= ::GetMenuItemInfo(hMenu
, 0, TRUE
, &mii
);
113 bRet
= (::GetLastError() != ERROR_INVALID_MENU_HANDLE
) ? TRUE
: FALSE
;
117 #if (_WIN32_WCE >= 410)
118 extern "C" void WINAPI
ListView_SetItemSpacing(HWND hwndLV
, int iHeight
);
119 #endif // (_WIN32_WCE >= 410)
121 inline int MulDiv(IN
int nNumber
, IN
int nNumerator
, IN
int nDenominator
)
123 __int64 multiple
= nNumber
* nNumerator
;
124 return static_cast<int>(multiple
/ nDenominator
);
127 #if (_ATL_VER >= 0x0800)
129 #ifndef _WTL_KEEP_WS_OVERLAPPEDWINDOW
130 #ifdef WS_OVERLAPPEDWINDOW
131 #undef WS_OVERLAPPEDWINDOW
132 #define WS_OVERLAPPEDWINDOW 0
133 #endif // WS_OVERLAPPEDWINDOW
134 #endif // !_WTL_KEEP_WS_OVERLAPPEDWINDOW
140 #ifndef WM_WINDOWPOSCHANGING
141 #define WM_WINDOWPOSCHANGING 0
142 #endif // !WM_WINDOWPOSCHANGING
144 #define FreeResource(x)
145 #define UnlockResource(x)
149 inline HRESULT
CComModule::RegisterClassObjects(DWORD
/*dwClsContext*/, DWORD
/*dwFlags*/) throw()
150 { return E_NOTIMPL
; }
151 inline HRESULT
CComModule::RevokeClassObjects() throw()
152 { return E_NOTIMPL
; }
156 #define lstrlenW (int)ATL::lstrlenW
159 inline int WINAPI
lstrlenA(LPCSTR lpszString
)
160 { return ATL::lstrlenA(lpszString
); }
164 #define lstrcpyn ATL::lstrcpynW
167 #ifndef SetWindowLongPtrW
168 inline LONG_PTR
tmp_SetWindowLongPtrW( HWND hWnd
, int nIndex
, LONG_PTR dwNewLong
)
170 return( ::SetWindowLongW( hWnd
, nIndex
, LONG( dwNewLong
) ) );
172 #define SetWindowLongPtrW tmp_SetWindowLongPtrW
175 #ifndef GetWindowLongPtrW
176 inline LONG_PTR
tmp_GetWindowLongPtrW( HWND hWnd
, int nIndex
)
178 return( ::GetWindowLongW( hWnd
, nIndex
) );
180 #define GetWindowLongPtrW tmp_GetWindowLongPtrW
184 #define LongToPtr(x) ((void*)x)
188 #define PtrToInt( p ) ((INT)(INT_PTR) (p) )
191 #else // !(_ATL_VER >= 0x0800)
195 #define lstrlenW (int)::wcslen
198 #define lstrlenA (int)strlen
201 inline LPTSTR
lstrcpyn(LPTSTR lpstrDest
, LPCTSTR lpstrSrc
, int nLength
)
203 if(lpstrDest
== NULL
|| lpstrSrc
== NULL
|| nLength
<= 0)
205 int nLen
= __min(lstrlen(lpstrSrc
), nLength
- 1);
206 LPTSTR lpstrRet
= (LPTSTR
)memcpy(lpstrDest
, lpstrSrc
, nLen
* sizeof(TCHAR
));
213 inline LPWSTR
lstrcpynW(LPWSTR lpstrDest
, LPCWSTR lpstrSrc
, int nLength
)
215 return lstrcpyn(lpstrDest
, lpstrSrc
, nLength
); // WinCE is Unicode only
220 inline LPSTR
lstrcpynA(LPSTR lpstrDest
, LPCSTR lpstrSrc
, int nLength
)
222 if(lpstrDest
== NULL
|| lpstrSrc
== NULL
|| nLength
<= 0)
224 int nLen
= __min(lstrlenA(lpstrSrc
), nLength
- 1);
225 LPSTR lpstrRet
= (LPSTR
)memcpy(lpstrDest
, lpstrSrc
, nLen
* sizeof(char));
231 #ifdef TrackPopupMenu
232 #undef TrackPopupMenu
233 #endif // TrackPopupMenu
235 #define DECLARE_WND_CLASS_EX(WndClassName, style, bkgnd) \
236 static CWndClassInfo& GetWndClassInfo() \
238 static CWndClassInfo wc = \
240 { style, StartWindowProc, \
241 0, 0, NULL, NULL, NULL, (HBRUSH)(bkgnd + 1), NULL, WndClassName }, \
242 NULL, NULL, IDC_ARROW, TRUE, 0, _T("") \
248 #define _MAX_FNAME _MAX_PATH
251 #if (_WIN32_WCE < 400)
252 #define MAKEINTATOM(i) (LPTSTR)((ULONG_PTR)((WORD)(i)))
253 #endif // (_WIN32_WCE < 400)
255 #if (_WIN32_WCE < 410)
256 #define WHEEL_PAGESCROLL (UINT_MAX)
257 #define WHEEL_DELTA 120
258 #endif // (_WIN32_WCE < 410)
274 #define VARCMP_NULL 3
277 #ifndef RDW_ALLCHILDREN
278 #define RDW_ALLCHILDREN 0
281 #endif // !(_ATL_VER >= 0x0800)
286 ///////////////////////////////////////////////////////////////////////////////
287 // Global support for using original VC++ 6.0 headers with WTL
289 #ifndef _ATL_NO_OLD_HEADERS_WIN64
290 #if !defined(_WIN64) && (_ATL_VER < 0x0700)
292 #ifndef PSM_INSERTPAGE
293 #define PSM_INSERTPAGE (WM_USER + 119)
294 #endif // !PSM_INSERTPAGE
296 #ifndef GetClassLongPtr
297 #define GetClassLongPtrA GetClassLongA
298 #define GetClassLongPtrW GetClassLongW
300 #define GetClassLongPtr GetClassLongPtrW
302 #define GetClassLongPtr GetClassLongPtrA
304 #endif // !GetClassLongPtr
307 #define GCLP_HICONSM (-34)
308 #endif // !GCLP_HICONSM
310 #ifndef GetWindowLongPtr
311 #define GetWindowLongPtrA GetWindowLongA
312 #define GetWindowLongPtrW GetWindowLongW
314 #define GetWindowLongPtr GetWindowLongPtrW
316 #define GetWindowLongPtr GetWindowLongPtrA
318 #endif // !GetWindowLongPtr
320 #ifndef SetWindowLongPtr
321 #define SetWindowLongPtrA SetWindowLongA
322 #define SetWindowLongPtrW SetWindowLongW
324 #define SetWindowLongPtr SetWindowLongPtrW
326 #define SetWindowLongPtr SetWindowLongPtrA
328 #endif // !SetWindowLongPtr
331 #define GWLP_WNDPROC (-4)
333 #ifndef GWLP_HINSTANCE
334 #define GWLP_HINSTANCE (-6)
336 #ifndef GWLP_HWNDPARENT
337 #define GWLP_HWNDPARENT (-8)
339 #ifndef GWLP_USERDATA
340 #define GWLP_USERDATA (-21)
343 #define GWLP_ID (-12)
346 #ifndef DWLP_MSGRESULT
347 #define DWLP_MSGRESULT 0
350 typedef long LONG_PTR
;
351 typedef unsigned long ULONG_PTR
;
352 typedef ULONG_PTR DWORD_PTR
;
354 #ifndef HandleToUlong
355 #define HandleToUlong( h ) ((ULONG)(ULONG_PTR)(h) )
358 #define HandleToLong( h ) ((LONG)(LONG_PTR) (h) )
361 #define LongToHandle( h) ((HANDLE)(LONG_PTR) (h))
364 #define PtrToUlong( p ) ((ULONG)(ULONG_PTR) (p) )
367 #define PtrToLong( p ) ((LONG)(LONG_PTR) (p) )
370 #define PtrToUint( p ) ((UINT)(UINT_PTR) (p) )
373 #define PtrToInt( p ) ((INT)(INT_PTR) (p) )
376 #define PtrToUshort( p ) ((unsigned short)(ULONG_PTR)(p) )
379 #define PtrToShort( p ) ((short)(LONG_PTR)(p) )
382 #define IntToPtr( i ) ((VOID *)(INT_PTR)((int)i))
385 #define UIntToPtr( ui ) ((VOID *)(UINT_PTR)((unsigned int)ui))
388 #define LongToPtr( l ) ((VOID *)(LONG_PTR)((long)l))
391 #define ULongToPtr( ul ) ((VOID *)(ULONG_PTR)((unsigned long)ul))
394 #endif // !defined(_WIN64) && (_ATL_VER < 0x0700)
395 #endif // !_ATL_NO_OLD_HEADERS_WIN64
398 ///////////////////////////////////////////////////////////////////////////////
399 // Global support for SecureHelper functions
402 #define _TRUNCATE ((size_t)-1)
405 #ifndef _ERRCODE_DEFINED
406 #define _ERRCODE_DEFINED
410 #ifndef _SECURECRT_ERRCODE_VALUES_DEFINED
411 #define _SECURECRT_ERRCODE_VALUES_DEFINED
417 #define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
421 ///////////////////////////////////////////////////////////////////////////////
422 // Miscellaneous global support
424 // define useful macros from winuser.h
425 #ifndef IS_INTRESOURCE
426 #define IS_INTRESOURCE(_r) (((ULONG_PTR)(_r) >> 16) == 0)
427 #endif // IS_INTRESOURCE
429 // protect template members from windowsx.h macros
431 #undef SubclassWindow
432 #endif // _INC_WINDOWSX
434 // define useful macros from windowsx.h
436 #define GET_X_LPARAM(lParam) ((int)(short)LOWORD(lParam))
439 #define GET_Y_LPARAM(lParam) ((int)(short)HIWORD(lParam))
442 // Dummy structs for compiling with /CLR
443 #if (_MSC_VER >= 1300) && defined(_MANAGED)
444 __if_not_exists(_IMAGELIST::_IMAGELIST
) { struct _IMAGELIST
{ }; }
445 __if_not_exists(_TREEITEM::_TREEITEM
) { struct _TREEITEM
{ }; }
446 __if_not_exists(_PSP::_PSP
) { struct _PSP
{ }; }
449 // Define ATLVERIFY macro for ATL3
450 #if (_ATL_VER < 0x0700)
453 #define ATLVERIFY(expr) ATLASSERT(expr)
455 #define ATLVERIFY(expr) (expr)
458 #endif // (_ATL_VER < 0x0700)
460 // Forward declaration for ATL3 and ATL11 fix
461 #if (((_ATL_VER < 0x0700) && defined(_ATL_DLL)) || (_ATL_VER >= 0x0B00)) && !defined(_WIN32_WCE)
462 namespace ATL
{ HRESULT
AtlGetCommCtrlVersion(LPDWORD pdwMajor
, LPDWORD pdwMinor
); };
469 #if (_ATL_VER >= 0x0700)
470 DECLARE_TRACE_CATEGORY(atlTraceUI
);
472 __declspec(selectany
) ATL::CTraceCategory
atlTraceUI(_T("atlTraceUI"));
474 #else // !(_ATL_VER >= 0x0700)
477 atlTraceUI
= 0x10000000
479 #endif // !(_ATL_VER >= 0x0700)
481 // Windows version helper
482 inline bool AtlIsOldWindows()
484 OSVERSIONINFO ovi
= { 0 };
485 ovi
.dwOSVersionInfoSize
= sizeof(OSVERSIONINFO
);
486 BOOL bRet
= ::GetVersionEx(&ovi
);
487 return (!bRet
|| !((ovi
.dwMajorVersion
>= 5) || (ovi
.dwMajorVersion
== 4 && ovi
.dwMinorVersion
>= 90)));
490 // default GUI font helper
491 inline HFONT
AtlGetDefaultGuiFont()
494 return (HFONT
)::GetStockObject(DEFAULT_GUI_FONT
);
496 return (HFONT
)::GetStockObject(SYSTEM_FONT
);
500 // bold font helper (NOTE: Caller owns the font, and should destroy it when done using it)
501 inline HFONT
AtlCreateBoldFont(HFONT hFont
= NULL
)
504 hFont
= AtlGetDefaultGuiFont();
505 ATLASSERT(hFont
!= NULL
);
506 HFONT hFontBold
= NULL
;
508 if(::GetObject(hFont
, sizeof(LOGFONT
), &lf
) == sizeof(LOGFONT
))
510 lf
.lfWeight
= FW_BOLD
;
511 hFontBold
= ::CreateFontIndirect(&lf
);
512 ATLASSERT(hFontBold
!= NULL
);
521 // Common Controls initialization helper
522 inline BOOL
AtlInitCommonControls(DWORD dwFlags
)
524 INITCOMMONCONTROLSEX iccx
= { sizeof(INITCOMMONCONTROLSEX
), dwFlags
};
525 BOOL bRet
= ::InitCommonControlsEx(&iccx
);
531 ///////////////////////////////////////////////////////////////////////////////
532 // RunTimeHelper - helper functions for Windows version and structure sizes
534 // Not for Windows CE
535 #if defined(_WIN32_WCE) && !defined(_WTL_NO_RUNTIME_STRUCT_SIZE)
536 #define _WTL_NO_RUNTIME_STRUCT_SIZE
539 #ifndef _WTL_NO_RUNTIME_STRUCT_SIZE
541 #ifndef _SIZEOF_STRUCT
542 #define _SIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member))
545 #if (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE)
546 #define REBARBANDINFO_V6_SIZE _SIZEOF_STRUCT(REBARBANDINFO, cxHeader)
547 #endif // (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE)
549 #if (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE)
550 #define LVGROUP_V5_SIZE _SIZEOF_STRUCT(LVGROUP, uAlign)
551 #endif // (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE)
553 #if (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE)
554 #define LVTILEINFO_V5_SIZE _SIZEOF_STRUCT(LVTILEINFO, puColumns)
555 #endif // (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE)
557 #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE)
558 #define MCHITTESTINFO_V1_SIZE _SIZEOF_STRUCT(MCHITTESTINFO, st)
559 #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE)
561 #if !defined(_WIN32_WCE) && (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE)
562 #define NONCLIENTMETRICS_V1_SIZE _SIZEOF_STRUCT(NONCLIENTMETRICS, lfMessageFont)
563 #endif // !defined(_WIN32_WCE) && (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE)
565 #endif // !_WTL_NO_RUNTIME_STRUCT_SIZE
567 namespace RunTimeHelper
570 inline bool IsCommCtrl6()
572 DWORD dwMajor
= 0, dwMinor
= 0;
573 HRESULT hRet
= ATL::AtlGetCommCtrlVersion(&dwMajor
, &dwMinor
);
574 return (SUCCEEDED(hRet
) && (dwMajor
>= 6));
577 inline bool IsVista()
579 OSVERSIONINFO ovi
= { sizeof(OSVERSIONINFO
) };
580 BOOL bRet
= ::GetVersionEx(&ovi
);
581 return ((bRet
!= FALSE
) && (ovi
.dwMajorVersion
>= 6));
583 #endif // !_WIN32_WCE
585 inline int SizeOf_REBARBANDINFO()
587 int nSize
= sizeof(REBARBANDINFO
);
588 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
589 if(!(IsVista() && IsCommCtrl6()))
590 nSize
= REBARBANDINFO_V6_SIZE
;
591 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
595 #if (_WIN32_WINNT >= 0x501)
596 inline int SizeOf_LVGROUP()
598 int nSize
= sizeof(LVGROUP
);
599 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
601 nSize
= LVGROUP_V5_SIZE
;
602 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
606 inline int SizeOf_LVTILEINFO()
608 int nSize
= sizeof(LVTILEINFO
);
609 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
611 nSize
= LVTILEINFO_V5_SIZE
;
612 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600)
615 #endif // (_WIN32_WINNT >= 0x501)
617 inline int SizeOf_MCHITTESTINFO()
619 int nSize
= sizeof(MCHITTESTINFO
);
620 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
621 if(!(IsVista() && IsCommCtrl6()))
622 nSize
= MCHITTESTINFO_V1_SIZE
;
623 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN)
628 inline int SizeOf_NONCLIENTMETRICS()
630 int nSize
= sizeof(NONCLIENTMETRICS
);
631 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600)
633 nSize
= NONCLIENTMETRICS_V1_SIZE
;
634 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600)
637 #endif // !_WIN32_WCE
641 ///////////////////////////////////////////////////////////////////////////////
642 // ModuleHelper - helper functions for ATL3 and ATL7 module classes
644 namespace ModuleHelper
646 inline HINSTANCE
GetModuleInstance()
648 #if (_ATL_VER >= 0x0700)
649 return ATL::_AtlBaseModule
.GetModuleInstance();
650 #else // !(_ATL_VER >= 0x0700)
651 return ATL::_pModule
->GetModuleInstance();
652 #endif // !(_ATL_VER >= 0x0700)
655 inline HINSTANCE
GetResourceInstance()
657 #if (_ATL_VER >= 0x0700)
658 return ATL::_AtlBaseModule
.GetResourceInstance();
659 #else // !(_ATL_VER >= 0x0700)
660 return ATL::_pModule
->GetResourceInstance();
661 #endif // !(_ATL_VER >= 0x0700)
664 inline void AddCreateWndData(ATL::_AtlCreateWndData
* pData
, void* pObject
)
666 #if (_ATL_VER >= 0x0700)
667 ATL::_AtlWinModule
.AddCreateWndData(pData
, pObject
);
668 #else // !(_ATL_VER >= 0x0700)
669 ATL::_pModule
->AddCreateWndData(pData
, pObject
);
670 #endif // !(_ATL_VER >= 0x0700)
673 inline void* ExtractCreateWndData()
675 #if (_ATL_VER >= 0x0700)
676 return ATL::_AtlWinModule
.ExtractCreateWndData();
677 #else // !(_ATL_VER >= 0x0700)
678 return ATL::_pModule
->ExtractCreateWndData();
679 #endif // !(_ATL_VER >= 0x0700)
684 ///////////////////////////////////////////////////////////////////////////////
685 // SecureHelper - helper functions for VS2005 secure CRT
687 namespace SecureHelper
689 inline void strcpyA_x(char* lpstrDest
, size_t cchDest
, const char* lpstrSrc
)
692 ATL::Checked::strcpy_s(lpstrDest
, cchDest
, lpstrSrc
);
694 if(cchDest
> (size_t)lstrlenA(lpstrSrc
))
695 ATLVERIFY(lstrcpyA(lpstrDest
, lpstrSrc
) != NULL
);
701 inline void strcpyW_x(wchar_t* lpstrDest
, size_t cchDest
, const wchar_t* lpstrSrc
)
704 ATL::Checked::wcscpy_s(lpstrDest
, cchDest
, lpstrSrc
);
706 if(cchDest
> (size_t)lstrlenW(lpstrSrc
))
707 ATLVERIFY(lstrcpyW(lpstrDest
, lpstrSrc
) != NULL
);
713 inline void strcpy_x(LPTSTR lpstrDest
, size_t cchDest
, LPCTSTR lpstrSrc
)
716 strcpyW_x(lpstrDest
, cchDest
, lpstrSrc
);
718 strcpyA_x(lpstrDest
, cchDest
, lpstrSrc
);
722 inline errno_t
strncpyA_x(char* lpstrDest
, size_t cchDest
, const char* lpstrSrc
, size_t cchCount
)
725 return ATL::Checked::strncpy_s(lpstrDest
, cchDest
, lpstrSrc
, cchCount
);
728 if(lpstrDest
== NULL
|| cchDest
== 0 || lpstrSrc
== NULL
)
732 else if(cchCount
== _TRUNCATE
)
734 cchCount
= __min(cchDest
- 1, size_t(lstrlenA(lpstrSrc
)));
737 else if(cchDest
<= cchCount
)
742 if(nRet
== 0 || nRet
== STRUNCATE
)
743 nRet
= (lstrcpynA(lpstrDest
, lpstrSrc
, (int)cchCount
+ 1) != NULL
) ? nRet
: EINVAL
;
744 ATLASSERT(nRet
== 0 || nRet
== STRUNCATE
);
749 inline errno_t
strncpyW_x(wchar_t* lpstrDest
, size_t cchDest
, const wchar_t* lpstrSrc
, size_t cchCount
)
752 return ATL::Checked::wcsncpy_s(lpstrDest
, cchDest
, lpstrSrc
, cchCount
);
755 if(lpstrDest
== NULL
|| cchDest
== 0 || lpstrSrc
== NULL
)
759 else if(cchCount
== _TRUNCATE
)
761 cchCount
= __min(cchDest
- 1, size_t(lstrlenW(lpstrSrc
)));
764 else if(cchDest
<= cchCount
)
769 if(nRet
== 0 || nRet
== STRUNCATE
)
770 nRet
= (lstrcpynW(lpstrDest
, lpstrSrc
, (int)cchCount
+ 1) != NULL
) ? nRet
: EINVAL
;
771 ATLASSERT(nRet
== 0 || nRet
== STRUNCATE
);
776 inline errno_t
strncpy_x(LPTSTR lpstrDest
, size_t cchDest
, LPCTSTR lpstrSrc
, size_t cchCount
)
779 return strncpyW_x(lpstrDest
, cchDest
, lpstrSrc
, cchCount
);
781 return strncpyA_x(lpstrDest
, cchDest
, lpstrSrc
, cchCount
);
785 inline void strcatA_x(char* lpstrDest
, size_t cchDest
, const char* lpstrSrc
)
788 ATL::Checked::strcat_s(lpstrDest
, cchDest
, lpstrSrc
);
790 if(cchDest
> (size_t)lstrlenA(lpstrSrc
))
791 ATLVERIFY(lstrcatA(lpstrDest
, lpstrSrc
) != NULL
);
797 inline void strcatW_x(wchar_t* lpstrDest
, size_t cchDest
, const wchar_t* lpstrSrc
)
800 ATL::Checked::wcscat_s(lpstrDest
, cchDest
, lpstrSrc
);
802 if(cchDest
> (size_t)lstrlenW(lpstrSrc
))
803 ATLVERIFY(lstrcatW(lpstrDest
, lpstrSrc
) != NULL
);
809 inline void strcat_x(LPTSTR lpstrDest
, size_t cchDest
, LPCTSTR lpstrSrc
)
812 strcatW_x(lpstrDest
, cchDest
, lpstrSrc
);
814 strcatA_x(lpstrDest
, cchDest
, lpstrSrc
);
818 inline void memcpy_x(void* pDest
, size_t cbDest
, const void* pSrc
, size_t cbSrc
)
821 ATL::Checked::memcpy_s(pDest
, cbDest
, pSrc
, cbSrc
);
824 memcpy(pDest
, pSrc
, cbSrc
);
830 inline void memmove_x(void* pDest
, size_t cbDest
, const void* pSrc
, size_t cbSrc
)
833 ATL::Checked::memmove_s(pDest
, cbDest
, pSrc
, cbSrc
);
836 memmove(pDest
, pSrc
, cbSrc
);
842 inline int vsprintf_x(LPTSTR lpstrBuff
, size_t cchBuff
, LPCTSTR lpstrFormat
, va_list args
)
844 #if _SECURE_ATL && !defined(_ATL_MIN_CRT) && !defined(_WIN32_WCE)
845 return _vstprintf_s(lpstrBuff
, cchBuff
, lpstrFormat
, args
);
847 cchBuff
; // Avoid unused argument warning
848 return _vstprintf(lpstrBuff
, lpstrFormat
, args
);
852 inline int wvsprintf_x(LPTSTR lpstrBuff
, size_t cchBuff
, LPCTSTR lpstrFormat
, va_list args
)
854 #if _SECURE_ATL && !defined(_ATL_MIN_CRT) && !defined(_WIN32_WCE)
855 return _vstprintf_s(lpstrBuff
, cchBuff
, lpstrFormat
, args
);
857 cchBuff
; // Avoid unused argument warning
858 return ::wvsprintf(lpstrBuff
, lpstrFormat
, args
);
862 inline int sprintf_x(LPTSTR lpstrBuff
, size_t cchBuff
, LPCTSTR lpstrFormat
, ...)
865 va_start(args
, lpstrFormat
);
866 int nRes
= vsprintf_x(lpstrBuff
, cchBuff
, lpstrFormat
, args
);
871 inline int wsprintf_x(LPTSTR lpstrBuff
, size_t cchBuff
, LPCTSTR lpstrFormat
, ...)
874 va_start(args
, lpstrFormat
);
875 int nRes
= wvsprintf_x(lpstrBuff
, cchBuff
, lpstrFormat
, args
);
879 }; // namespace SecureHelper
882 ///////////////////////////////////////////////////////////////////////////////
883 // CMessageFilter - Interface for message filter support
888 virtual BOOL
PreTranslateMessage(MSG
* pMsg
) = 0;
892 ///////////////////////////////////////////////////////////////////////////////
893 // CIdleHandler - Interface for idle processing
898 virtual BOOL
OnIdle() = 0;
901 #ifndef _ATL_NO_OLD_NAMES
902 // for compatilibility with old names only
903 typedef CIdleHandler CUpdateUIObject
;
904 #define DoUpdate OnIdle
905 #endif // !_ATL_NO_OLD_NAMES
908 ///////////////////////////////////////////////////////////////////////////////
909 // CMessageLoop - message loop implementation
914 ATL::CSimpleArray
<CMessageFilter
*> m_aMsgFilter
;
915 ATL::CSimpleArray
<CIdleHandler
*> m_aIdleHandler
;
918 // Message filter operations
919 BOOL
AddMessageFilter(CMessageFilter
* pMessageFilter
)
921 return m_aMsgFilter
.Add(pMessageFilter
);
924 BOOL
RemoveMessageFilter(CMessageFilter
* pMessageFilter
)
926 return m_aMsgFilter
.Remove(pMessageFilter
);
929 // Idle handler operations
930 BOOL
AddIdleHandler(CIdleHandler
* pIdleHandler
)
932 return m_aIdleHandler
.Add(pIdleHandler
);
935 BOOL
RemoveIdleHandler(CIdleHandler
* pIdleHandler
)
937 return m_aIdleHandler
.Remove(pIdleHandler
);
940 #ifndef _ATL_NO_OLD_NAMES
941 // for compatilibility with old names only
942 BOOL
AddUpdateUI(CIdleHandler
* pIdleHandler
)
944 ATLTRACE2(atlTraceUI
, 0, _T("CUpdateUIObject and AddUpdateUI are deprecated. Please change your code to use CIdleHandler and OnIdle\n"));
945 return AddIdleHandler(pIdleHandler
);
948 BOOL
RemoveUpdateUI(CIdleHandler
* pIdleHandler
)
950 ATLTRACE2(atlTraceUI
, 0, _T("CUpdateUIObject and RemoveUpdateUI are deprecated. Please change your code to use CIdleHandler and OnIdle\n"));
951 return RemoveIdleHandler(pIdleHandler
);
953 #endif // !_ATL_NO_OLD_NAMES
964 while(bDoIdle
&& !::PeekMessage(&m_msg
, NULL
, 0, 0, PM_NOREMOVE
))
966 if(!OnIdle(nIdleCount
++))
970 bRet
= ::GetMessage(&m_msg
, NULL
, 0, 0);
974 ATLTRACE2(atlTraceUI
, 0, _T("::GetMessage returned -1 (error)\n"));
975 continue; // error, don't process
979 ATLTRACE2(atlTraceUI
, 0, _T("CMessageLoop::Run - exiting\n"));
980 break; // WM_QUIT, exit message loop
983 if(!PreTranslateMessage(&m_msg
))
985 ::TranslateMessage(&m_msg
);
986 ::DispatchMessage(&m_msg
);
989 if(IsIdleMessage(&m_msg
))
996 return (int)m_msg
.wParam
;
999 static BOOL
IsIdleMessage(MSG
* pMsg
)
1001 // These messages should NOT cause idle processing
1002 switch(pMsg
->message
)
1006 case WM_NCMOUSEMOVE
:
1007 #endif // !_WIN32_WCE
1009 case 0x0118: // WM_SYSTIMER (caret blink)
1017 // Override to change message filtering
1018 virtual BOOL
PreTranslateMessage(MSG
* pMsg
)
1021 for(int i
= m_aMsgFilter
.GetSize() - 1; i
>= 0; i
--)
1023 CMessageFilter
* pMessageFilter
= m_aMsgFilter
[i
];
1024 if(pMessageFilter
!= NULL
&& pMessageFilter
->PreTranslateMessage(pMsg
))
1027 return FALSE
; // not translated
1030 // override to change idle processing
1031 virtual BOOL
OnIdle(int /*nIdleCount*/)
1033 for(int i
= 0; i
< m_aIdleHandler
.GetSize(); i
++)
1035 CIdleHandler
* pIdleHandler
= m_aIdleHandler
[i
];
1036 if(pIdleHandler
!= NULL
)
1037 pIdleHandler
->OnIdle();
1039 return FALSE
; // don't continue
1044 ///////////////////////////////////////////////////////////////////////////////
1045 // CStaticDataInitCriticalSectionLock and CWindowCreateCriticalSectionLock
1046 // internal classes to manage critical sections for both ATL3 and ATL7
1048 class CStaticDataInitCriticalSectionLock
1051 #if (_ATL_VER >= 0x0700)
1052 ATL::CComCritSecLock
<ATL::CComCriticalSection
> m_cslock
;
1054 CStaticDataInitCriticalSectionLock() : m_cslock(ATL::_pAtlModule
->m_csStaticDataInitAndTypeInfo
, false)
1056 #endif // (_ATL_VER >= 0x0700)
1060 #if (_ATL_VER >= 0x0700)
1061 return m_cslock
.Lock();
1062 #else // !(_ATL_VER >= 0x0700)
1063 ::EnterCriticalSection(&ATL::_pModule
->m_csStaticDataInit
);
1065 #endif // !(_ATL_VER >= 0x0700)
1070 #if (_ATL_VER >= 0x0700)
1072 #else // !(_ATL_VER >= 0x0700)
1073 ::LeaveCriticalSection(&ATL::_pModule
->m_csStaticDataInit
);
1074 #endif // !(_ATL_VER >= 0x0700)
1079 class CWindowCreateCriticalSectionLock
1082 #if (_ATL_VER >= 0x0700)
1083 ATL::CComCritSecLock
<ATL::CComCriticalSection
> m_cslock
;
1085 CWindowCreateCriticalSectionLock() : m_cslock(ATL::_AtlWinModule
.m_csWindowCreate
, false)
1087 #endif // (_ATL_VER >= 0x0700)
1091 #if (_ATL_VER >= 0x0700)
1092 return m_cslock
.Lock();
1093 #else // !(_ATL_VER >= 0x0700)
1094 ::EnterCriticalSection(&ATL::_pModule
->m_csWindowCreate
);
1096 #endif // !(_ATL_VER >= 0x0700)
1101 #if (_ATL_VER >= 0x0700)
1103 #else // !(_ATL_VER >= 0x0700)
1104 ::LeaveCriticalSection(&ATL::_pModule
->m_csWindowCreate
);
1105 #endif // !(_ATL_VER >= 0x0700)
1110 ///////////////////////////////////////////////////////////////////////////////
1111 // CTempBuffer - helper class for stack allocations for ATL3
1113 #ifndef _WTL_STACK_ALLOC_THRESHOLD
1114 #define _WTL_STACK_ALLOC_THRESHOLD 512
1117 #if (_ATL_VER >= 0x0700)
1119 using ATL::CTempBuffer
;
1121 #else // !(_ATL_VER >= 0x0700)
1125 #define SIZE_MAX _UI64_MAX
1127 #define SIZE_MAX UINT_MAX
1131 #pragma warning(disable: 4284) // warning for operator ->
1133 template<typename T
, int t_nFixedBytes
= 128>
1137 CTempBuffer() : m_p(NULL
)
1141 CTempBuffer(size_t nElements
) : m_p(NULL
)
1143 Allocate(nElements
);
1148 if(m_p
!= reinterpret_cast<T
*>(m_abFixedBuffer
))
1157 T
* operator ->() const
1159 ATLASSERT(m_p
!= NULL
);
1163 T
* Allocate(size_t nElements
)
1165 ATLASSERT(nElements
<= (SIZE_MAX
/ sizeof(T
)));
1166 return AllocateBytes(nElements
* sizeof(T
));
1169 T
* AllocateBytes(size_t nBytes
)
1171 ATLASSERT(m_p
== NULL
);
1172 if(nBytes
> t_nFixedBytes
)
1173 m_p
= static_cast<T
*>(malloc(nBytes
));
1175 m_p
= reinterpret_cast<T
*>(m_abFixedBuffer
);
1182 BYTE m_abFixedBuffer
[t_nFixedBytes
];
1185 #pragma warning(default: 4284)
1187 #endif // !(_ATL_VER >= 0x0700)
1190 ///////////////////////////////////////////////////////////////////////////////
1191 // CAppModule - module class for an application
1193 class CAppModule
: public ATL::CComModule
1196 DWORD m_dwMainThreadID
;
1197 ATL::CSimpleMap
<DWORD
, CMessageLoop
*>* m_pMsgLoopMap
;
1198 ATL::CSimpleArray
<HWND
>* m_pSettingChangeNotify
;
1200 // Overrides of CComModule::Init and Term
1201 HRESULT
Init(ATL::_ATL_OBJMAP_ENTRY
* pObjMap
, HINSTANCE hInstance
, const GUID
* pLibID
= NULL
)
1203 HRESULT hRet
= CComModule::Init(pObjMap
, hInstance
, pLibID
);
1207 m_dwMainThreadID
= ::GetCurrentThreadId();
1208 typedef ATL::CSimpleMap
<DWORD
, CMessageLoop
*> _mapClass
;
1209 m_pMsgLoopMap
= NULL
;
1210 ATLTRY(m_pMsgLoopMap
= new _mapClass
);
1211 if(m_pMsgLoopMap
== NULL
)
1212 return E_OUTOFMEMORY
;
1213 m_pSettingChangeNotify
= NULL
;
1220 TermSettingChangeNotify();
1221 delete m_pMsgLoopMap
;
1225 // Message loop map methods
1226 BOOL
AddMessageLoop(CMessageLoop
* pMsgLoop
)
1228 CStaticDataInitCriticalSectionLock lock
;
1229 if(FAILED(lock
.Lock()))
1231 ATLTRACE2(atlTraceUI
, 0, _T("ERROR : Unable to lock critical section in CAppModule::AddMessageLoop.\n"));
1236 ATLASSERT(pMsgLoop
!= NULL
);
1237 ATLASSERT(m_pMsgLoopMap
->Lookup(::GetCurrentThreadId()) == NULL
); // not in map yet
1239 BOOL bRet
= m_pMsgLoopMap
->Add(::GetCurrentThreadId(), pMsgLoop
);
1246 BOOL
RemoveMessageLoop()
1248 CStaticDataInitCriticalSectionLock lock
;
1249 if(FAILED(lock
.Lock()))
1251 ATLTRACE2(atlTraceUI
, 0, _T("ERROR : Unable to lock critical section in CAppModule::RemoveMessageLoop.\n"));
1256 BOOL bRet
= m_pMsgLoopMap
->Remove(::GetCurrentThreadId());
1263 CMessageLoop
* GetMessageLoop(DWORD dwThreadID
= ::GetCurrentThreadId()) const
1265 CStaticDataInitCriticalSectionLock lock
;
1266 if(FAILED(lock
.Lock()))
1268 ATLTRACE2(atlTraceUI
, 0, _T("ERROR : Unable to lock critical section in CAppModule::GetMessageLoop.\n"));
1273 CMessageLoop
* pLoop
= m_pMsgLoopMap
->Lookup(dwThreadID
);
1280 // Setting change notify methods
1281 // Note: Call this from the main thread for MSDI apps
1282 BOOL
InitSettingChangeNotify(DLGPROC pfnDlgProc
= _SettingChangeDlgProc
)
1284 CStaticDataInitCriticalSectionLock lock
;
1285 if(FAILED(lock
.Lock()))
1287 ATLTRACE2(atlTraceUI
, 0, _T("ERROR : Unable to lock critical section in CAppModule::InitSettingChangeNotify.\n"));
1292 if(m_pSettingChangeNotify
== NULL
)
1294 typedef ATL::CSimpleArray
<HWND
> _notifyClass
;
1295 ATLTRY(m_pSettingChangeNotify
= new _notifyClass
);
1296 ATLASSERT(m_pSettingChangeNotify
!= NULL
);
1299 BOOL bRet
= (m_pSettingChangeNotify
!= NULL
);
1300 if(bRet
&& m_pSettingChangeNotify
->GetSize() == 0)
1303 _ATL_EMPTY_DLGTEMPLATE templ
;
1304 HWND hNtfWnd
= ::CreateDialogIndirect(GetModuleInstance(), &templ
, NULL
, pfnDlgProc
);
1305 ATLASSERT(::IsWindow(hNtfWnd
));
1306 if(::IsWindow(hNtfWnd
))
1308 // need conditional code because types don't match in winuser.h
1310 ::SetWindowLongPtr(hNtfWnd
, GWLP_USERDATA
, (LONG_PTR
)this);
1312 ::SetWindowLongPtr(hNtfWnd
, GWLP_USERDATA
, PtrToLong(this));
1314 bRet
= m_pSettingChangeNotify
->Add(hNtfWnd
);
1327 void TermSettingChangeNotify()
1329 CStaticDataInitCriticalSectionLock lock
;
1330 if(FAILED(lock
.Lock()))
1332 ATLTRACE2(atlTraceUI
, 0, _T("ERROR : Unable to lock critical section in CAppModule::TermSettingChangeNotify.\n"));
1337 if(m_pSettingChangeNotify
!= NULL
&& m_pSettingChangeNotify
->GetSize() > 0)
1338 ::DestroyWindow((*m_pSettingChangeNotify
)[0]);
1339 delete m_pSettingChangeNotify
;
1340 m_pSettingChangeNotify
= NULL
;
1345 BOOL
AddSettingChangeNotify(HWND hWnd
)
1347 CStaticDataInitCriticalSectionLock lock
;
1348 if(FAILED(lock
.Lock()))
1350 ATLTRACE2(atlTraceUI
, 0, _T("ERROR : Unable to lock critical section in CAppModule::AddSettingChangeNotify.\n"));
1355 ATLASSERT(::IsWindow(hWnd
));
1357 if(InitSettingChangeNotify() != FALSE
)
1358 bRet
= m_pSettingChangeNotify
->Add(hWnd
);
1365 BOOL
RemoveSettingChangeNotify(HWND hWnd
)
1367 CStaticDataInitCriticalSectionLock lock
;
1368 if(FAILED(lock
.Lock()))
1370 ATLTRACE2(atlTraceUI
, 0, _T("ERROR : Unable to lock critical section in CAppModule::RemoveSettingChangeNotify.\n"));
1376 if(m_pSettingChangeNotify
!= NULL
)
1377 bRet
= m_pSettingChangeNotify
->Remove(hWnd
);
1384 // Implementation - setting change notify dialog template and dialog procedure
1385 struct _ATL_EMPTY_DLGTEMPLATE
: DLGTEMPLATE
1387 _ATL_EMPTY_DLGTEMPLATE()
1389 memset(this, 0, sizeof(_ATL_EMPTY_DLGTEMPLATE
));
1392 WORD wMenu
, wClass
, wTitle
;
1396 static INT_PTR CALLBACK
_SettingChangeDlgProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1398 static BOOL CALLBACK
_SettingChangeDlgProc(HWND hWnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1401 if(uMsg
== WM_SETTINGCHANGE
)
1403 // need conditional code because types don't match in winuser.h
1405 CAppModule
* pModule
= (CAppModule
*)::GetWindowLongPtr(hWnd
, GWLP_USERDATA
);
1407 CAppModule
* pModule
= (CAppModule
*)LongToPtr(::GetWindowLongPtr(hWnd
, GWLP_USERDATA
));
1409 ATLASSERT(pModule
!= NULL
);
1410 ATLASSERT(pModule
->m_pSettingChangeNotify
!= NULL
);
1411 const UINT uTimeout
= 1500; // ms
1412 for(int i
= 1; i
< pModule
->m_pSettingChangeNotify
->GetSize(); i
++)
1414 #if !defined(_WIN32_WCE)
1415 ::SendMessageTimeout((*pModule
->m_pSettingChangeNotify
)[i
], uMsg
, wParam
, lParam
, SMTO_ABORTIFHUNG
, uTimeout
, NULL
);
1416 #elif(_WIN32_WCE >= 400) // CE specific
1417 ::SendMessageTimeout((*pModule
->m_pSettingChangeNotify
)[i
], uMsg
, wParam
, lParam
, SMTO_NORMAL
, uTimeout
, NULL
);
1418 #else // _WIN32_WCE < 400 specific
1420 ::SendMessage((*pModule
->m_pSettingChangeNotify
)[i
], uMsg
, wParam
, lParam
);
1430 ///////////////////////////////////////////////////////////////////////////////
1431 // CServerAppModule - module class for a COM server application
1433 class CServerAppModule
: public CAppModule
1436 HANDLE m_hEventShutdown
;
1441 // Override of CAppModule::Init
1442 HRESULT
Init(ATL::_ATL_OBJMAP_ENTRY
* pObjMap
, HINSTANCE hInstance
, const GUID
* pLibID
= NULL
)
1446 return CAppModule::Init(pObjMap
, hInstance
, pLibID
);
1451 if(m_hEventShutdown
!= NULL
&& ::CloseHandle(m_hEventShutdown
))
1452 m_hEventShutdown
= NULL
;
1456 // COM Server methods
1459 LONG lRet
= CComModule::Unlock();
1463 ::SetEvent(m_hEventShutdown
); // tell monitor that we transitioned to zero
1468 void MonitorShutdown()
1472 ::WaitForSingleObject(m_hEventShutdown
, INFINITE
);
1476 m_bActivity
= false;
1477 dwWait
= ::WaitForSingleObject(m_hEventShutdown
, m_dwTimeOut
);
1479 while(dwWait
== WAIT_OBJECT_0
);
1481 if(!m_bActivity
&& m_nLockCnt
== 0) // if no activity let's really bail
1483 #if ((_WIN32_WINNT >= 0x0400 ) || defined(_WIN32_DCOM)) && defined(_ATL_FREE_THREADED) && !defined(_WIN32_WCE)
1484 ::CoSuspendClassObjects();
1485 if(!m_bActivity
&& m_nLockCnt
== 0)
1490 // This handle should be valid now. If it isn't,
1491 // check if _Module.Term was called first (it shouldn't)
1492 if(::CloseHandle(m_hEventShutdown
))
1493 m_hEventShutdown
= NULL
;
1494 ::PostThreadMessage(m_dwMainThreadID
, WM_QUIT
, 0, 0);
1499 m_hEventShutdown
= ::CreateEvent(NULL
, false, false, NULL
);
1500 if(m_hEventShutdown
== NULL
)
1502 DWORD dwThreadID
= 0;
1503 #if !defined(_ATL_MIN_CRT) && defined(_MT) && !defined(_WIN32_WCE)
1504 HANDLE hThread
= (HANDLE
)_beginthreadex(NULL
, 0, (UINT (WINAPI
*)(void*))MonitorProc
, this, 0, (UINT
*)&dwThreadID
);
1506 HANDLE hThread
= ::CreateThread(NULL
, 0, MonitorProc
, this, 0, &dwThreadID
);
1508 bool bRet
= (hThread
!= NULL
);
1510 ::CloseHandle(hThread
);
1514 static DWORD WINAPI
MonitorProc(void* pv
)
1516 CServerAppModule
* p
= (CServerAppModule
*)pv
;
1517 p
->MonitorShutdown();
1521 #if (_ATL_VER < 0x0700)
1522 // search for an occurence of string p2 in string p1
1523 static LPCTSTR
FindOneOf(LPCTSTR p1
, LPCTSTR p2
)
1525 while(p1
!= NULL
&& *p1
!= NULL
)
1528 while(p
!= NULL
&& *p
!= NULL
)
1531 return ::CharNext(p1
);
1534 p1
= ::CharNext(p1
);
1538 #endif // (_ATL_VER < 0x0700)
1542 ///////////////////////////////////////////////////////////////////////////////
1543 // CString forward reference (enables CString use in atluser.h and atlgdi.h)
1545 #if defined(_WTL_FORWARD_DECLARE_CSTRING) && !defined(_WTL_USE_CSTRING)
1546 #define _WTL_USE_CSTRING
1547 #endif // defined(_WTL_FORWARD_DECLARE_CSTRING) && !defined(_WTL_USE_CSTRING)
1549 #ifdef _WTL_USE_CSTRING
1550 class CString
; // forward declaration (include atlmisc.h for the whole class)
1551 #endif // _WTL_USE_CSTRING
1553 // CString namespace
1556 #define _CSTRING_NS ATL
1558 #define _CSTRING_NS WTL
1560 #endif // _CSTRING_NS
1562 // Type classes namespace
1564 #ifdef __ATLTYPES_H__
1567 #define _WTYPES_NS WTL
1569 #endif // _WTYPES_NS
1574 ///////////////////////////////////////////////////////////////////////////////
1575 // General DLL version helpers
1576 // (ATL3: excluded from atlbase.h if _ATL_DLL is defined; ATL11: removed)
1578 #if (((_ATL_VER < 0x0700) && defined(_ATL_DLL)) || (_ATL_VER >= 0x0B00)) && !defined(_WIN32_WCE)
1583 inline HRESULT
AtlGetDllVersion(HINSTANCE hInstDLL
, DLLVERSIONINFO
* pDllVersionInfo
)
1585 ATLASSERT(pDllVersionInfo
!= NULL
);
1586 if(pDllVersionInfo
== NULL
)
1587 return E_INVALIDARG
;
1589 // We must get this function explicitly because some DLLs don't implement it.
1590 DLLGETVERSIONPROC pfnDllGetVersion
= (DLLGETVERSIONPROC
)::GetProcAddress(hInstDLL
, "DllGetVersion");
1591 if(pfnDllGetVersion
== NULL
)
1594 return (*pfnDllGetVersion
)(pDllVersionInfo
);
1597 inline HRESULT
AtlGetDllVersion(LPCTSTR lpstrDllName
, DLLVERSIONINFO
* pDllVersionInfo
)
1599 HINSTANCE hInstDLL
= ::LoadLibrary(lpstrDllName
);
1600 if(hInstDLL
== NULL
)
1602 HRESULT hRet
= AtlGetDllVersion(hInstDLL
, pDllVersionInfo
);
1603 ::FreeLibrary(hInstDLL
);
1607 // Common Control Versions:
1608 // Win95/WinNT 4.0 maj=4 min=00
1609 // IE 3.x maj=4 min=70
1610 // IE 4.0 maj=4 min=71
1611 inline HRESULT
AtlGetCommCtrlVersion(LPDWORD pdwMajor
, LPDWORD pdwMinor
)
1613 ATLASSERT(pdwMajor
!= NULL
&& pdwMinor
!= NULL
);
1614 if(pdwMajor
== NULL
|| pdwMinor
== NULL
)
1615 return E_INVALIDARG
;
1618 ::ZeroMemory(&dvi
, sizeof(dvi
));
1619 dvi
.cbSize
= sizeof(dvi
);
1620 HRESULT hRet
= AtlGetDllVersion(_T("comctl32.dll"), &dvi
);
1624 *pdwMajor
= dvi
.dwMajorVersion
;
1625 *pdwMinor
= dvi
.dwMinorVersion
;
1627 else if(hRet
== E_NOTIMPL
)
1629 // If DllGetVersion is not there, then the DLL is a version
1630 // previous to the one shipped with IE 3.x
1640 // Win95/WinNT 4.0 maj=4 min=00
1641 // IE 3.x, IE 4.0 without Web Integrated Desktop maj=4 min=00
1642 // IE 4.0 with Web Integrated Desktop maj=4 min=71
1643 // IE 4.01 with Web Integrated Desktop maj=4 min=72
1644 inline HRESULT
AtlGetShellVersion(LPDWORD pdwMajor
, LPDWORD pdwMinor
)
1646 ATLASSERT(pdwMajor
!= NULL
&& pdwMinor
!= NULL
);
1647 if(pdwMajor
== NULL
|| pdwMinor
== NULL
)
1648 return E_INVALIDARG
;
1651 ::ZeroMemory(&dvi
, sizeof(dvi
));
1652 dvi
.cbSize
= sizeof(dvi
);
1653 HRESULT hRet
= AtlGetDllVersion(_T("shell32.dll"), &dvi
);
1657 *pdwMajor
= dvi
.dwMajorVersion
;
1658 *pdwMinor
= dvi
.dwMinorVersion
;
1660 else if(hRet
== E_NOTIMPL
)
1662 // If DllGetVersion is not there, then the DLL is a version
1663 // previous to the one shipped with IE 4.x
1674 #endif // (_ATL_VER < 0x0700) && defined(_ATL_DLL) && !defined(_WIN32_WCE)
1677 // These are always included
1678 #include "atlwinx.h"
1679 #include "atluser.h"
1682 #ifndef _WTL_NO_AUTOMATIC_NAMESPACE
1683 using namespace WTL
;
1684 #endif // !_WTL_NO_AUTOMATIC_NAMESPACE
1686 #endif // __ATLAPP_H__