2 * Copyright 2003, 2004, 2005 Martin Fuchs
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 // Martin Fuchs, 23.07.2003
28 // standard windows headers
29 #define WIN32_LEAN_AND_MEAN
30 #define WIN32_EXTRA_LEAN
34 #if defined(UNICODE) && !defined(_UNICODE)
39 #include <windowsx.h> // for SelectBrush(), ListBox_SetSel(), SubclassWindow(), ...
45 #include <oleauto.h> // for VARIANT
47 #include <malloc.h> // for alloca()
49 #include <stdlib.h> // for _MAX_DIR, ...
50 #include <stdio.h> // for sprintf()
56 #pragma warning(disable: 4786) // disable warnings about too long debug information symbols
59 // STL headers for strings and streams
64 #endif /* __cplusplus */
68 #define _MAX_FNAME 256
69 #define _MAX_DIR _MAX_FNAME
70 #define _MAX_EXT _MAX_FNAME
74 #define W_VER_NT 0 // constant for HIWORD(GetVersion())>>14
82 #define for if (0) {} else for
85 #define COUNTOF _countof
87 #define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
91 #define BUFFER_LEN 2048
94 extern void _log_(LPCTSTR txt
);
96 #define LOG(txt) _log_(txt)
100 #define LONGLONGARG TEXT("I64")
102 #define LONGLONGARG TEXT("L")
108 #define _tcsrchr wcsrchr
110 #define _tcsrchr strrchr
116 #define _stprintf wcsprintf
118 #define _stprintf sprintf
122 #define U2A(s, d, l) WideCharToMultiByte(CP_ACP, 0, s, -1, d, l, NULL, NULL)
123 #define U2nA(s, d, l) WideCharToMultiByte(CP_ACP, 0, s, l, d, l, NULL, NULL)
124 #define A2U(s, d, l) MultiByteToWideChar(CP_ACP, 0, s, -1, d, l)
125 #define A2nU(s, d, l) MultiByteToWideChar(CP_ACP, 0, s, l, d, l)
130 extern void _wsplitpath(const WCHAR
* path
, WCHAR
* drv
, WCHAR
* dir
, WCHAR
* name
, WCHAR
* ext
);
132 extern void _splitpath(const CHAR
* path
, CHAR
* drv
, CHAR
* dir
, CHAR
* name
, CHAR
* ext
);
134 #define _tcsnicmp strncasecmp
135 #define _tcsicoll strcasecmp
138 #ifndef FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
139 #define FILE_ATTRIBUTE_ENCRYPTED 0x00000040
140 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
141 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
142 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
146 #define SetDlgCtrlID(hwnd, id) SetWindowLongPtr(hwnd, GWL_ID, id)
147 #define SetWindowStyle(hwnd, val) (DWORD)SetWindowLongPtr(hwnd, GWL_STYLE, val)
148 #define SetWindowExStyle(h, val) (DWORD)SetWindowLongPtr(hwnd, GWL_EXSTYLE, val)
149 #define Window_SetIcon(hwnd, type, hicon) (HICON)SendMessage(hwnd, WM_SETICON, type, (LPARAM)(hicon))
152 // center window in respect to its parent window
153 extern void CenterWindow(HWND hwnd
);
155 // move window into visibility
156 extern void MoveVisible(HWND hwnd
);
158 // display error message
159 extern void display_error(HWND hwnd
, DWORD error
);
161 // convert time_t to WIN32 FILETIME
162 extern BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
);
164 // search for windows of a specific classname
165 extern int find_window_class(LPCTSTR classname
);
167 // create a directory with all missing parent directories
168 BOOL
RecursiveCreateDirectory(LPCTSTR path_in
);
170 // read DWORD value from registry
171 DWORD
RegGetDWORDValue(HKEY root
, LPCTSTR path
, LPCTSTR valueName
, DWORD def
);
173 // write DWORD value to registry
174 BOOL
RegSetDWORDValue(HKEY root
, LPCTSTR path
, LPCTSTR valueName
, DWORD value
);
176 // test for existing directory
177 BOOL
exists_path(LPCTSTR path
);
185 // secure CRT functions
186 //@@ _MS_VER: temporarily needed for the ReactOS build environment
187 #if defined(__STDC_WANT_SECURE_LIB__) && defined(_MS_VER) // for VS 2005: _MSC_VER>=1400
189 #define _stprintf_s1 _stprintf_s
190 #define _stprintf_s2 _stprintf_s
192 #else // __STDC_WANT_SECURE_LIB__
194 #define strcpy_s(d, l, s) strcpy(d, s)
195 #define wcscpy_s(d, l, s) wcscpy(d, s)
196 #define wcsncpy_s(d, l, s, n) wcsncpy(d, s, n)
198 #if defined(_tcscpy) && !defined(_tcscpy_s)
199 #define _tcscpy_s(d, l, s) _tcscpy(d, s)
202 #if defined(_tsplitpath) && !defined(_tsplitpath_s)
203 #define _tsplitpath_s(f, d,dl, p,pl, n,nl, e,el) _tsplitpath(f, d, p, n, e)
205 #define _wsplitpath_s(f, d,dl, p,pl, n,nl, e,el) _wsplitpath(f, d, p, n, e)
206 #define _splitpath_s(f, d,dl, p,pl, n,nl, e,el) _splitpath(f, d, p, n, e)
209 #define _stprintf_s1(b, l, f, p1) _stprintf(b, f, p1)
210 #define _stprintf_s2(b, l, f, p1,p2) _stprintf(b, f, p1,p2)
212 #endif // __STDC_WANT_SECURE_LIB__
225 /* not necessary with correct include file order for comdef.h ("<MS PSDK>\include" path first) */
226 #if _MSC_VER>=1300 // VS.Net
231 #if defined(_MSC_VER) && !defined(_NO_COMUTIL)
233 // COM utility headers
235 using namespace _com_util
;
237 #endif // _MSC_VER && !_NO_COMUTIL
240 // launch a program or document file
241 extern BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
=SW_SHOWNORMAL
, LPCTSTR parameters
=NULL
);
243 extern BOOL
launch_fileA(HWND hwnd
, LPSTR cmd
, UINT nCmdShow
=SW_SHOWNORMAL
, LPCSTR parameters
=NULL
);
245 #define launch_fileA launch_file
248 // call an DLL export like rundll32
249 extern BOOL
RunDLL(HWND hwnd
, LPCTSTR dllname
, LPCSTR procname
, LPCTSTR cmdline
, UINT nCmdShow
);
251 // launch control panel applet
252 extern BOOL
launch_cpanel(HWND hwnd
, LPCTSTR applet
);
255 /// initialization of windows common controls
256 struct CommonControlInit
258 CommonControlInit(DWORD flags
=ICC_LISTVIEW_CLASSES
|ICC_TREEVIEW_CLASSES
|ICC_BAR_CLASSES
|ICC_PROGRESS_CLASS
|ICC_COOL_CLASSES
)
260 INITCOMMONCONTROLSEX icc
= {sizeof(INITCOMMONCONTROLSEX
), flags
};
262 InitCommonControlsEx(&icc
);
269 struct WaitCursor
///@todo integrate with WM_SETCURSOR to enable multithreaded background tasks as program launching
273 _old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
278 SetCursor(_old_cursor
);
286 /// base of all structures storing a window handle
289 WindowHandle(HWND hwnd
=0)
292 operator HWND() const {return _hwnd
;}
293 HWND
* operator&() {return &_hwnd
;}
300 /// locally hide a window
301 struct HiddenWindow
: public WindowHandle
303 HiddenWindow(HWND hwnd
)
304 : WindowHandle(IsWindowVisible(hwnd
)? hwnd
: 0)
307 SetWindowPos(_hwnd
, 0, 0, 0, 0, 0, SWP_HIDEWINDOW
|SWP_NOREDRAW
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
);
313 SetWindowPos(_hwnd
, 0, 0, 0, 0, 0, SWP_SHOWWINDOW
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
);
318 /// critical section wrapper
320 struct CritSect
: public CRITICAL_SECTION
324 InitializeCriticalSection(this);
329 DeleteCriticalSection(this);
334 /// Lock protects a code section utilizing a critical section
338 Lock(CritSect
& crit_sect
)
339 : _crit_sect(crit_sect
)
341 EnterCriticalSection(&crit_sect
);
346 LeaveCriticalSection(&_crit_sect
);
350 CritSect
& _crit_sect
;
354 /// Thread base class
362 _hThread
= INVALID_HANDLE_VALUE
;
363 _evtFinish
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
370 CloseHandle(_evtFinish
);
371 CloseHandle(_hThread
);
381 _hThread
= CreateThread(NULL
, 0, ThreadProc
, this, 0, NULL
);
387 SetEvent(_evtFinish
);
391 Lock
lock(_crit_sect
);
395 // wait for finishing
396 WaitForSingleObject(_hThread
, INFINITE
);
400 virtual int Run() = 0;
402 bool is_alive() const {return _alive
;}
407 static DWORD WINAPI
ThreadProc(void* para
);
418 /// ClientRect retreives the client area rectangle of a window.
419 struct ClientRect
: public RECT
421 ClientRect(HWND hwnd
)
423 GetClientRect(hwnd
, this);
426 operator LPRECT() {return this;}
428 POINT
& pos() {return *(LPPOINT
)this;}
431 /// ClientRect retreives the window rectangle of a window.
432 struct WindowRect
: public RECT
434 WindowRect(HWND hwnd
)
436 GetWindowRect(hwnd
, this);
439 operator LPRECT() {return this;}
441 POINT
& pos() {return *(LPPOINT
)this;}
444 /// PointL encapsulates the POINT structure into a C++ object.
445 struct Point
: public POINT
447 Point(LONG x_
, LONG y_
)
453 // constructor for being used in processing WM_MOUSEMOVE, WM_LBUTTONDOWN, ... messages
456 x
= GET_X_LPARAM(lparam
);
457 y
= GET_Y_LPARAM(lparam
);
460 operator LPPOINT() {return this;}
464 /// transform coordinates in a RECT from client to screen coordiantes
465 inline void ClientToScreen(HWND hwnd
, RECT
* prect
)
466 {::ClientToScreen(hwnd
,(LPPOINT
)&prect
->left
); ::ClientToScreen(hwnd
,(LPPOINT
)&prect
->right
);}
468 /// transform coordinates in a RECT from screen to client coordiantes
469 inline void ScreenToClient(HWND hwnd
, RECT
* prect
)
470 {::ScreenToClient(hwnd
,(LPPOINT
)&prect
->left
); ::ScreenToClient(hwnd
,(LPPOINT
)&prect
->right
);}
473 /// structure containing information about full screen display of the frame window
474 struct FullScreenParameters
476 FullScreenParameters()
489 /// PaintCanvas is a encapsulation of device contexts managed by BeginPaint()/EndPaint().
490 struct PaintCanvas
: public PAINTSTRUCT
492 PaintCanvas(HWND hwnd
)
495 BeginPaint(hwnd
, this);
500 EndPaint(_hwnd
, this);
503 operator HDC() const {return hdc
;}
509 /// Canvas is a encapsulation of device contexts.
512 Canvas(HDC hdc
) : _hdc(hdc
) {}
514 operator HDC() {return _hdc
;}
520 /// WindowCanvas is a encapsulation of client area device contexts.
521 struct WindowCanvas
: public Canvas
523 WindowCanvas(HWND hwnd
)
524 : Canvas(GetDC(hwnd
)), _hwnd(hwnd
) {}
526 ~WindowCanvas() {ReleaseDC(_hwnd
, _hdc
);}
533 // double buffering classes
535 /// Memory Canvas creates and destroys memory devoce contexts.
536 struct MemCanvas
: public Canvas
539 : Canvas(CreateCompatibleDC(hdc
)) {assert(_hdc
);}
541 ~MemCanvas() {DeleteDC(_hdc
);}
544 /// SelectedBitmap is used to localy select bitmaps into device contexts.
545 struct SelectedBitmap
547 SelectedBitmap(HDC hdc
, HBITMAP hbmp
)
548 : _hdc(hdc
), _old_hbmp(SelectBitmap(hdc
, hbmp
)) {}
550 ~SelectedBitmap() {DeleteObject(SelectBitmap(_hdc
, _old_hbmp
));}
557 /// BufferCanvas manages offscreen bitmaps selected into memory device contexts.
558 struct BufferCanvas
: public MemCanvas
560 BufferCanvas(HDC hdc
, int x
, int y
, int w
, int h
)
561 : MemCanvas(hdc
), _hdctarg(hdc
),
562 _x(x
), _y(y
), _w(w
), _h(h
),
563 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, w
, h
)) {}
565 BufferCanvas(HDC hdc
, const RECT
& rect
)
566 : MemCanvas(hdc
), _hdctarg(hdc
),
567 _x(rect
.left
), _y(rect
.top
), _w(rect
.right
-rect
.left
), _h(rect
.bottom
-rect
.top
),
568 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, _w
, _h
)) {}
576 /// BufferedCanvas enables double buffering for a device context.
577 struct BufferedCanvas
: public BufferCanvas
579 BufferedCanvas(HDC hdc
, int x
, int y
, int w
, int h
, DWORD mode
=SRCCOPY
)
580 : BufferCanvas(hdc
, x
, y
, w
, h
), _mode(mode
) {}
582 BufferedCanvas(HDC hdc
, const RECT
& rect
, DWORD mode
=SRCCOPY
)
583 : BufferCanvas(hdc
, rect
), _mode(mode
) {}
585 ~BufferedCanvas() {BitBlt(_hdctarg
, _x
, _y
, _w
, _h
, _hdc
, 0, 0, _mode
);}
590 /// BufferedPaintCanvas extends PaintCanvas for double buffering.
591 struct BufferedPaintCanvas
: public PaintCanvas
, public BufferedCanvas
593 BufferedPaintCanvas(HWND hwnd
)
595 BufferedCanvas(PAINTSTRUCT::hdc
, 0, 0, rcPaint
.right
, rcPaint
.bottom
)
599 operator HDC() {return BufferedCanvas::_hdc
;}
603 /// TextColor locally selects a text color for drawing.
606 TextColor(HDC hdc
, COLORREF color
)
607 : _hdc(hdc
), _old_color(SetTextColor(hdc
, color
)) {}
609 ~TextColor() {SetTextColor(_hdc
, _old_color
);}
616 /// BkMode locally sets the background mode for drawing.
619 BkMode(HDC hdc
, int bkmode
)
620 : _hdc(hdc
), _old_bkmode(SetBkMode(hdc
, bkmode
)) {}
622 ~BkMode() {SetBkMode(_hdc
, _old_bkmode
);}
626 COLORREF _old_bkmode
;
629 /// FontSelection locally selects a font for drawing.
632 FontSelection(HDC hdc
, HFONT hFont
)
633 : _hdc(hdc
), _old_hFont(SelectFont(hdc
, hFont
)) {}
635 ~FontSelection() {SelectFont(_hdc
, _old_hFont
);}
642 /// BitmapSelection locally selects a bitmap into a device context.
643 struct BitmapSelection
645 BitmapSelection(HDC hdc
, HBITMAP hBmp
)
646 : _hdc(hdc
), _old_hBmp(SelectBitmap(hdc
, hBmp
)) {}
648 ~BitmapSelection() {SelectBitmap(_hdc
, _old_hBmp
);}
655 /// BrushSelection locally selects a brush into a device context.
656 struct BrushSelection
658 BrushSelection(HDC hdc
, HBRUSH hBrush
)
659 : _hdc(hdc
), _old_hBrush(SelectBrush(hdc
, hBrush
)) {}
661 ~BrushSelection() {SelectBrush(_hdc
, _old_hBrush
);}
673 : _hmenu(CreatePopupMenu())
684 operator HMENU() {return _hmenu
;}
686 void Append(UINT id
, LPCTSTR str
, UINT flags
=MF_STRING
)
688 AppendMenu(_hmenu
, flags
, id
, str
);
691 int TrackPopupMenu(HWND hwnd
, const POINT
& pt
, UINT flags
=TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
, LPTPMPARAMS tpm
=NULL
) {
692 return TrackPopupMenuEx(_hmenu
, flags
, pt
.x
, pt
.y
, hwnd
, tpm
);
695 int PopupContextMenu(HWND hwnd
, POINTS pos
, UINT flags
=TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
) {
699 return TrackPopupMenuEx(_hmenu
, flags
, pt
.x
, pt
.y
, hwnd
, NULL
);
702 int TrackPopupMenu(HWND hwnd
, POINTS pos
, UINT flags
=TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
) {
706 ClientToScreen(hwnd
, &pt
);
707 return TrackPopupMenuEx(_hmenu
, flags
, pt
.x
, pt
.y
, hwnd
, NULL
);
710 int TrackPopupMenuAtCursor(HWND hwnd
, UINT flags
=TPM_LEFTBUTTON
) {
711 POINT pt
; GetCursorPos(&pt
);
712 return TrackPopupMenuEx(_hmenu
, flags
, pt
.x
, pt
.y
, hwnd
, NULL
);
715 int TrackPopupMenuAtPos(HWND hwnd
, DWORD pos
, UINT flags
=TPM_LEFTBUTTON
) {
716 return TrackPopupMenuEx(_hmenu
, flags
, GET_X_LPARAM(pos
), GET_Y_LPARAM(pos
), hwnd
, NULL
);
724 struct Variant
: public VARIANT
726 Variant() {VariantInit(this);}
727 Variant(const VARIANT
& var
);
728 Variant(const VARIANT
* var
);
731 operator long() const;
732 operator bool() const;
733 operator VARIANT_BOOL() const;
734 operator IDispatch
*() const;
747 _p
= SysAllocString(s
);
755 _p
= SysAllocStringLen(b
, MultiByteToWideChar(CP_ACP
, 0, s
, -1, b
, BUFFER_LEN
)-1);
762 _p
= SysAllocString(s
);
765 BStr(const VARIANT
& var
)
777 void assign(const VARIANT
& var
);
779 operator BSTR() const
781 return _p
? _p
: (BSTR
)L
"";
786 return _p
? wcslen(_p
): 0;
794 /// string class for TCHAR strings
803 typedef wstring super
;
805 typedef string super
;
810 String(LPCTSTR s
) {if (s
) super::assign(s
);}
811 String(LPCTSTR s
, int l
) : super(s
, l
) {}
813 String(const super
& other
) : super(other
) {}
814 String(const String
& other
) : super(other
) {}
817 String(LPCSTR s
) {assign(s
);}
818 String(LPCSTR s
, int l
) {assign(s
, l
);}
819 String(const string
& other
) {assign(other
.c_str());}
820 String
& operator=(LPCSTR s
) {assign(s
); return *this;}
821 void assign(LPCSTR s
) {if (s
) {TCHAR b
[BUFFER_LEN
]; super::assign(b
, MultiByteToWideChar(CP_ACP
, 0, s
, -1, b
, BUFFER_LEN
)-1);} else erase();}
822 void assign(LPCSTR s
, int l
) {if (s
) {TCHAR b
[BUFFER_LEN
]; super::assign(b
, MultiByteToWideChar(CP_ACP
, 0, s
, l
, b
, BUFFER_LEN
));} else erase();}
823 void assign(const BStr
& s
) {int l
= s
.length(); super::assign(s
, l
);}
825 String(LPCWSTR s
) {assign(s
);}
826 String(LPCWSTR s
, int l
) {assign(s
, l
);}
827 String(const wstring
& other
) {assign(other
.c_str());}
828 String
& operator=(LPCWSTR s
) {assign(s
); return *this;}
829 void assign(LPCWSTR s
) {if (s
) {char b
[BUFFER_LEN
]; super::assign(b
, WideCharToMultiByte(CP_ACP
, 0, s
, -1, b
, BUFFER_LEN
, 0, 0)-1);} else erase();}
830 void assign(LPCWSTR s
, int l
) {if (s
) {char b
[BUFFER_LEN
]; super::assign(b
, WideCharToMultiByte(CP_ACP
, 0, s
, l
, b
, BUFFER_LEN
, 0, 0));} else erase();}
831 void assign(const BStr
& s
) {int l
= s
.length(); if (l
) {char b
[BUFFER_LEN
]; super::assign(b
, WideCharToMultiByte(CP_ACP
, 0, s
, l
, b
, BUFFER_LEN
, 0, 0));} else erase();}
833 String(const BStr
& s
) {assign(s
);}
834 String
& operator=(const BStr
& s
) {assign(s
); return *this;}
836 String
& operator=(LPCTSTR s
) {if (s
) super::assign(s
); else erase(); return *this;}
837 String
& operator=(const super
& s
) {super::assign(s
); return *this;}
838 void assign(LPCTSTR s
) {super::assign(s
);}
839 void assign(LPCTSTR s
, int l
) {super::assign(s
, l
);}
841 operator LPCTSTR() const {return c_str();}
844 operator string() const {char b
[BUFFER_LEN
]; return string(b
, WideCharToMultiByte(CP_ACP
, 0, c_str(), -1, b
, BUFFER_LEN
, 0, 0)-1);}
846 operator wstring() const {WCHAR b
[BUFFER_LEN
]; return wstring(b
, MultiByteToWideChar(CP_ACP
, 0, c_str(), -1, b
, BUFFER_LEN
)-1);}
849 LPTSTR
str() {return (LPTSTR
)data();} /// return modifyable character string pointer
851 String
& printf(LPCTSTR fmt
, ...)
857 super::assign(b
, _vsntprintf(b
, COUNTOF(b
), fmt
, l
));
863 String
& vprintf(LPCTSTR fmt
, va_list l
)
867 super::assign(b
, _vsntprintf(b
, COUNTOF(b
), fmt
, l
));
872 String
& appendf(LPCTSTR fmt
, ...)
878 super::append(b
, _vsntprintf(b
, COUNTOF(b
), fmt
, l
));
884 String
& vappendf(LPCTSTR fmt
, va_list l
)
888 super::append(b
, _vsntprintf(b
, COUNTOF(b
), fmt
, l
));
900 #define _STRING_DEFINED
903 struct FmtString
: public String
905 FmtString(LPCTSTR fmt
, ...)
922 int l
= wcslen(s
) + 1;
923 _str
= (LPSTR
) malloc(2*l
);
925 if (WideCharToMultiByte(CP_ACP
, 0, s
, -1, _str
, 2*l
, 0, 0) <= 0)
934 operator LPCSTR() {return _str
;}
940 #define UNC(x) ((LPCWSTR)(x))
944 #define ANS(x) ((LPCSTR)(x))
950 int l
= strlen(s
) + 1;
951 _str
= (LPWSTR
) malloc(2*l
);
953 if (_str
&& MultiByteToWideChar(CP_ACP
, 0, s
, -1, _str
, l
) <= 0)
962 operator LPCWSTR() {return _str
;}
971 // determine windows version string
972 String
get_windows_version_str();
975 /// link dynamicly to functions by using GetModuleHandle() and GetProcAddress()
976 template<typename FCT
> struct DynamicFct
978 DynamicFct(LPCTSTR moduleName
, UINT ordinal
)
980 HMODULE hModule
= GetModuleHandle(moduleName
);
982 _fct
= (FCT
) GetProcAddress(hModule
, (LPCSTR
)ordinal
);
985 DynamicFct(LPCTSTR moduleName
, LPCSTR name
)
987 HMODULE hModule
= GetModuleHandle(moduleName
);
989 _fct
= (FCT
) GetProcAddress(hModule
, name
);
992 FCT
operator*() const {return _fct
;}
993 operator bool() const {return _fct
? true: false;}
1000 /// link dynamicly to functions by using LoadLibrary() and GetProcAddress()
1001 template<typename FCT
> struct DynamicLoadLibFct
1003 DynamicLoadLibFct(LPCTSTR moduleName
, UINT ordinal
)
1005 _hModule
= LoadLibrary(moduleName
);
1007 _fct
= (FCT
) GetProcAddress(_hModule
, (LPCSTR
)ordinal
);
1010 DynamicLoadLibFct(LPCTSTR moduleName
, LPCSTR name
)
1012 _hModule
= LoadLibrary(moduleName
);
1014 _fct
= (FCT
) GetProcAddress(_hModule
, name
);
1017 ~DynamicLoadLibFct()
1019 FreeLibrary(_hModule
);
1022 FCT
operator*() const {return _fct
;}
1023 operator bool() const {return _fct
? true: false;}
1033 Context(const char* ctx
)
1040 Context(const char* ctx
, LPCSTR obj
)
1048 Context(const char* ctx
, LPCWSTR obj
)
1056 Context(const Context
& other
)
1071 String
toString() const;
1072 String
getStackTrace() const;
1077 static Context
& current() {return *s_current
;}
1082 static Context
* s_current
; ///@todo use TLS
1083 static Context s_main
;
1086 #define CONTEXT_OBJ __ctx__._obj
1087 #define CONTEXT(c) Context __ctx__(c)
1088 #define CURRENT_CONTEXT Context::current()
1089 #define OBJ_CONTEXT(c, o) Context __ctx__(c, o)
1092 extern bool SplitFileSysURL(LPCTSTR url
, String
& dir_out
, String
& fname_out
);
1095 #endif // __cplusplus