forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatlsubset.h
More file actions
180 lines (143 loc) · 3.54 KB
/
atlsubset.h
File metadata and controls
180 lines (143 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* Copyright (C) 2009-2015 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
#ifndef __MINI_ATL_H
#define __MINI_ATL_H
#define __ATLBASE_H__
#include <malloc.h>
////////////////////////////////////////////////////////////////////////////////
// String Conversion
inline char *_ConvW2A(char *p_ansi, const WCHAR *p_wide, int p_ansi_chars)
{
int t_conv;
t_conv = WideCharToMultiByte(CP_ACP, 0, p_wide, -1, p_ansi, p_ansi_chars, NULL, NULL);
if (t_conv == 0)
return NULL;
return p_ansi;
}
inline WCHAR *_ConvA2W(WCHAR *p_wide, const char *p_ansi, int p_wide_chars)
{
int t_conv;
t_conv = MultiByteToWideChar(CP_ACP, 0, p_ansi, -1, p_wide, p_wide_chars);
if (t_conv == 0)
return NULL;
return p_wide;
}
#define USES_CONVERSION int _conv_chars; char *_conv_ansi_str; WCHAR *_conv_wide_str; (_conv_chars,_conv_ansi_str,_conv_wide_str);
#define W2A(w) (w == NULL ? NULL : (_conv_chars = WideCharToMultiByte(CP_ACP, 0, w, -1, NULL, 0, NULL, NULL), _conv_ansi_str = (char*)alloca(_conv_chars), _ConvW2A(_conv_ansi_str, w, _conv_chars)))
#define A2W(a) (a == NULL ? NULL : (_conv_chars = MultiByteToWideChar(CP_ACP, 0, a, -1, NULL, 0), _conv_wide_str = (WCHAR*)alloca(_conv_chars * sizeof(WCHAR)), _ConvA2W(_conv_wide_str, a, _conv_chars)))
#if defined(_UNICODE)
#define W2T(a) (a)
#define T2W(a) (a)
#else
#define W2T W2A
#define T2W A2W
#endif
////////////////////////////////////////////////////////////////////////////////
// CComPtr
template<class T>
class CComPtr
{
public:
T** operator & (void)
{
return &m_ptr;
}
bool operator ! (void)
{
return m_ptr == NULL;
}
T* operator -> (void)
{
return m_ptr;
}
operator T* (void)
{
return m_ptr;
}
T* operator = (const CComPtr<T> &p_comptr)
{
if (m_ptr != p_comptr.m_ptr)
{
Release();
m_ptr = p_comptr.m_ptr;
if (m_ptr != NULL)
m_ptr->AddRef();
}
return m_ptr;
}
CComPtr()
{
m_ptr = NULL;
}
//CComPtr(T*);
//CComPtr(const CComPtr<T>&);
//template<class S>
//CComPtr(const CComPtr<S>&);
CComPtr(int p_null)
{
// initialise to NULL
m_ptr = NULL;
}
~CComPtr()
{
Release();
}
HRESULT CoCreateInstance(GUID p_id, IUnknown *p_outer = NULL, DWORD p_cls_context = CLSCTX_ALL)
{
HRESULT t_result;
t_result = ::CoCreateInstance(p_id, p_outer, p_cls_context, __uuidof(T), (void**)&m_ptr);
return t_result;
}
void Release(void)
{
if (m_ptr != NULL)
m_ptr->Release();
m_ptr = NULL;
}
T* Detach(void)
{
T* t_ptr = m_ptr;
m_ptr = NULL;
return t_ptr;
}
protected:
T *m_ptr;
};
template<class T, const GUID *I>
class CComQIPtr : public CComPtr<T>
{
public:
T* operator = (IUnknown *p_unknown)
{
Query(p_unknown);
return m_ptr;
}
CComQIPtr() : CComPtr()
{
}
//CComQIPtr(T*);
CComQIPtr(IUnknown *p_unknown)
{
Query(p_unknown);
}
protected:
void Query(IUnknown *p_unknown)
{
IUnknown *t_queried = NULL;
if (p_unknown != NULL)
p_unknown->QueryInterface(*I, (void**)&t_queried);
Release();
m_ptr = (T*)t_queried;
}
};
////////////////////////////////////////////////////////////////////////////////
#endif