4 * Copyright 2009 Andrew Hill <ash77@reactos.org>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 // It is common to use this in ATL constructors. They only store this for later use, so the usage is safe.
28 #pragma warning(disable:4355)
32 #define _ATL_PACKING 8
35 #ifndef _ATL_FREE_THREADED
36 #ifndef _ATL_APARTMENT_THREADED
37 #ifndef _ATL_SINGLE_THREADED
38 #define _ATL_FREE_THREADED
47 #ifdef _ATL_DISABLE_NO_VTABLE
50 #define ATL_NO_VTABLE __declspec(novtable)
75 CComPtr(const CComPtr
<T
> &lp
)
98 T
*operator = (const CComPtr
<T
> &lp
)
135 ATLASSERT(p
== NULL
);
146 ATLASSERT(p
!= NULL
);
162 CComBSTR(LPCOLESTR pSrc
)
167 m_str
= ::SysAllocString(pSrc
);
175 m_str
= ::SysAllocStringLen(NULL
, length
);
178 CComBSTR(int length
, LPCOLESTR pSrc
)
183 m_str
= ::SysAllocStringLen(pSrc
, length
);
190 int len
= MultiByteToWideChar(CP_THREAD_ACP
, 0, pSrc
, -1, NULL
, 0);
191 m_str
= ::SysAllocStringLen(NULL
, len
- 1);
194 int res
= MultiByteToWideChar(CP_THREAD_ACP
, 0, pSrc
, -1, m_str
, len
);
195 ATLASSERT(res
== len
);
198 ::SysFreeString(m_str
);
209 CComBSTR(const CComBSTR
&other
)
211 m_str
= other
.Copy();
214 CComBSTR(REFGUID guid
)
217 ::StringFromGUID2(guid
, szGuid
, 40);
218 m_str
= ::SysAllocString(szGuid
);
223 ::SysFreeString(m_str
);
227 operator BSTR () const
237 CComBSTR
&operator = (const CComBSTR
&other
)
239 ::SysFreeString(m_str
);
240 m_str
= other
.Copy();
255 return ::SysAllocStringLen(m_str
, ::SysStringLen(m_str
));
258 HRESULT
CopyTo(BSTR
*other
) const
266 bool LoadString(HMODULE module
, DWORD uID
)
268 ::SysFreeString(m_str
);
270 const wchar_t *ptr
= NULL
;
271 int len
= ::LoadStringW(module
, uID
, (PWSTR
)&ptr
, 0);
273 m_str
= ::SysAllocStringLen(ptr
, len
);
274 return m_str
!= NULL
;
277 unsigned int Length() const
279 return ::SysStringLen(m_str
);
282 unsigned int ByteLength() const
284 return ::SysStringByteLen(m_str
);
289 class CComVariant
: public tagVARIANT
297 CComVariant(const CComVariant
& other
)
299 V_VT(this) = VT_EMPTY
;
308 CComVariant(LPCOLESTR lpStr
)
310 V_VT(this) = VT_BSTR
;
311 V_BSTR(this) = ::SysAllocString(lpStr
);
314 CComVariant(LPCSTR lpStr
)
316 V_VT(this) = VT_BSTR
;
318 V_BSTR(this) = str
.Detach();
321 CComVariant(bool value
)
323 V_VT(this) = VT_BOOL
;
324 V_BOOL(this) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
327 CComVariant(char value
)
333 CComVariant(BYTE value
)
339 CComVariant(short value
)
345 CComVariant(unsigned short value
)
351 CComVariant(int value
, VARENUM type
= VT_I4
)
353 if (type
== VT_I4
|| type
== VT_INT
)
360 V_VT(this) = VT_ERROR
;
361 V_ERROR(this) = E_INVALIDARG
;
365 CComVariant(unsigned int value
, VARENUM type
= VT_UI4
)
367 if (type
== VT_UI4
|| type
== VT_UINT
)
374 V_VT(this) = VT_ERROR
;
375 V_ERROR(this) = E_INVALIDARG
;
379 CComVariant(long value
, VARENUM type
= VT_I4
)
381 if (type
== VT_I4
|| type
== VT_ERROR
)
388 V_VT(this) = VT_ERROR
;
389 V_ERROR(this) = E_INVALIDARG
;
393 CComVariant(unsigned long value
)
399 CComVariant(float value
)
405 CComVariant(double value
, VARENUM type
= VT_R8
)
407 if (type
== VT_R8
|| type
== VT_DATE
)
414 V_VT(this) = VT_ERROR
;
415 V_ERROR(this) = E_INVALIDARG
;
419 CComVariant(const LONGLONG
& value
)
425 CComVariant(const ULONGLONG
& value
)
431 CComVariant(const CY
& value
)
434 V_I8(this) = value
.int64
;
440 return ::VariantClear(this);
443 HRESULT
Copy(_In_
const VARIANT
* src
)
445 return ::VariantCopy(this, const_cast<VARIANT
*>(src
));
448 HRESULT
ChangeType(_In_ VARTYPE newType
, _In_opt_
const LPVARIANT src
= NULL
)
450 const LPVARIANT lpSrc
= src
? src
: this;
451 return ::VariantChangeType(this, lpSrc
, 0, newType
);
459 #ifndef _ATL_NO_AUTOMATIC_NAMESPACE
461 #endif //!_ATL_NO_AUTOMATIC_NAMESPACE