3 /////////////////////////////////////////////////////////////////////////////
5 // Copyright (c) 2002 Iain Murray, Inference Group, Cavendish, Cambridge.
7 /////////////////////////////////////////////////////////////////////////////
11 // Track memory leaks on Windows to the line that new'd the memory
14 #define DEBUG_NEW new( _NORMAL_BLOCK, THIS_FILE, __LINE__ )
17 static char THIS_FILE
[] = __FILE__
;
23 } void WinHelper::LastWindowsError() {
25 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_IGNORE_INSERTS
, NULL
, GetLastError(), MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
), // Default language
26 (LPTSTR
) & lpMsgBuf
, 0, NULL
);
27 MessageBox(NULL
, (LPCTSTR
) lpMsgBuf
, TEXT("Error"), MB_OK
| MB_ICONINFORMATION
);
32 bool CommonControlsInited
= false;
35 void WinHelper::InitCommonControlLib() {
36 if(CommonControlsInited
)
39 INITCOMMONCONTROLSEX iccex
;
40 iccex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
41 iccex
.dwICC
= ICC_BAR_CLASSES
| ICC_COOL_CLASSES
;
42 InitCommonControlsEx(&iccex
);
43 CommonControlsInited
= true;
47 // For SHGetSpecialFolderPath.
51 void WinHelper::GetUserDirectory(Tstring
*Output
) {
52 Tstring
& UserData
= *Output
;
53 TCHAR Buffer
[MAX_PATH
];
54 // My documentation says SHGetSpecialFolderPath returns NOERROR if successful
55 // With my headers NOERROR==0 and this function returns TRUE==1 as docs online say.
56 // Not sure I trust the return value, so I'm just going to assume if I have a string
57 // it is probably correct :)
58 Buffer
[0] = TEXT('\0');
59 SHGetSpecialFolderPath(NULL
, Buffer
, CSIDL_APPDATA
, 0);
61 if(UserData
[UserData
.size() - 1] != TEXT('\\'))
62 UserData
+= TEXT('\\');
65 void WinHelper::GetAppDirectory(Tstring
*Output
) {
66 Tstring
& AppLocation
= *Output
;
68 TCHAR Buffer
[MAX_PATH
];
69 if(0 != GetModuleFileName(NULL
, Buffer
, MAX_PATH
)) {
70 TCHAR
*pos
= _tcsrchr(Buffer
, TEXT('\\')); // 3 line hack to remove filename
76 AppLocation
= TEXT(""); // Cop out. Current directory may be elsewhere.
77 // Hopefully it won't come to this...