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
31 #define WIN32_NO_STATUS
33 #define COM_NO_WINDOWS_H
39 //#include <undocuser.h>
42 #if defined(UNICODE) && !defined(_UNICODE)
47 #include <windowsx.h> // for SelectBrush(), ListBox_SetSel(), SubclassWindow(), ...
51 //#include <oleauto.h> // for VARIANT
53 //#include <malloc.h> // for alloca()
55 //#include <stdlib.h> // for _MAX_DIR, ...
56 #include <stdio.h> // for sprintf()
62 #pragma warning(disable: 4786) // disable warnings about too long debug information symbols
65 // STL headers for strings and streams
70 #endif /* __cplusplus */
74 #define _MAX_FNAME 256
75 #define _MAX_DIR _MAX_FNAME
76 #define _MAX_EXT _MAX_FNAME
80 #define W_VER_NT 0 // constant for HIWORD(GetVersion())>>14
88 #define for if (0) {} else for
91 #define COUNTOF _countof
93 #define COUNTOF(x) (sizeof(x)/sizeof(x[0]))
97 #define BUFFER_LEN 2048
100 extern void _log_(LPCTSTR txt
);
102 #define LOG(txt) _log_(txt)
106 #define LONGLONGARG TEXT("I64")
108 #define LONGLONGARG TEXT("L")
114 #define _tcsrchr wcsrchr
116 #define _tcsrchr strrchr
122 #define _stprintf wcsprintf
124 #define _stprintf sprintf
128 #define U2A(s, d, l) WideCharToMultiByte(CP_ACP, 0, s, -1, d, l, NULL, NULL)
129 #define U2nA(s, d, l) WideCharToMultiByte(CP_ACP, 0, s, l, d, l, NULL, NULL)
130 #define A2U(s, d, l) MultiByteToWideChar(CP_ACP, 0, s, -1, d, l)
131 #define A2nU(s, d, l) MultiByteToWideChar(CP_ACP, 0, s, l, d, l)
136 extern void _wsplitpath(const WCHAR
* path
, WCHAR
* drv
, WCHAR
* dir
, WCHAR
* name
, WCHAR
* ext
);
138 extern void _splitpath(const CHAR
* path
, CHAR
* drv
, CHAR
* dir
, CHAR
* name
, CHAR
* ext
);
140 #define _tcsnicmp strncasecmp
141 #define _tcsicoll strcasecmp
144 #ifndef FILE_ATTRIBUTE_NOT_CONTENT_INDEXED
145 #define FILE_ATTRIBUTE_ENCRYPTED 0x00000040
146 #define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200
147 #define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400
148 #define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
152 #define SetDlgCtrlID(hwnd, id) SetWindowLongPtr(hwnd, GWL_ID, id)
153 #define SetWindowStyle(hwnd, val) (DWORD)SetWindowLongPtr(hwnd, GWL_STYLE, val)
154 #define SetWindowExStyle(h, val) (DWORD)SetWindowLongPtr(hwnd, GWL_EXSTYLE, val)
155 #define Window_SetIcon(hwnd, type, hicon) (HICON)SendMessage(hwnd, WM_SETICON, type, (LPARAM)(hicon))
158 // center window in respect to its parent window
159 extern void CenterWindow(HWND hwnd
);
161 // move window into visibility
162 extern void MoveVisible(HWND hwnd
);
164 // display error message
165 extern void display_error(HWND hwnd
, DWORD error
);
167 // convert time_t to WIN32 FILETIME
168 extern BOOL
time_to_filetime(const time_t* t
, FILETIME
* ftime
);
170 // search for windows of a specific classname
171 extern int find_window_class(LPCTSTR classname
);
173 // create a directory with all missing parent directories
174 BOOL
RecursiveCreateDirectory(LPCTSTR path_in
);
176 // read DWORD value from registry
177 DWORD
RegGetDWORDValue(HKEY root
, LPCTSTR path
, LPCTSTR valueName
, DWORD def
);
179 // write DWORD value to registry
180 BOOL
RegSetDWORDValue(HKEY root
, LPCTSTR path
, LPCTSTR valueName
, DWORD value
);
182 // test for existing directory
183 BOOL
exists_path(LPCTSTR path
);
191 // secure CRT functions
192 //@@ _MS_VER: temporarily needed for the ReactOS build environment
193 #if defined(__STDC_WANT_SECURE_LIB__) && defined(_MS_VER) // for VS 2005: _MSC_VER>=1400
195 #define _stprintf_s1 _stprintf_s
196 #define _stprintf_s2 _stprintf_s
198 #else // __STDC_WANT_SECURE_LIB__
200 #define strcpy_s(d, l, s) strcpy(d, s)
201 #define wcscpy_s(d, l, s) wcscpy(d, s)
202 #define wcsncpy_s(d, l, s, n) wcsncpy(d, s, n)
204 #if defined(_tcscpy) && !defined(_tcscpy_s)
205 #define _tcscpy_s(d, l, s) _tcscpy(d, s)
208 #if defined(_tsplitpath) && !defined(_tsplitpath_s)
209 #define _tsplitpath_s(f, d,dl, p,pl, n,nl, e,el) _tsplitpath(f, d, p, n, e)
211 #define _wsplitpath_s(f, d,dl, p,pl, n,nl, e,el) _wsplitpath(f, d, p, n, e)
212 #define _splitpath_s(f, d,dl, p,pl, n,nl, e,el) _splitpath(f, d, p, n, e)
215 #define _stprintf_s1(b, l, f, p1) _stprintf(b, f, p1)
216 #define _stprintf_s2(b, l, f, p1,p2) _stprintf(b, f, p1,p2)
218 #endif // __STDC_WANT_SECURE_LIB__
231 /* not necessary with correct include file order for comdef.h ("<MS PSDK>\include" path first) */
232 #if _MSC_VER>=1300 // VS.Net
237 #if defined(_MSC_VER) && !defined(_NO_COMUTIL)
239 // COM utility headers
241 using namespace _com_util
;
243 #endif // _MSC_VER && !_NO_COMUTIL
246 // launch a program or document file
247 extern BOOL
launch_file(HWND hwnd
, LPCTSTR cmd
, UINT nCmdShow
=SW_SHOWNORMAL
, LPCTSTR parameters
=NULL
);
249 extern BOOL
launch_fileA(HWND hwnd
, LPSTR cmd
, UINT nCmdShow
=SW_SHOWNORMAL
, LPCSTR parameters
=NULL
);
251 #define launch_fileA launch_file
254 // call an DLL export like rundll32
255 extern BOOL
RunDLL(HWND hwnd
, LPCTSTR dllname
, LPCSTR procname
, LPCTSTR cmdline
, UINT nCmdShow
);
257 // launch control panel applet
258 extern BOOL
launch_cpanel(HWND hwnd
, LPCTSTR applet
);
261 /// initialization of windows common controls
262 struct CommonControlInit
264 CommonControlInit(DWORD flags
=ICC_LISTVIEW_CLASSES
|ICC_TREEVIEW_CLASSES
|ICC_BAR_CLASSES
|ICC_PROGRESS_CLASS
|ICC_COOL_CLASSES
)
266 INITCOMMONCONTROLSEX icc
= {sizeof(INITCOMMONCONTROLSEX
), flags
};
268 InitCommonControlsEx(&icc
);
275 struct WaitCursor
///@todo integrate with WM_SETCURSOR to enable multithreaded background tasks as program launching
279 _old_cursor
= SetCursor(LoadCursor(0, IDC_WAIT
));
284 SetCursor(_old_cursor
);
292 /// base of all structures storing a window handle
295 WindowHandle(HWND hwnd
=0)
298 operator HWND() const {return _hwnd
;}
299 HWND
* operator&() {return &_hwnd
;}
306 /// locally hide a window
307 struct HiddenWindow
: public WindowHandle
309 HiddenWindow(HWND hwnd
)
310 : WindowHandle(IsWindowVisible(hwnd
)? hwnd
: 0)
313 SetWindowPos(_hwnd
, 0, 0, 0, 0, 0, SWP_HIDEWINDOW
|SWP_NOREDRAW
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
);
319 SetWindowPos(_hwnd
, 0, 0, 0, 0, 0, SWP_SHOWWINDOW
|SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
);
324 /// critical section wrapper
326 struct CritSect
: public CRITICAL_SECTION
330 InitializeCriticalSection(this);
335 DeleteCriticalSection(this);
340 /// Lock protects a code section utilizing a critical section
344 Lock(CritSect
& crit_sect
)
345 : _crit_sect(crit_sect
)
347 EnterCriticalSection(&crit_sect
);
352 LeaveCriticalSection(&_crit_sect
);
356 CritSect
& _crit_sect
;
360 /// Thread base class
368 _hThread
= INVALID_HANDLE_VALUE
;
369 _evtFinish
= CreateEvent(NULL
, TRUE
, FALSE
, NULL
);
376 CloseHandle(_evtFinish
);
377 CloseHandle(_hThread
);
387 _hThread
= CreateThread(NULL
, 0, ThreadProc
, this, 0, NULL
);
393 SetEvent(_evtFinish
);
397 Lock
lock(_crit_sect
);
401 // wait for finishing
402 WaitForSingleObject(_hThread
, INFINITE
);
406 virtual int Run() = 0;
408 bool is_alive() const {return _alive
;}
413 static DWORD WINAPI
ThreadProc(void* para
);
424 /// ClientRect retreives the client area rectangle of a window.
425 struct ClientRect
: public RECT
427 ClientRect(HWND hwnd
)
429 GetClientRect(hwnd
, this);
432 operator LPRECT() {return this;}
434 POINT
& pos() {return *(LPPOINT
)this;}
437 /// ClientRect retreives the window rectangle of a window.
438 struct WindowRect
: public RECT
440 WindowRect(HWND hwnd
)
442 GetWindowRect(hwnd
, this);
445 operator LPRECT() {return this;}
447 POINT
& pos() {return *(LPPOINT
)this;}
450 /// PointL encapsulates the POINT structure into a C++ object.
451 struct Point
: public POINT
453 Point(LONG x_
, LONG y_
)
459 // constructor for being used in processing WM_MOUSEMOVE, WM_LBUTTONDOWN, ... messages
462 x
= GET_X_LPARAM(lparam
);
463 y
= GET_Y_LPARAM(lparam
);
466 operator LPPOINT() {return this;}
470 /// transform coordinates in a RECT from client to screen coordiantes
471 inline void ClientToScreen(HWND hwnd
, RECT
* prect
)
472 {::ClientToScreen(hwnd
,(LPPOINT
)&prect
->left
); ::ClientToScreen(hwnd
,(LPPOINT
)&prect
->right
);}
474 /// transform coordinates in a RECT from screen to client coordiantes
475 inline void ScreenToClient(HWND hwnd
, RECT
* prect
)
476 {::ScreenToClient(hwnd
,(LPPOINT
)&prect
->left
); ::ScreenToClient(hwnd
,(LPPOINT
)&prect
->right
);}
479 /// structure containing information about full screen display of the frame window
480 struct FullScreenParameters
482 FullScreenParameters()
495 /// PaintCanvas is a encapsulation of device contexts managed by BeginPaint()/EndPaint().
496 struct PaintCanvas
: public PAINTSTRUCT
498 PaintCanvas(HWND hwnd
)
501 BeginPaint(hwnd
, this);
506 EndPaint(_hwnd
, this);
509 operator HDC() const {return hdc
;}
515 /// Canvas is a encapsulation of device contexts.
518 Canvas(HDC hdc
) : _hdc(hdc
) {}
520 operator HDC() {return _hdc
;}
526 /// WindowCanvas is a encapsulation of client area device contexts.
527 struct WindowCanvas
: public Canvas
529 WindowCanvas(HWND hwnd
)
530 : Canvas(GetDC(hwnd
)), _hwnd(hwnd
) {}
532 ~WindowCanvas() {ReleaseDC(_hwnd
, _hdc
);}
539 // double buffering classes
541 /// Memory Canvas creates and destroys memory devoce contexts.
542 struct MemCanvas
: public Canvas
545 : Canvas(CreateCompatibleDC(hdc
)) {assert(_hdc
);}
547 ~MemCanvas() {DeleteDC(_hdc
);}
550 /// SelectedBitmap is used to localy select bitmaps into device contexts.
551 struct SelectedBitmap
553 SelectedBitmap(HDC hdc
, HBITMAP hbmp
)
554 : _hdc(hdc
), _old_hbmp(SelectBitmap(hdc
, hbmp
)) {}
556 ~SelectedBitmap() {DeleteObject(SelectBitmap(_hdc
, _old_hbmp
));}
563 /// BufferCanvas manages offscreen bitmaps selected into memory device contexts.
564 struct BufferCanvas
: public MemCanvas
566 BufferCanvas(HDC hdc
, int x
, int y
, int w
, int h
)
567 : MemCanvas(hdc
), _hdctarg(hdc
),
568 _x(x
), _y(y
), _w(w
), _h(h
),
569 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, w
, h
)) {}
571 BufferCanvas(HDC hdc
, const RECT
& rect
)
572 : MemCanvas(hdc
), _hdctarg(hdc
),
573 _x(rect
.left
), _y(rect
.top
), _w(rect
.right
-rect
.left
), _h(rect
.bottom
-rect
.top
),
574 _bmp(_hdc
, CreateCompatibleBitmap(hdc
, _w
, _h
)) {}
582 /// BufferedCanvas enables double buffering for a device context.
583 struct BufferedCanvas
: public BufferCanvas
585 BufferedCanvas(HDC hdc
, int x
, int y
, int w
, int h
, DWORD mode
=SRCCOPY
)
586 : BufferCanvas(hdc
, x
, y
, w
, h
), _mode(mode
) {}
588 BufferedCanvas(HDC hdc
, const RECT
& rect
, DWORD mode
=SRCCOPY
)
589 : BufferCanvas(hdc
, rect
), _mode(mode
) {}
591 ~BufferedCanvas() {BitBlt(_hdctarg
, _x
, _y
, _w
, _h
, _hdc
, 0, 0, _mode
);}
596 /// BufferedPaintCanvas extends PaintCanvas for double buffering.
597 struct BufferedPaintCanvas
: public PaintCanvas
, public BufferedCanvas
599 BufferedPaintCanvas(HWND hwnd
)
601 BufferedCanvas(PAINTSTRUCT::hdc
, 0, 0, rcPaint
.right
, rcPaint
.bottom
)
605 operator HDC() {return BufferedCanvas::_hdc
;}
609 /// TextColor locally selects a text color for drawing.
612 TextColor(HDC hdc
, COLORREF color
)
613 : _hdc(hdc
), _old_color(SetTextColor(hdc
, color
)) {}
615 ~TextColor() {SetTextColor(_hdc
, _old_color
);}
622 /// BkMode locally sets the background mode for drawing.
625 BkMode(HDC hdc
, int bkmode
)
626 : _hdc(hdc
), _old_bkmode(SetBkMode(hdc
, bkmode
)) {}
628 ~BkMode() {SetBkMode(_hdc
, _old_bkmode
);}
632 COLORREF _old_bkmode
;
635 /// FontSelection locally selects a font for drawing.
638 FontSelection(HDC hdc
, HFONT hFont
)
639 : _hdc(hdc
), _old_hFont(SelectFont(hdc
, hFont
)) {}
641 ~FontSelection() {SelectFont(_hdc
, _old_hFont
);}
648 /// BitmapSelection locally selects a bitmap into a device context.
649 struct BitmapSelection
651 BitmapSelection(HDC hdc
, HBITMAP hBmp
)
652 : _hdc(hdc
), _old_hBmp(SelectBitmap(hdc
, hBmp
)) {}
654 ~BitmapSelection() {SelectBitmap(_hdc
, _old_hBmp
);}
661 /// BrushSelection locally selects a brush into a device context.
662 struct BrushSelection
664 BrushSelection(HDC hdc
, HBRUSH hBrush
)
665 : _hdc(hdc
), _old_hBrush(SelectBrush(hdc
, hBrush
)) {}
667 ~BrushSelection() {SelectBrush(_hdc
, _old_hBrush
);}
679 : _hmenu(CreatePopupMenu())
690 operator HMENU() {return _hmenu
;}
692 void Append(UINT id
, LPCTSTR str
, UINT flags
=MF_STRING
)
694 AppendMenu(_hmenu
, flags
, id
, str
);
697 int TrackPopupMenu(HWND hwnd
, const POINT
& pt
, UINT flags
=TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
, LPTPMPARAMS tpm
=NULL
) {
698 return TrackPopupMenuEx(_hmenu
, flags
, pt
.x
, pt
.y
, hwnd
, tpm
);
701 int PopupContextMenu(HWND hwnd
, POINTS pos
, UINT flags
=TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
) {
705 return TrackPopupMenuEx(_hmenu
, flags
, pt
.x
, pt
.y
, hwnd
, NULL
);
708 int TrackPopupMenu(HWND hwnd
, POINTS pos
, UINT flags
=TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
) {
712 ClientToScreen(hwnd
, &pt
);
713 return TrackPopupMenuEx(_hmenu
, flags
, pt
.x
, pt
.y
, hwnd
, NULL
);
716 int TrackPopupMenuAtCursor(HWND hwnd
, UINT flags
=TPM_LEFTBUTTON
) {
717 POINT pt
; GetCursorPos(&pt
);
718 return TrackPopupMenuEx(_hmenu
, flags
, pt
.x
, pt
.y
, hwnd
, NULL
);
721 int TrackPopupMenuAtPos(HWND hwnd
, DWORD pos
, UINT flags
=TPM_LEFTBUTTON
) {
722 return TrackPopupMenuEx(_hmenu
, flags
, GET_X_LPARAM(pos
), GET_Y_LPARAM(pos
), hwnd
, NULL
);
730 struct Variant
: public VARIANT
732 Variant() {VariantInit(this);}
733 Variant(const VARIANT
& var
);
734 Variant(const VARIANT
* var
);
737 operator long() const;
738 operator bool() const;
739 operator VARIANT_BOOL() const;
740 operator IDispatch
*() const;
753 _p
= SysAllocString(s
);
761 _p
= SysAllocStringLen(b
, MultiByteToWideChar(CP_ACP
, 0, s
, -1, b
, BUFFER_LEN
)-1);
768 _p
= SysAllocString(s
);
771 BStr(const VARIANT
& var
)
783 void assign(const VARIANT
& var
);
785 operator BSTR() const
787 return _p
? _p
: (BSTR
)L
"";
792 return _p
? wcslen(_p
): 0;
800 /// string class for TCHAR strings
809 typedef wstring super
;
811 typedef string super
;
816 String(LPCTSTR s
) {if (s
) super::assign(s
);}
817 String(LPCTSTR s
, int l
) : super(s
, l
) {}
819 String(const super
& other
) : super(other
) {}
820 String(const String
& other
) : super(other
) {}
823 String(LPCSTR s
) {assign(s
);}
824 String(LPCSTR s
, int l
) {assign(s
, l
);}
825 String(const string
& other
) {assign(other
.c_str());}
826 String
& operator=(LPCSTR s
) {assign(s
); return *this;}
827 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();}
828 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();}
829 void assign(const BStr
& s
) {int l
= s
.length(); super::assign(s
, l
);}
831 String(LPCWSTR s
) {assign(s
);}
832 String(LPCWSTR s
, int l
) {assign(s
, l
);}
833 String(const wstring
& other
) {assign(other
.c_str());}
834 String
& operator=(LPCWSTR s
) {assign(s
); return *this;}
835 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();}
836 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();}
837 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();}
839 String(const BStr
& s
) {assign(s
);}
840 String
& operator=(const BStr
& s
) {assign(s
); return *this;}
842 String
& operator=(LPCTSTR s
) {if (s
) super::assign(s
); else erase(); return *this;}
843 String
& operator=(const super
& s
) {super::assign(s
); return *this;}
844 void assign(LPCTSTR s
) {super::assign(s
);}
845 void assign(LPCTSTR s
, int l
) {super::assign(s
, l
);}
847 operator LPCTSTR() const {return c_str();}
850 operator string() const {char b
[BUFFER_LEN
]; return string(b
, WideCharToMultiByte(CP_ACP
, 0, c_str(), -1, b
, BUFFER_LEN
, 0, 0)-1);}
852 operator wstring() const {WCHAR b
[BUFFER_LEN
]; return wstring(b
, MultiByteToWideChar(CP_ACP
, 0, c_str(), -1, b
, BUFFER_LEN
)-1);}
855 LPTSTR
str() {return (LPTSTR
)data();} /// return modifyable character string pointer
857 String
& printf(LPCTSTR fmt
, ...)
863 super::assign(b
, _vsntprintf(b
, COUNTOF(b
), fmt
, l
));
869 String
& vprintf(LPCTSTR fmt
, va_list l
)
873 super::assign(b
, _vsntprintf(b
, COUNTOF(b
), fmt
, l
));
878 String
& appendf(LPCTSTR fmt
, ...)
884 super::append(b
, _vsntprintf(b
, COUNTOF(b
), fmt
, l
));
890 String
& vappendf(LPCTSTR fmt
, va_list l
)
894 super::append(b
, _vsntprintf(b
, COUNTOF(b
), fmt
, l
));
906 #define _STRING_DEFINED
909 struct FmtString
: public String
911 FmtString(LPCTSTR fmt
, ...)
928 int l
= wcslen(s
) + 1;
929 _str
= (LPSTR
) malloc(2*l
);
931 if (WideCharToMultiByte(CP_ACP
, 0, s
, -1, _str
, 2*l
, 0, 0) <= 0)
940 operator LPCSTR() {return _str
;}
946 #define UNC(x) ((LPCWSTR)(x))
950 #define ANS(x) ((LPCSTR)(x))
956 int l
= strlen(s
) + 1;
957 _str
= (LPWSTR
) malloc(2*l
);
959 if (_str
&& MultiByteToWideChar(CP_ACP
, 0, s
, -1, _str
, l
) <= 0)
968 operator LPCWSTR() {return _str
;}
977 // determine windows version string
978 String
get_windows_version_str();
981 /// link dynamicly to functions by using GetModuleHandle() and GetProcAddress()
982 template<typename FCT
> struct DynamicFct
984 DynamicFct(LPCTSTR moduleName
, UINT ordinal
)
986 HMODULE hModule
= GetModuleHandle(moduleName
);
988 _fct
= (FCT
) GetProcAddress(hModule
, (LPCSTR
)ordinal
);
991 DynamicFct(LPCTSTR moduleName
, LPCSTR name
)
993 HMODULE hModule
= GetModuleHandle(moduleName
);
995 _fct
= (FCT
) GetProcAddress(hModule
, name
);
998 FCT
operator*() const {return _fct
;}
999 operator bool() const {return _fct
? true: false;}
1006 /// link dynamicly to functions by using LoadLibrary() and GetProcAddress()
1007 template<typename FCT
> struct DynamicLoadLibFct
1009 DynamicLoadLibFct(LPCTSTR moduleName
, UINT ordinal
)
1011 _hModule
= LoadLibrary(moduleName
);
1013 _fct
= (FCT
) GetProcAddress(_hModule
, (LPCSTR
)ordinal
);
1016 DynamicLoadLibFct(LPCTSTR moduleName
, LPCSTR name
)
1018 _hModule
= LoadLibrary(moduleName
);
1020 _fct
= (FCT
) GetProcAddress(_hModule
, name
);
1023 ~DynamicLoadLibFct()
1025 FreeLibrary(_hModule
);
1028 FCT
operator*() const {return _fct
;}
1029 operator bool() const {return _fct
? true: false;}
1039 Context(const char* ctx
)
1046 Context(const char* ctx
, LPCSTR obj
)
1054 Context(const char* ctx
, LPCWSTR obj
)
1062 Context(const Context
& other
)
1077 String
toString() const;
1078 String
getStackTrace() const;
1083 static Context
& current() {return *s_current
;}
1088 static Context
* s_current
; ///@todo use TLS
1089 static Context s_main
;
1092 #define CONTEXT_OBJ __ctx__._obj
1093 #define CONTEXT(c) Context __ctx__(c)
1094 #define CURRENT_CONTEXT Context::current()
1095 #define OBJ_CONTEXT(c, o) Context __ctx__(c, o)
1098 extern bool SplitFileSysURL(LPCTSTR url
, String
& dir_out
, String
& fname_out
);
1101 #endif // __cplusplus