]> git.saurik.com Git - wxWidgets.git/blame - src/msw/ole/safearray.cpp
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / src / msw / ole / safearray.cpp
CommitLineData
226fa6db
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: msw/ole/safearray.cpp
3// Purpose: Implementation of wxSafeArrayBase class.
4// Author: PB
5// Created: 2012-09-23
226fa6db
VZ
6// Copyright: (c) 2012 wxWidgets development team
7// Licence: wxWindows licence
8///////////////////////////////////////////////////////////////////////////////
9
10// ============================================================================
11// declarations
12// ============================================================================
13
14// ----------------------------------------------------------------------------
15// headers
16// ----------------------------------------------------------------------------
17
18// for compilers that support precompilation, includes "wx.h".
19#include "wx/wxprec.h"
20
21#ifdef __BORLANDC__
22 #pragma hdrstop
23#endif
24
0555b2a0
VZ
25#if wxUSE_OLE && wxUSE_VARIANT
26
226fa6db
VZ
27#ifndef WX_PRECOMP
28 #include "wx/variant.h"
29#endif // WX_PRECOMP
30
31#include "wx/msw/ole/safearray.h"
32
33// ============================================================================
34// implementation
35// ============================================================================
36
37// ----------------------------------------------------------------------------
38// wxSafeArrayBase
39// ----------------------------------------------------------------------------
40
41void wxSafeArrayBase::Destroy()
42{
43 if ( m_array )
44 {
45 Unlock();
46 HRESULT hr = SafeArrayDestroy(m_array);
47 if ( FAILED(hr) )
48 {
49 wxLogApiError(wxS("SafeArrayDestroy()"), hr);
50 }
51 m_array = NULL;
52 }
53}
54
55SAFEARRAY* wxSafeArrayBase::Detach()
56{
57 wxCHECK_MSG( m_array, NULL, wxS("Uninitialized safe array") );
58
59 Unlock();
60 SAFEARRAY* array = m_array;
61 m_array = NULL;
62 return array;
63}
64
65size_t wxSafeArrayBase::GetDim() const
66{
67 wxASSERT( m_array );
68
69 return SafeArrayGetDim(m_array);
70}
71
72bool wxSafeArrayBase::GetLBound(size_t dim, long& bound) const
73{
74 wxCHECK_MSG( m_array, false, wxS("Uninitialized safe array") );
75 wxCHECK_MSG( dim > 0, false, wxS("Invalid dimension index") );
76
77 HRESULT hr = SafeArrayGetLBound(m_array, dim, &bound);
78 if ( FAILED(hr) )
79 {
80 wxLogApiError(wxS("SafeArrayGetLBound()"), hr);
81 return false;
82 }
83 return true;
84}
85
86bool wxSafeArrayBase::GetUBound(size_t dim, long& bound) const
87{
88 wxCHECK_MSG( m_array, false, wxS("Uninitialized safe array") );
89 wxCHECK_MSG( dim > 0, false, wxS("Invalid dimension index") );
90
91 HRESULT hr = SafeArrayGetUBound(m_array, dim, &bound);
92 if ( FAILED(hr) )
93 {
94 wxLogApiError(wxS("SafeArrayGetUBound()"), hr);
95 return false;
96 }
97 return true;
98}
99
100size_t wxSafeArrayBase::GetCount(size_t dim) const
101{
102 long lBound, uBound;
103
104 if ( GetLBound(dim, lBound) && GetUBound(dim, uBound) )
105 return uBound - lBound + 1;
106 return 0;
107}
108
109bool wxSafeArrayBase::Lock()
110{
111 wxCHECK_MSG( m_array, false, wxS("Uninitialized safe array") );
112
113 HRESULT hr = SafeArrayLock(m_array);
114 if ( FAILED(hr) )
115 {
116 wxLogApiError(wxS("SafeArrayLock()"), hr);
117 return false;
118 }
119 return true;
120}
121
122bool wxSafeArrayBase::Unlock()
123{
124 wxCHECK_MSG( m_array, false, wxS("Uninitialized safe array") );
125
126 HRESULT hr = SafeArrayUnlock(m_array);
127 if ( FAILED(hr) )
128 {
129 wxLogApiError(wxS("SafeArrayUnlock()"), hr);
130 return false;
131 }
132 return true;
133}
134
0555b2a0 135#endif // wxUSE_OLE && wxUSE_VARIANT