18 #error WTL requires C++ compilation (use a .cpp suffix) 22 #error atlapp.h requires atlbase.h to be included first 27 #error WTL requires Windows version 4.0 or higher 30 #if (_WIN32_IE < 0x0300) 31 #error WTL requires IE version 3.0 or higher 35 #ifdef _ATL_NO_COMMODULE 36 #error WTL requires that _ATL_NO_COMMODULE is not defined 39 #if (_ATL_VER >= 0x0900) && defined(_ATL_MIN_CRT) 40 #error _ATL_MIN_CRT is not supported with ATL 9.0 and higher 43 #if defined(_WIN32_WCE) && defined(_ATL_MIN_CRT) 44 #pragma message("Warning: WTL for Windows CE doesn't use _ATL_MIN_CRT") 48 #if !defined(_ATL_MIN_CRT) && defined(_MT) && !defined(_WIN32_WCE) 52 #if (_ATL_VER < 0x0800) && !defined(_DEBUG) 58 #pragma comment(lib, "comctl32.lib") 68 #pragma warning(disable: 4127) 70 #if (_ATL_VER >= 0x0900) && !defined(_SECURE_ATL) 78 #define _WTL_VER 0x0810 105 #ifndef SW_SHOWDEFAULT 106 #define SW_SHOWDEFAULT SW_SHOWNORMAL 107 #endif // !SW_SHOWDEFAULT 111 #define LR_DEFAULTSIZE 0 112 #define LR_LOADFROMFILE 0 115 #define SM_CXCURSOR 13 118 #define SM_CYCURSOR 14 121 inline BOOL IsMenu(HMENU hMenu)
123 MENUITEMINFO mii = {
sizeof(MENUITEMINFO) };
125 BOOL bRet = ::GetMenuItemInfo(hMenu, 0, TRUE, &mii);
127 bRet = (::GetLastError() != ERROR_INVALID_MENU_HANDLE) ? TRUE : FALSE;
131 #if (_WIN32_WCE >= 410) 132 extern "C" void WINAPI ListView_SetItemSpacing(HWND hwndLV,
int iHeight);
133 #endif // (_WIN32_WCE >= 410) 135 inline int MulDiv(IN
int nNumber, IN
int nNumerator, IN
int nDenominator)
137 __int64 multiple = nNumber * nNumerator;
138 return static_cast<int>(multiple / nDenominator);
141 #if (_ATL_VER >= 0x0800) 143 #ifndef _WTL_KEEP_WS_OVERLAPPEDWINDOW 144 #ifdef WS_OVERLAPPEDWINDOW 145 #undef WS_OVERLAPPEDWINDOW 146 #define WS_OVERLAPPEDWINDOW 0 147 #endif // WS_OVERLAPPEDWINDOW 148 #endif // !_WTL_KEEP_WS_OVERLAPPEDWINDOW 154 #ifndef WM_WINDOWPOSCHANGING 155 #define WM_WINDOWPOSCHANGING 0 156 #endif // !WM_WINDOWPOSCHANGING 158 #define FreeResource(x) 159 #define UnlockResource(x) 163 inline HRESULT CComModule::RegisterClassObjects(DWORD , DWORD ) throw()
164 {
return E_NOTIMPL; }
165 inline HRESULT CComModule::RevokeClassObjects() throw()
166 {
return E_NOTIMPL; }
170 #define lstrlenW (int)ATL::lstrlenW 173 inline int WINAPI lstrlenA(LPCSTR lpszString)
174 {
return ATL::lstrlenA(lpszString); }
178 #define lstrcpyn ATL::lstrcpynW 181 #ifndef SetWindowLongPtrW 182 inline LONG_PTR tmp_SetWindowLongPtrW( HWND hWnd,
int nIndex, LONG_PTR dwNewLong )
184 return( ::SetWindowLongW( hWnd, nIndex, LONG( dwNewLong ) ) );
186 #define SetWindowLongPtrW tmp_SetWindowLongPtrW 189 #ifndef GetWindowLongPtrW 190 inline LONG_PTR tmp_GetWindowLongPtrW( HWND hWnd,
int nIndex )
192 return( ::GetWindowLongW( hWnd, nIndex ) );
194 #define GetWindowLongPtrW tmp_GetWindowLongPtrW 198 #define LongToPtr(x) ((void*)x) 202 #define PtrToInt( p ) ((INT)(INT_PTR) (p) ) 205 #else // !(_ATL_VER >= 0x0800) 209 #define lstrlenW (int)::wcslen 212 #define lstrlenA (int)strlen 215 inline LPTSTR lstrcpyn(LPTSTR lpstrDest, LPCTSTR lpstrSrc,
int nLength)
217 if(lpstrDest == NULL || lpstrSrc == NULL || nLength <= 0)
219 int nLen = min(lstrlen(lpstrSrc), nLength - 1);
220 LPTSTR lpstrRet = (LPTSTR)memcpy(lpstrDest, lpstrSrc, nLen *
sizeof(TCHAR));
227 inline LPWSTR lstrcpynW(LPWSTR lpstrDest, LPCWSTR lpstrSrc,
int nLength)
229 return lstrcpyn(lpstrDest, lpstrSrc, nLength);
234 inline LPSTR lstrcpynA(LPSTR lpstrDest, LPCSTR lpstrSrc,
int nLength)
236 if(lpstrDest == NULL || lpstrSrc == NULL || nLength <= 0)
238 int nLen = min(lstrlenA(lpstrSrc), nLength - 1);
239 LPSTR lpstrRet = (LPSTR)memcpy(lpstrDest, lpstrSrc, nLen *
sizeof(
char));
245 #ifdef TrackPopupMenu 246 #undef TrackPopupMenu 247 #endif // TrackPopupMenu 249 #define DECLARE_WND_CLASS_EX(WndClassName, style, bkgnd) \ 250 static CWndClassInfo& GetWndClassInfo() \ 252 static CWndClassInfo wc = \ 254 { style, StartWindowProc, \ 255 0, 0, NULL, NULL, NULL, (HBRUSH)(bkgnd + 1), NULL, WndClassName }, \ 256 NULL, NULL, IDC_ARROW, TRUE, 0, _T("") \ 262 #define _MAX_FNAME _MAX_PATH 265 #if (_WIN32_WCE < 400) 266 #define MAKEINTATOM(i) (LPTSTR)((ULONG_PTR)((WORD)(i))) 267 #endif // (_WIN32_WCE < 400) 269 #if (_WIN32_WCE < 410) 270 #define WHEEL_PAGESCROLL (UINT_MAX) 271 #define WHEEL_DELTA 120 272 #endif // (_WIN32_WCE < 410) 288 #define VARCMP_NULL 3 291 #ifndef RDW_ALLCHILDREN 292 #define RDW_ALLCHILDREN 0 295 #endif // !(_ATL_VER >= 0x0800) 303 #ifndef _ATL_NO_OLD_HEADERS_WIN64 304 #if !defined(_WIN64) && (_ATL_VER < 0x0700) 306 #ifndef PSM_INSERTPAGE 307 #define PSM_INSERTPAGE (WM_USER + 119) 308 #endif // !PSM_INSERTPAGE 310 #ifndef GetClassLongPtr 311 #define GetClassLongPtrA GetClassLongA 312 #define GetClassLongPtrW GetClassLongW 314 #define GetClassLongPtr GetClassLongPtrW 316 #define GetClassLongPtr GetClassLongPtrA 318 #endif // !GetClassLongPtr 321 #define GCLP_HICONSM (-34) 322 #endif // !GCLP_HICONSM 324 #ifndef GetWindowLongPtr 325 #define GetWindowLongPtrA GetWindowLongA 326 #define GetWindowLongPtrW GetWindowLongW 328 #define GetWindowLongPtr GetWindowLongPtrW 330 #define GetWindowLongPtr GetWindowLongPtrA 332 #endif // !GetWindowLongPtr 334 #ifndef SetWindowLongPtr 335 #define SetWindowLongPtrA SetWindowLongA 336 #define SetWindowLongPtrW SetWindowLongW 338 #define SetWindowLongPtr SetWindowLongPtrW 340 #define SetWindowLongPtr SetWindowLongPtrA 342 #endif // !SetWindowLongPtr 345 #define GWLP_WNDPROC (-4) 347 #ifndef GWLP_HINSTANCE 348 #define GWLP_HINSTANCE (-6) 350 #ifndef GWLP_HWNDPARENT 351 #define GWLP_HWNDPARENT (-8) 353 #ifndef GWLP_USERDATA 354 #define GWLP_USERDATA (-21) 357 #define GWLP_ID (-12) 360 #ifndef DWLP_MSGRESULT 361 #define DWLP_MSGRESULT 0 364 typedef long LONG_PTR;
365 typedef unsigned long ULONG_PTR;
366 typedef ULONG_PTR DWORD_PTR;
368 #ifndef HandleToUlong 369 #define HandleToUlong( h ) ((ULONG)(ULONG_PTR)(h) ) 372 #define HandleToLong( h ) ((LONG)(LONG_PTR) (h) ) 375 #define LongToHandle( h) ((HANDLE)(LONG_PTR) (h)) 378 #define PtrToUlong( p ) ((ULONG)(ULONG_PTR) (p) ) 381 #define PtrToLong( p ) ((LONG)(LONG_PTR) (p) ) 384 #define PtrToUint( p ) ((UINT)(UINT_PTR) (p) ) 387 #define PtrToInt( p ) ((INT)(INT_PTR) (p) ) 390 #define PtrToUshort( p ) ((unsigned short)(ULONG_PTR)(p) ) 393 #define PtrToShort( p ) ((short)(LONG_PTR)(p) ) 396 #define IntToPtr( i ) ((VOID *)(INT_PTR)((int)i)) 399 #define UIntToPtr( ui ) ((VOID *)(UINT_PTR)((unsigned int)ui)) 402 #define LongToPtr( l ) ((VOID *)(LONG_PTR)((long)l)) 405 #define ULongToPtr( ul ) ((VOID *)(ULONG_PTR)((unsigned long)ul)) 408 #endif // !defined(_WIN64) && (_ATL_VER < 0x0700) 409 #endif // !_ATL_NO_OLD_HEADERS_WIN64 416 #define _TRUNCATE ((size_t)-1) 419 #ifndef _ERRCODE_DEFINED 420 #define _ERRCODE_DEFINED 424 #ifndef _SECURECRT_ERRCODE_VALUES_DEFINED 425 #define _SECURECRT_ERRCODE_VALUES_DEFINED 431 #define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0])) 439 #ifndef IS_INTRESOURCE 440 #define IS_INTRESOURCE(_r) (((ULONG_PTR)(_r) >> 16) == 0) 441 #endif // IS_INTRESOURCE 445 #undef SubclassWindow 446 #endif // _INC_WINDOWSX 450 #define GET_X_LPARAM(lParam) ((int)(short)LOWORD(lParam)) 453 #define GET_Y_LPARAM(lParam) ((int)(short)HIWORD(lParam)) 457 #if (_MSC_VER >= 1300) && defined(_MANAGED) 458 __if_not_exists(_IMAGELIST::_IMAGELIST) {
struct _IMAGELIST { }; }
459 __if_not_exists(_TREEITEM::_TREEITEM) {
struct _TREEITEM { }; }
460 __if_not_exists(_PSP::_PSP) {
struct _PSP { }; }
464 #if (_ATL_VER < 0x0700) 467 #define ATLVERIFY(expr) ATLASSERT(expr) 469 #define ATLVERIFY(expr) (expr) 472 #endif // (_ATL_VER < 0x0700) 475 #if (((_ATL_VER < 0x0700) && defined(_ATL_DLL)) || (_ATL_VER >= 0x0B00)) && !defined(_WIN32_WCE) 476 namespace ATL { HRESULT AtlGetCommCtrlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor); };
479 #ifndef WM_MOUSEHWHEEL 480 #define WM_MOUSEHWHEEL 0x020E 487 #if (_ATL_VER >= 0x0700) 488 DECLARE_TRACE_CATEGORY(atlTraceUI);
490 __declspec(selectany)
ATL::CTraceCategory atlTraceUI(_T("atlTraceUI"));
492 #else // !(_ATL_VER >= 0x0700) 495 atlTraceUI = 0x10000000
497 #endif // !(_ATL_VER >= 0x0700) 500 inline bool AtlIsOldWindows()
502 OSVERSIONINFO ovi = {
sizeof(OSVERSIONINFO) };
503 BOOL bRet = ::GetVersionEx(&ovi);
504 return (!bRet || !((ovi.dwMajorVersion >= 5) || (ovi.dwMajorVersion == 4 && ovi.dwMinorVersion >= 90)));
508 inline HFONT AtlGetDefaultGuiFont()
511 return (HFONT)::GetStockObject(DEFAULT_GUI_FONT);
513 return (HFONT)::GetStockObject(SYSTEM_FONT);
519 inline HFONT AtlCreateControlFont()
523 ATLVERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT,
sizeof(LOGFONT), &lf, 0) != FALSE);
524 HFONT hFont = ::CreateFontIndirect(&lf);
525 ATLASSERT(hFont != NULL);
528 return (HFONT)::GetStockObject(SYSTEM_FONT);
534 inline HFONT AtlCreateBoldFont(HFONT hFont = NULL)
539 ATLVERIFY(::SystemParametersInfo(SPI_GETICONTITLELOGFONT,
sizeof(LOGFONT), &lf, 0) != FALSE);
541 ATLVERIFY(::GetObject(hFont,
sizeof(LOGFONT), &lf) ==
sizeof(LOGFONT));
544 hFont = (HFONT)::GetStockObject(SYSTEM_FONT);
545 ATLVERIFY(::GetObject(hFont,
sizeof(LOGFONT), &lf) ==
sizeof(LOGFONT));
547 lf.lfWeight = FW_BOLD;
548 HFONT hFontBold = ::CreateFontIndirect(&lf);
549 ATLASSERT(hFontBold != NULL);
554 inline BOOL AtlInitCommonControls(DWORD dwFlags)
556 INITCOMMONCONTROLSEX iccx = {
sizeof(INITCOMMONCONTROLSEX), dwFlags };
557 BOOL bRet = ::InitCommonControlsEx(&iccx);
567 #if defined(_WIN32_WCE) && !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) 568 #define _WTL_NO_RUNTIME_STRUCT_SIZE 571 #ifndef _WTL_NO_RUNTIME_STRUCT_SIZE 573 #ifndef _SIZEOF_STRUCT 574 #define _SIZEOF_STRUCT(structname, member) (((int)((LPBYTE)(&((structname*)0)->member) - ((LPBYTE)((structname*)0)))) + sizeof(((structname*)0)->member)) 577 #if (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE) 578 #define REBARBANDINFO_V6_SIZE _SIZEOF_STRUCT(REBARBANDINFO, cxHeader) 579 #endif // (_WIN32_WINNT >= 0x0600) && !defined(REBARBANDINFO_V6_SIZE) 581 #if (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE) 582 #define LVGROUP_V5_SIZE _SIZEOF_STRUCT(LVGROUP, uAlign) 583 #endif // (_WIN32_WINNT >= 0x0600) && !defined(LVGROUP_V5_SIZE) 585 #if (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE) 586 #define LVTILEINFO_V5_SIZE _SIZEOF_STRUCT(LVTILEINFO, puColumns) 587 #endif // (_WIN32_WINNT >= 0x0600) && !defined(LVTILEINFO_V5_SIZE) 589 #if defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE) 590 #define MCHITTESTINFO_V1_SIZE _SIZEOF_STRUCT(MCHITTESTINFO, st) 591 #endif // defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) && !defined(MCHITTESTINFO_V1_SIZE) 593 #if !defined(_WIN32_WCE) && (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE) 594 #define NONCLIENTMETRICS_V1_SIZE _SIZEOF_STRUCT(NONCLIENTMETRICS, lfMessageFont) 595 #endif // !defined(_WIN32_WCE) && (WINVER >= 0x0600) && !defined(NONCLIENTMETRICS_V1_SIZE) 597 #endif // !_WTL_NO_RUNTIME_STRUCT_SIZE 599 namespace RunTimeHelper
602 inline bool IsCommCtrl6()
604 DWORD dwMajor = 0, dwMinor = 0;
605 HRESULT hRet = ATL::AtlGetCommCtrlVersion(&dwMajor, &dwMinor);
606 return (SUCCEEDED(hRet) && (dwMajor >= 6));
609 inline bool IsVista()
611 OSVERSIONINFO ovi = {
sizeof(OSVERSIONINFO) };
612 BOOL bRet = ::GetVersionEx(&ovi);
613 return ((bRet != FALSE) && (ovi.dwMajorVersion >= 6));
616 inline bool IsThemeAvailable()
622 HMODULE hThemeDLL = ::LoadLibrary(_T(
"uxtheme.dll"));
623 if(hThemeDLL != NULL)
625 typedef BOOL (STDAPICALLTYPE *PFN_IsThemeActive)();
626 PFN_IsThemeActive pfnIsThemeActive = (PFN_IsThemeActive)::GetProcAddress(hThemeDLL,
"IsThemeActive");
627 ATLASSERT(pfnIsThemeActive != NULL);
628 bRet = (pfnIsThemeActive != NULL) && (pfnIsThemeActive() != FALSE);
631 typedef BOOL (STDAPICALLTYPE *PFN_IsAppThemed)();
632 PFN_IsAppThemed pfnIsAppThemed = (PFN_IsAppThemed)::GetProcAddress(hThemeDLL,
"IsAppThemed");
633 ATLASSERT(pfnIsAppThemed != NULL);
634 bRet = (pfnIsAppThemed != NULL) && (pfnIsAppThemed() != FALSE);
637 ::FreeLibrary(hThemeDLL);
646 OSVERSIONINFO ovi = {
sizeof(OSVERSIONINFO) };
647 BOOL bRet = ::GetVersionEx(&ovi);
648 return ((bRet != FALSE) && (ovi.dwMajorVersion == 6) && (ovi.dwMinorVersion >= 1));
651 inline bool IsRibbonUIAvailable()
653 static INT iRibbonUI = -1;
655 #if defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7) 658 HMODULE hRibbonDLL = ::LoadLibrary(_T(
"propsys.dll"));
659 if (hRibbonDLL != NULL)
661 const GUID CLSID_UIRibbonFramework = { 0x926749fa, 0x2615, 0x4987, { 0x88, 0x45, 0xc3, 0x3e, 0x65, 0xf2, 0xb9, 0x57 } };
664 ATL::CComPtr<IUnknown> pIUIFramework;
665 iRibbonUI = SUCCEEDED(pIUIFramework.CoCreateInstance(CLSID_UIRibbonFramework)) ? 1 : 0;
667 ::FreeLibrary(hRibbonDLL);
674 #endif // defined(NTDDI_WIN7) && (NTDDI_VERSION >= NTDDI_WIN7) 676 return (iRibbonUI == 1);
679 #endif // !_WIN32_WCE 681 inline int SizeOf_REBARBANDINFO()
683 int nSize =
sizeof(REBARBANDINFO);
684 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600) 685 if(!(IsVista() && IsCommCtrl6()))
686 nSize = REBARBANDINFO_V6_SIZE;
687 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600) 691 #if (_WIN32_WINNT >= 0x501) 692 inline int SizeOf_LVGROUP()
694 int nSize =
sizeof(LVGROUP);
695 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600) 697 nSize = LVGROUP_V5_SIZE;
698 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600) 702 inline int SizeOf_LVTILEINFO()
704 int nSize =
sizeof(LVTILEINFO);
705 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600) 707 nSize = LVTILEINFO_V5_SIZE;
708 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (_WIN32_WINNT >= 0x0600) 711 #endif // (_WIN32_WINNT >= 0x501) 713 inline int SizeOf_MCHITTESTINFO()
715 int nSize =
sizeof(MCHITTESTINFO);
716 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) 717 if(!(IsVista() && IsCommCtrl6()))
718 nSize = MCHITTESTINFO_V1_SIZE;
719 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && defined(NTDDI_VERSION) && (NTDDI_VERSION >= NTDDI_LONGHORN) 724 inline int SizeOf_NONCLIENTMETRICS()
726 int nSize =
sizeof(NONCLIENTMETRICS);
727 #if !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600) 729 nSize = NONCLIENTMETRICS_V1_SIZE;
730 #endif // !defined(_WTL_NO_RUNTIME_STRUCT_SIZE) && (WINVER >= 0x0600) 733 #endif // !_WIN32_WCE 740 namespace ModuleHelper
742 inline HINSTANCE GetModuleInstance()
744 #if (_ATL_VER >= 0x0700) 745 return ATL::_AtlBaseModule.GetModuleInstance();
746 #else // !(_ATL_VER >= 0x0700) 747 return ATL::_pModule->GetModuleInstance();
748 #endif // !(_ATL_VER >= 0x0700) 751 inline HINSTANCE GetResourceInstance()
753 #if (_ATL_VER >= 0x0700) 754 return ATL::_AtlBaseModule.GetResourceInstance();
755 #else // !(_ATL_VER >= 0x0700) 756 return ATL::_pModule->GetResourceInstance();
757 #endif // !(_ATL_VER >= 0x0700) 760 inline void AddCreateWndData(ATL::_AtlCreateWndData* pData,
void* pObject)
762 #if (_ATL_VER >= 0x0700) 763 ATL::_AtlWinModule.AddCreateWndData(pData, pObject);
764 #else // !(_ATL_VER >= 0x0700) 765 ATL::_pModule->AddCreateWndData(pData, pObject);
766 #endif // !(_ATL_VER >= 0x0700) 769 inline void* ExtractCreateWndData()
771 #if (_ATL_VER >= 0x0700) 772 return ATL::_AtlWinModule.ExtractCreateWndData();
773 #else // !(_ATL_VER >= 0x0700) 774 return ATL::_pModule->ExtractCreateWndData();
775 #endif // !(_ATL_VER >= 0x0700) 783 namespace SecureHelper
785 inline void strcpyA_x(
char* lpstrDest,
size_t cchDest,
const char* lpstrSrc)
788 ATL::Checked::strcpy_s(lpstrDest, cchDest, lpstrSrc);
790 if(cchDest > (
size_t)lstrlenA(lpstrSrc))
791 ATLVERIFY(lstrcpyA(lpstrDest, lpstrSrc) != NULL);
797 inline void strcpyW_x(
wchar_t* lpstrDest,
size_t cchDest,
const wchar_t* lpstrSrc)
800 ATL::Checked::wcscpy_s(lpstrDest, cchDest, lpstrSrc);
802 if(cchDest > (
size_t)lstrlenW(lpstrSrc))
803 ATLVERIFY(lstrcpyW(lpstrDest, lpstrSrc) != NULL);
809 inline void strcpy_x(LPTSTR lpstrDest,
size_t cchDest, LPCTSTR lpstrSrc)
812 strcpyW_x(lpstrDest, cchDest, lpstrSrc);
814 strcpyA_x(lpstrDest, cchDest, lpstrSrc);
818 inline errno_t strncpyA_x(
char* lpstrDest,
size_t cchDest,
const char* lpstrSrc,
size_t cchCount)
821 return ATL::Checked::strncpy_s(lpstrDest, cchDest, lpstrSrc, cchCount);
824 if(lpstrDest == NULL || cchDest == 0 || lpstrSrc == NULL)
828 else if(cchCount == _TRUNCATE)
830 cchCount = min(cchDest - 1,
size_t(lstrlenA(lpstrSrc)));
833 else if(cchDest <= cchCount)
838 if(nRet == 0 || nRet == STRUNCATE)
839 nRet = (lstrcpynA(lpstrDest, lpstrSrc, (
int)cchCount + 1) != NULL) ? nRet : EINVAL;
840 ATLASSERT(nRet == 0 || nRet == STRUNCATE);
845 inline errno_t strncpyW_x(
wchar_t* lpstrDest,
size_t cchDest,
const wchar_t* lpstrSrc,
size_t cchCount)
848 return ATL::Checked::wcsncpy_s(lpstrDest, cchDest, lpstrSrc, cchCount);
851 if(lpstrDest == NULL || cchDest == 0 || lpstrSrc == NULL)
855 else if(cchCount == _TRUNCATE)
857 cchCount = min(cchDest - 1,
size_t(lstrlenW(lpstrSrc)));
860 else if(cchDest <= cchCount)
865 if(nRet == 0 || nRet == STRUNCATE)
866 nRet = (lstrcpynW(lpstrDest, lpstrSrc, (
int)cchCount + 1) != NULL) ? nRet : EINVAL;
867 ATLASSERT(nRet == 0 || nRet == STRUNCATE);
872 inline errno_t strncpy_x(LPTSTR lpstrDest,
size_t cchDest, LPCTSTR lpstrSrc,
size_t cchCount)
875 return strncpyW_x(lpstrDest, cchDest, lpstrSrc, cchCount);
877 return strncpyA_x(lpstrDest, cchDest, lpstrSrc, cchCount);
881 inline void strcatA_x(
char* lpstrDest,
size_t cchDest,
const char* lpstrSrc)
884 ATL::Checked::strcat_s(lpstrDest, cchDest, lpstrSrc);
886 if(cchDest > (
size_t)lstrlenA(lpstrSrc))
887 ATLVERIFY(lstrcatA(lpstrDest, lpstrSrc) != NULL);
893 inline void strcatW_x(
wchar_t* lpstrDest,
size_t cchDest,
const wchar_t* lpstrSrc)
896 ATL::Checked::wcscat_s(lpstrDest, cchDest, lpstrSrc);
898 if(cchDest > (
size_t)lstrlenW(lpstrSrc))
899 ATLVERIFY(lstrcatW(lpstrDest, lpstrSrc) != NULL);
905 inline void strcat_x(LPTSTR lpstrDest,
size_t cchDest, LPCTSTR lpstrSrc)
908 strcatW_x(lpstrDest, cchDest, lpstrSrc);
910 strcatA_x(lpstrDest, cchDest, lpstrSrc);
914 inline void memcpy_x(
void* pDest,
size_t cbDest,
const void* pSrc,
size_t cbSrc)
917 ATL::Checked::memcpy_s(pDest, cbDest, pSrc, cbSrc);
920 memcpy(pDest, pSrc, cbSrc);
926 inline void memmove_x(
void* pDest,
size_t cbDest,
const void* pSrc,
size_t cbSrc)
929 ATL::Checked::memmove_s(pDest, cbDest, pSrc, cbSrc);
932 memmove(pDest, pSrc, cbSrc);
938 inline int vsprintf_x(LPTSTR lpstrBuff,
size_t cchBuff, LPCTSTR lpstrFormat, va_list args)
940 #if _SECURE_ATL && !defined(_ATL_MIN_CRT) && !defined(_WIN32_WCE) 941 return _vstprintf_s(lpstrBuff, cchBuff, lpstrFormat, args);
944 #pragma warning(disable: 4996) 945 return _vstprintf(lpstrBuff, lpstrFormat, args);
946 #pragma warning(default: 4996) 950 inline int wvsprintf_x(LPTSTR lpstrBuff,
size_t cchBuff, LPCTSTR lpstrFormat, va_list args)
952 #if _SECURE_ATL && !defined(_ATL_MIN_CRT) && !defined(_WIN32_WCE) 953 return _vstprintf_s(lpstrBuff, cchBuff, lpstrFormat, args);
956 return ::wvsprintf(lpstrBuff, lpstrFormat, args);
960 inline int sprintf_x(LPTSTR lpstrBuff,
size_t cchBuff, LPCTSTR lpstrFormat, ...)
963 va_start(args, lpstrFormat);
964 int nRes = vsprintf_x(lpstrBuff, cchBuff, lpstrFormat, args);
969 inline int wsprintf_x(LPTSTR lpstrBuff,
size_t cchBuff, LPCTSTR lpstrFormat, ...)
972 va_start(args, lpstrFormat);
973 int nRes = wvsprintf_x(lpstrBuff, cchBuff, lpstrFormat, args);
983 namespace MinCrtHelper
985 inline int _isspace(TCHAR ch)
988 return _istspace(ch);
989 #else // _ATL_MIN_CRT 991 ::GetStringTypeEx(::GetThreadLocale(), CT_CTYPE1, &ch, 1, &type);
992 return (type & C1_SPACE) == C1_SPACE;
993 #endif // _ATL_MIN_CRT 996 inline int _isdigit(TCHAR ch)
999 return _istdigit(ch);
1000 #else // _ATL_MIN_CRT 1002 ::GetStringTypeEx(::GetThreadLocale(), CT_CTYPE1, &ch, 1, &type);
1003 return (type & C1_DIGIT) == C1_DIGIT;
1004 #endif // _ATL_MIN_CRT 1007 inline int _atoi(LPCTSTR str)
1009 #ifndef _ATL_MIN_CRT 1011 #else // _ATL_MIN_CRT 1012 while(_isspace(*str) != 0)
1017 if(ch == _T(
'-') || ch == _T(
'+'))
1021 while(_isdigit(ch) != 0)
1023 total = 10 * total + (ch -
'0');
1027 return (sign ==
'-') ? -total : total;
1028 #endif // _ATL_MIN_CRT 1031 inline LPCTSTR _strrchr(LPCTSTR str, TCHAR ch)
1033 #ifndef _ATL_MIN_CRT 1034 return _tcsrchr(str, ch);
1035 #else // _ATL_MIN_CRT 1036 LPCTSTR lpsz = NULL;
1041 str = ::CharNext(str);
1044 #endif // _ATL_MIN_CRT 1047 inline LPTSTR _strrchr(LPTSTR str, TCHAR ch)
1049 #ifndef _ATL_MIN_CRT 1050 return _tcsrchr(str, ch);
1051 #else // _ATL_MIN_CRT 1057 str = ::CharNext(str);
1060 #endif // _ATL_MIN_CRT 1071 virtual BOOL PreTranslateMessage(MSG* pMsg) = 0;
1081 virtual BOOL OnIdle() = 0;
1084 #ifndef _ATL_NO_OLD_NAMES 1087 #define DoUpdate OnIdle 1088 #endif // !_ATL_NO_OLD_NAMES 1097 ATL::CSimpleArray<CMessageFilter*> m_aMsgFilter;
1098 ATL::CSimpleArray<CIdleHandler*> m_aIdleHandler;
1104 return m_aMsgFilter.Add(pMessageFilter);
1109 return m_aMsgFilter.Remove(pMessageFilter);
1115 return m_aIdleHandler.Add(pIdleHandler);
1120 return m_aIdleHandler.Remove(pIdleHandler);
1123 #ifndef _ATL_NO_OLD_NAMES 1127 ATLTRACE2(atlTraceUI, 0, _T(
"CUpdateUIObject and AddUpdateUI are deprecated. Please change your code to use CIdleHandler and OnIdle\n"));
1128 return AddIdleHandler(pIdleHandler);
1133 ATLTRACE2(atlTraceUI, 0, _T(
"CUpdateUIObject and RemoveUpdateUI are deprecated. Please change your code to use CIdleHandler and OnIdle\n"));
1134 return RemoveIdleHandler(pIdleHandler);
1136 #endif // !_ATL_NO_OLD_NAMES 1141 BOOL bDoIdle = TRUE;
1147 while(bDoIdle && !::PeekMessage(&m_msg, NULL, 0, 0, PM_NOREMOVE))
1149 if(!OnIdle(nIdleCount++))
1153 bRet = ::GetMessage(&m_msg, NULL, 0, 0);
1157 ATLTRACE2(atlTraceUI, 0, _T(
"::GetMessage returned -1 (error)\n"));
1162 ATLTRACE2(atlTraceUI, 0, _T(
"CMessageLoop::Run - exiting\n"));
1166 if(!PreTranslateMessage(&m_msg))
1168 ::TranslateMessage(&m_msg);
1169 ::DispatchMessage(&m_msg);
1172 if(IsIdleMessage(&m_msg))
1179 return (
int)m_msg.wParam;
1182 static BOOL IsIdleMessage(MSG* pMsg)
1185 switch(pMsg->message)
1189 case WM_NCMOUSEMOVE:
1190 #endif // !_WIN32_WCE 1201 virtual BOOL PreTranslateMessage(MSG* pMsg)
1204 for(
int i = m_aMsgFilter.GetSize() - 1; i >= 0; i--)
1207 if(pMessageFilter != NULL && pMessageFilter->PreTranslateMessage(pMsg))
1214 virtual BOOL OnIdle(
int )
1216 for(
int i = 0; i < m_aIdleHandler.GetSize(); i++)
1219 if(pIdleHandler != NULL)
1220 pIdleHandler->OnIdle();
1234 #if (_ATL_VER >= 0x0700) 1235 ATL::CComCritSecLock<ATL::CComCriticalSection> m_cslock;
1239 #endif // (_ATL_VER >= 0x0700) 1243 #if (_ATL_VER >= 0x0700) 1244 return m_cslock.Lock();
1245 #else // !(_ATL_VER >= 0x0700) 1246 ::EnterCriticalSection(&ATL::_pModule->m_csStaticDataInit);
1248 #endif // !(_ATL_VER >= 0x0700) 1253 #if (_ATL_VER >= 0x0700) 1255 #else // !(_ATL_VER >= 0x0700) 1256 ::LeaveCriticalSection(&ATL::_pModule->m_csStaticDataInit);
1257 #endif // !(_ATL_VER >= 0x0700) 1265 #if (_ATL_VER >= 0x0700) 1266 ATL::CComCritSecLock<ATL::CComCriticalSection> m_cslock;
1270 #endif // (_ATL_VER >= 0x0700) 1274 #if (_ATL_VER >= 0x0700) 1275 return m_cslock.Lock();
1276 #else // !(_ATL_VER >= 0x0700) 1277 ::EnterCriticalSection(&ATL::_pModule->m_csWindowCreate);
1279 #endif // !(_ATL_VER >= 0x0700) 1284 #if (_ATL_VER >= 0x0700) 1286 #else // !(_ATL_VER >= 0x0700) 1287 ::LeaveCriticalSection(&ATL::_pModule->m_csWindowCreate);
1288 #endif // !(_ATL_VER >= 0x0700) 1296 #ifndef _WTL_STACK_ALLOC_THRESHOLD 1297 #define _WTL_STACK_ALLOC_THRESHOLD 512 1300 #if (_ATL_VER >= 0x0700) 1302 using ATL::CTempBuffer;
1304 #else // !(_ATL_VER >= 0x0700) 1308 #define SIZE_MAX _UI64_MAX 1310 #define SIZE_MAX UINT_MAX 1314 #pragma warning(disable: 4284) // warning for operator -> 1316 template<
typename T,
int t_nFixedBytes = 128>
1326 Allocate(nElements);
1331 if(m_p != reinterpret_cast<T*>(m_abFixedBuffer))
1340 T* operator ->()
const 1342 ATLASSERT(m_p != NULL);
1346 T* Allocate(
size_t nElements)
1348 ATLASSERT(nElements <= (SIZE_MAX /
sizeof(T)));
1349 return AllocateBytes(nElements *
sizeof(T));
1352 T* AllocateBytes(
size_t nBytes)
1354 ATLASSERT(m_p == NULL);
1355 if(nBytes > t_nFixedBytes)
1356 m_p =
static_cast<T*
>(malloc(nBytes));
1358 m_p =
reinterpret_cast<T*
>(m_abFixedBuffer);
1365 BYTE m_abFixedBuffer[t_nFixedBytes];
1368 #pragma warning(default: 4284) 1370 #endif // !(_ATL_VER >= 0x0700) 1379 DWORD m_dwMainThreadID;
1380 ATL::CSimpleMap<DWORD, CMessageLoop*>* m_pMsgLoopMap;
1381 ATL::CSimpleArray<HWND>* m_pSettingChangeNotify;
1384 HRESULT Init(ATL::_ATL_OBJMAP_ENTRY* pObjMap, HINSTANCE hInstance,
const GUID* pLibID = NULL)
1386 HRESULT hRet = CComModule::Init(pObjMap, hInstance, pLibID);
1390 m_dwMainThreadID = ::GetCurrentThreadId();
1391 typedef ATL::CSimpleMap<DWORD, CMessageLoop*> _mapClass;
1392 m_pMsgLoopMap = NULL;
1393 ATLTRY(m_pMsgLoopMap =
new _mapClass);
1394 if(m_pMsgLoopMap == NULL)
1395 return E_OUTOFMEMORY;
1396 m_pSettingChangeNotify = NULL;
1403 TermSettingChangeNotify();
1404 delete m_pMsgLoopMap;
1412 if(FAILED(lock.Lock()))
1414 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::AddMessageLoop.\n"));
1419 ATLASSERT(pMsgLoop != NULL);
1420 ATLASSERT(m_pMsgLoopMap->Lookup(::GetCurrentThreadId()) == NULL);
1422 BOOL bRet = m_pMsgLoopMap->Add(::GetCurrentThreadId(), pMsgLoop);
1429 BOOL RemoveMessageLoop()
1432 if(FAILED(lock.Lock()))
1434 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::RemoveMessageLoop.\n"));
1439 BOOL bRet = m_pMsgLoopMap->Remove(::GetCurrentThreadId());
1446 CMessageLoop* GetMessageLoop(DWORD dwThreadID = ::GetCurrentThreadId())
const 1449 if(FAILED(lock.Lock()))
1451 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::GetMessageLoop.\n"));
1456 CMessageLoop* pLoop = m_pMsgLoopMap->Lookup(dwThreadID);
1465 BOOL InitSettingChangeNotify(DLGPROC pfnDlgProc = _SettingChangeDlgProc)
1468 if(FAILED(lock.Lock()))
1470 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::InitSettingChangeNotify.\n"));
1475 if(m_pSettingChangeNotify == NULL)
1477 typedef ATL::CSimpleArray<HWND> _notifyClass;
1478 ATLTRY(m_pSettingChangeNotify =
new _notifyClass);
1479 ATLASSERT(m_pSettingChangeNotify != NULL);
1482 BOOL bRet = (m_pSettingChangeNotify != NULL);
1483 if(bRet && m_pSettingChangeNotify->GetSize() == 0)
1487 HWND hNtfWnd = ::CreateDialogIndirect(GetModuleInstance(), &templ, NULL, pfnDlgProc);
1488 ATLASSERT(::IsWindow(hNtfWnd));
1489 if(::IsWindow(hNtfWnd))
1493 ::SetWindowLongPtr(hNtfWnd, GWLP_USERDATA, (LONG_PTR)
this);
1495 ::SetWindowLongPtr(hNtfWnd, GWLP_USERDATA, PtrToLong(
this));
1497 bRet = m_pSettingChangeNotify->Add(hNtfWnd);
1510 void TermSettingChangeNotify()
1513 if(FAILED(lock.Lock()))
1515 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::TermSettingChangeNotify.\n"));
1520 if(m_pSettingChangeNotify != NULL && m_pSettingChangeNotify->GetSize() > 0)
1521 ::DestroyWindow((*m_pSettingChangeNotify)[0]);
1522 delete m_pSettingChangeNotify;
1523 m_pSettingChangeNotify = NULL;
1528 BOOL AddSettingChangeNotify(HWND hWnd)
1531 if(FAILED(lock.Lock()))
1533 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::AddSettingChangeNotify.\n"));
1538 ATLASSERT(::IsWindow(hWnd));
1540 if(InitSettingChangeNotify() != FALSE)
1541 bRet = m_pSettingChangeNotify->Add(hWnd);
1548 BOOL RemoveSettingChangeNotify(HWND hWnd)
1551 if(FAILED(lock.Lock()))
1553 ATLTRACE2(atlTraceUI, 0, _T(
"ERROR : Unable to lock critical section in CAppModule::RemoveSettingChangeNotify.\n"));
1559 if(m_pSettingChangeNotify != NULL)
1560 bRet = m_pSettingChangeNotify->Remove(hWnd);
1575 WORD wMenu, wClass, wTitle;
1579 static INT_PTR CALLBACK _SettingChangeDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1581 static BOOL CALLBACK _SettingChangeDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
1584 if(uMsg == WM_SETTINGCHANGE)
1592 ATLASSERT(pModule != NULL);
1593 ATLASSERT(pModule->m_pSettingChangeNotify != NULL);
1594 const UINT uTimeout = 1500;
1595 for(
int i = 1; i < pModule->m_pSettingChangeNotify->GetSize(); i++)
1597 #if !defined(_WIN32_WCE) 1598 ::SendMessageTimeout((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam, SMTO_ABORTIFHUNG, uTimeout, NULL);
1599 #elif(_WIN32_WCE >= 400) // CE specific 1600 ::SendMessageTimeout((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam, SMTO_NORMAL, uTimeout, NULL);
1601 #else // _WIN32_WCE < 400 specific 1603 ::SendMessage((*pModule->m_pSettingChangeNotify)[i], uMsg, wParam, lParam);
1619 HANDLE m_hEventShutdown;
1625 HRESULT Init(ATL::_ATL_OBJMAP_ENTRY* pObjMap, HINSTANCE hInstance,
const GUID* pLibID = NULL)
1629 return CAppModule::Init(pObjMap, hInstance, pLibID);
1634 if(m_hEventShutdown != NULL && ::CloseHandle(m_hEventShutdown))
1635 m_hEventShutdown = NULL;
1642 LONG lRet = CComModule::Unlock();
1646 ::SetEvent(m_hEventShutdown);
1651 void MonitorShutdown()
1655 ::WaitForSingleObject(m_hEventShutdown, INFINITE);
1659 m_bActivity =
false;
1660 dwWait = ::WaitForSingleObject(m_hEventShutdown, m_dwTimeOut);
1662 while(dwWait == WAIT_OBJECT_0);
1664 if(!m_bActivity && m_nLockCnt == 0)
1666 #if ((_WIN32_WINNT >= 0x0400 ) || defined(_WIN32_DCOM)) && defined(_ATL_FREE_THREADED) && !defined(_WIN32_WCE) 1667 ::CoSuspendClassObjects();
1668 if(!m_bActivity && m_nLockCnt == 0)
1675 if(::CloseHandle(m_hEventShutdown))
1676 m_hEventShutdown = NULL;
1677 ::PostThreadMessage(m_dwMainThreadID, WM_QUIT, 0, 0);
1682 m_hEventShutdown = ::CreateEvent(NULL,
false,
false, NULL);
1683 if(m_hEventShutdown == NULL)
1685 DWORD dwThreadID = 0;
1686 #if !defined(_ATL_MIN_CRT) && defined(_MT) && !defined(_WIN32_WCE) 1687 HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, (UINT (WINAPI*)(
void*))MonitorProc,
this, 0, (UINT*)&dwThreadID);
1689 HANDLE hThread = ::CreateThread(NULL, 0, MonitorProc,
this, 0, &dwThreadID);
1691 bool bRet = (hThread != NULL);
1693 ::CloseHandle(hThread);
1697 static DWORD WINAPI MonitorProc(
void* pv)
1700 p->MonitorShutdown();
1704 #if (_ATL_VER < 0x0700) 1706 static LPCTSTR FindOneOf(LPCTSTR p1, LPCTSTR p2)
1708 while(p1 != NULL && *p1 != NULL)
1711 while(p != NULL && *p != NULL)
1714 return ::CharNext(p1);
1717 p1 = ::CharNext(p1);
1721 #endif // (_ATL_VER < 0x0700) 1728 #if (_ATL_VER < 0x0700) 1741 Attach(key.Detach());
1747 Attach(key.Detach());
1752 LONG SetValue(LPCTSTR pszValueName, DWORD dwType,
const void* pValue, ULONG nBytes)
1754 ATLASSERT(m_hKey != NULL);
1755 return ::RegSetValueEx(m_hKey, pszValueName, NULL, dwType, static_cast<const BYTE*>(pValue), nBytes);
1758 LONG SetGUIDValue(LPCTSTR pszValueName, REFGUID guidValue)
1760 ATLASSERT(m_hKey != NULL);
1762 OLECHAR szGUID[64] = { 0 };
1763 ::StringFromGUID2(guidValue, szGUID, 64);
1766 LPCTSTR lpstr = OLE2CT(szGUID);
1769 return E_OUTOFMEMORY;
1771 return SetStringValue(pszValueName, lpstr);
1774 LONG SetBinaryValue(LPCTSTR pszValueName,
const void* pValue, ULONG nBytes)
1776 ATLASSERT(m_hKey != NULL);
1777 return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_BINARY, reinterpret_cast<const BYTE*>(pValue), nBytes);
1780 LONG SetDWORDValue(LPCTSTR pszValueName, DWORD dwValue)
1782 ATLASSERT(m_hKey != NULL);
1783 return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_DWORD, reinterpret_cast<const BYTE*>(&dwValue),
sizeof(DWORD));
1787 LONG SetQWORDValue(LPCTSTR pszValueName, ULONGLONG qwValue)
1789 ATLASSERT(m_hKey != NULL);
1790 return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_QWORD, reinterpret_cast<const BYTE*>(&qwValue),
sizeof(ULONGLONG));
1794 LONG SetStringValue(LPCTSTR pszValueName, LPCTSTR pszValue, DWORD dwType = REG_SZ)
1796 ATLASSERT(m_hKey != NULL);
1797 if(pszValue == NULL)
1800 return ERROR_INVALID_DATA;
1802 ATLASSERT((dwType == REG_SZ) || (dwType == REG_EXPAND_SZ));
1804 return ::RegSetValueEx(m_hKey, pszValueName, NULL, dwType, reinterpret_cast<const BYTE*>(pszValue), (lstrlen(pszValue) + 1) *
sizeof(TCHAR));
1807 LONG SetMultiStringValue(LPCTSTR pszValueName, LPCTSTR pszValue)
1809 ATLASSERT(m_hKey != NULL);
1810 if(pszValue == NULL)
1813 return ERROR_INVALID_DATA;
1818 LPCTSTR pszTemp = pszValue;
1821 nLength = lstrlen(pszTemp) + 1;
1823 nBytes += nLength *
sizeof(TCHAR);
1824 }
while (nLength != 1);
1826 return ::RegSetValueEx(m_hKey, pszValueName, NULL, REG_MULTI_SZ, reinterpret_cast<const BYTE*>(pszValue), nBytes);
1829 LONG QueryValue(LPCTSTR pszValueName, DWORD* pdwType,
void* pData, ULONG* pnBytes)
1831 ATLASSERT(m_hKey != NULL);
1832 return ::RegQueryValueEx(m_hKey, pszValueName, NULL, pdwType, static_cast<LPBYTE>(pData), pnBytes);
1835 LONG QueryGUIDValue(LPCTSTR pszValueName, GUID& guidValue)
1837 ATLASSERT(m_hKey != NULL);
1839 guidValue = GUID_NULL;
1841 TCHAR szGUID[64] = { 0 };
1843 LONG lRes = QueryStringValue(pszValueName, szGUID, &nCount);
1845 if (lRes != ERROR_SUCCESS)
1848 if(szGUID[0] != _T(
'{'))
1849 return ERROR_INVALID_DATA;
1852 LPOLESTR lpstr = T2OLE(szGUID);
1855 return E_OUTOFMEMORY;
1858 HRESULT hr = ::CLSIDFromString(lpstr, &guidValue);
1860 return ERROR_INVALID_DATA;
1862 return ERROR_SUCCESS;
1865 LONG QueryBinaryValue(LPCTSTR pszValueName,
void* pValue, ULONG* pnBytes)
1867 ATLASSERT(pnBytes != NULL);
1868 ATLASSERT(m_hKey != NULL);
1871 LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(pValue), pnBytes);
1872 if (lRes != ERROR_SUCCESS)
1874 if (dwType != REG_BINARY)
1875 return ERROR_INVALID_DATA;
1877 return ERROR_SUCCESS;
1880 LONG QueryDWORDValue(LPCTSTR pszValueName, DWORD& dwValue)
1882 ATLASSERT(m_hKey != NULL);
1884 ULONG nBytes =
sizeof(DWORD);
1886 LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(&dwValue), &nBytes);
1887 if (lRes != ERROR_SUCCESS)
1889 if (dwType != REG_DWORD)
1890 return ERROR_INVALID_DATA;
1892 return ERROR_SUCCESS;
1895 LONG QueryQWORDValue(LPCTSTR pszValueName, ULONGLONG& qwValue)
1897 ATLASSERT(m_hKey != NULL);
1899 ULONG nBytes =
sizeof(ULONGLONG);
1901 LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(&qwValue), &nBytes);
1902 if (lRes != ERROR_SUCCESS)
1904 if (dwType != REG_QWORD)
1905 return ERROR_INVALID_DATA;
1907 return ERROR_SUCCESS;
1910 LONG QueryStringValue(LPCTSTR pszValueName, LPTSTR pszValue, ULONG* pnChars)
1912 ATLASSERT(m_hKey != NULL);
1913 ATLASSERT(pnChars != NULL);
1915 ULONG nBytes = (*pnChars) *
sizeof(TCHAR);
1918 LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(pszValue), &nBytes);
1920 if (lRes != ERROR_SUCCESS)
1925 if(dwType != REG_SZ && dwType != REG_EXPAND_SZ)
1927 return ERROR_INVALID_DATA;
1930 if (pszValue != NULL)
1934 if ((nBytes %
sizeof(TCHAR) != 0) || (pszValue[nBytes /
sizeof(TCHAR) -1] != 0))
1935 return ERROR_INVALID_DATA;
1939 pszValue[0] = _T(
'\0');
1943 *pnChars = nBytes /
sizeof(TCHAR);
1945 return ERROR_SUCCESS;
1948 LONG QueryMultiStringValue(LPCTSTR pszValueName, LPTSTR pszValue, ULONG* pnChars)
1950 ATLASSERT(m_hKey != NULL);
1951 ATLASSERT(pnChars != NULL);
1953 if (pszValue != NULL && *pnChars < 2)
1954 return ERROR_INSUFFICIENT_BUFFER;
1956 ULONG nBytes = (*pnChars) *
sizeof(TCHAR);
1959 LONG lRes = ::RegQueryValueEx(m_hKey, pszValueName, NULL, &dwType, reinterpret_cast<LPBYTE>(pszValue), &nBytes);
1960 if (lRes != ERROR_SUCCESS)
1962 if (dwType != REG_MULTI_SZ)
1963 return ERROR_INVALID_DATA;
1964 if (pszValue != NULL && (nBytes %
sizeof(TCHAR) != 0 || nBytes /
sizeof(TCHAR) < 1 || pszValue[nBytes /
sizeof(TCHAR) - 1] != 0 || ((nBytes /
sizeof(TCHAR)) > 1 && pszValue[nBytes /
sizeof(TCHAR) - 2] != 0)))
1965 return ERROR_INVALID_DATA;
1967 *pnChars = nBytes /
sizeof(TCHAR);
1969 return ERROR_SUCCESS;
1973 #else // !(_ATL_VER < 0x0700) 1977 #endif // !(_ATL_VER < 0x0700) 1983 #if defined(_WTL_FORWARD_DECLARE_CSTRING) && !defined(_WTL_USE_CSTRING) 1984 #define _WTL_USE_CSTRING 1985 #endif // defined(_WTL_FORWARD_DECLARE_CSTRING) && !defined(_WTL_USE_CSTRING) 1987 #ifdef _WTL_USE_CSTRING 1989 #endif // _WTL_USE_CSTRING 1994 #define _CSTRING_NS ATL 1996 #define _CSTRING_NS WTL 1998 #endif // _CSTRING_NS 2002 #ifdef __ATLTYPES_H__ 2005 #define _WTYPES_NS WTL 2007 #endif // _WTYPES_NS 2016 #if (((_ATL_VER < 0x0700) && defined(_ATL_DLL)) || (_ATL_VER >= 0x0B00)) && !defined(_WIN32_WCE) 2021 inline HRESULT AtlGetDllVersion(HINSTANCE hInstDLL, DLLVERSIONINFO* pDllVersionInfo)
2023 ATLASSERT(pDllVersionInfo != NULL);
2024 if(pDllVersionInfo == NULL)
2025 return E_INVALIDARG;
2028 DLLGETVERSIONPROC pfnDllGetVersion = (DLLGETVERSIONPROC)::GetProcAddress(hInstDLL,
"DllGetVersion");
2029 if(pfnDllGetVersion == NULL)
2032 return (*pfnDllGetVersion)(pDllVersionInfo);
2035 inline HRESULT AtlGetDllVersion(LPCTSTR lpstrDllName, DLLVERSIONINFO* pDllVersionInfo)
2037 HINSTANCE hInstDLL = ::LoadLibrary(lpstrDllName);
2038 if(hInstDLL == NULL)
2040 HRESULT hRet = AtlGetDllVersion(hInstDLL, pDllVersionInfo);
2041 ::FreeLibrary(hInstDLL);
2049 inline HRESULT AtlGetCommCtrlVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
2051 ATLASSERT(pdwMajor != NULL && pdwMinor != NULL);
2052 if(pdwMajor == NULL || pdwMinor == NULL)
2053 return E_INVALIDARG;
2056 ::ZeroMemory(&dvi,
sizeof(dvi));
2057 dvi.cbSize =
sizeof(dvi);
2058 HRESULT hRet = AtlGetDllVersion(_T(
"comctl32.dll"), &dvi);
2062 *pdwMajor = dvi.dwMajorVersion;
2063 *pdwMinor = dvi.dwMinorVersion;
2065 else if(hRet == E_NOTIMPL)
2082 inline HRESULT AtlGetShellVersion(LPDWORD pdwMajor, LPDWORD pdwMinor)
2084 ATLASSERT(pdwMajor != NULL && pdwMinor != NULL);
2085 if(pdwMajor == NULL || pdwMinor == NULL)
2086 return E_INVALIDARG;
2089 ::ZeroMemory(&dvi,
sizeof(dvi));
2090 dvi.cbSize =
sizeof(dvi);
2091 HRESULT hRet = AtlGetDllVersion(_T(
"shell32.dll"), &dvi);
2095 *pdwMajor = dvi.dwMajorVersion;
2096 *pdwMinor = dvi.dwMinorVersion;
2098 else if(hRet == E_NOTIMPL)
2112 #endif // (_ATL_VER < 0x0700) && defined(_ATL_DLL) && !defined(_WIN32_WCE) 2116 #include "atlwinx.h" 2117 #include "atluser.h" 2120 #ifndef _WTL_NO_AUTOMATIC_NAMESPACE 2121 using namespace WTL;
2122 #endif // !_WTL_NO_AUTOMATIC_NAMESPACE 2124 #endif // __ATLAPP_H__ Definition: atlapp.h:1068
Definition: atlapp.h:1730
Definition: atlapp.h:1231
Definition: atlapp.h:1094
Definition: atlapp.h:1262
Definition: atlapp.h:1376
Definition: atlapp.h:1078
Definition: atlmisc.h:760
Definition: atlapp.h:1317
Definition: atlapp.h:1616
Definition: atlapp.h:1568