]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/tls.h
convert COM arguments to wx lazily to improve performance and allow calling Invoke...
[wxWidgets.git] / include / wx / msw / tls.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/tls.h
3 // Purpose: Win32 implementation of wxTlsValue<>
4 // Author: Vadim Zeitlin
5 // Created: 2008-08-08
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_MSW_TLS_H_
12 #define _WX_MSW_TLS_H_
13
14 #include "wx/msw/wrapwin.h"
15
16 // ----------------------------------------------------------------------------
17 // wxTlsKey is a helper class encapsulating a TLS slot
18 // ----------------------------------------------------------------------------
19
20 class wxTlsKey
21 {
22 public:
23 // ctor allocates a new key
24 wxTlsKey()
25 {
26 m_slot = ::TlsAlloc();
27 }
28
29 // return true if the key was successfully allocated
30 bool IsOk() const { return m_slot != TLS_OUT_OF_INDEXES; }
31
32 // get the key value, there is no error return
33 void *Get() const
34 {
35 return ::TlsGetValue(m_slot);
36 }
37
38 // change the key value, return true if ok
39 bool Set(void *value)
40 {
41 return ::TlsSetValue(m_slot, value) != 0;
42 }
43
44 // free the key
45 ~wxTlsKey()
46 {
47 if ( IsOk() )
48 ::TlsFree(m_slot);
49 }
50
51 private:
52 DWORD m_slot;
53
54 DECLARE_NO_COPY_CLASS(wxTlsKey)
55 };
56
57 #endif // _WX_MSW_TLS_H_
58