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
);
152 //CComQIIDPtr<I_ID(Itype)> is the gcc compatible version of CComQIPtr<Itype>
153 #define I_ID(Itype) Itype,IID_##Itype
155 template <class T
, const IID
* piid
>
163 CComQIIDPtr(_Inout_opt_ T
* lp
) :
167 CComQIIDPtr(_Inout_
const CComQIIDPtr
<T
,piid
>& lp
):
171 CComQIIDPtr(_Inout_opt_ IUnknown
* lp
)
175 if (FAILED(lp
->QueryInterface(*piid
, (void **)&this.p
)))
179 T
*operator = (T
*lp
)
189 T
*operator = (const CComQIIDPtr
<T
,piid
> &lp
)
199 T
* operator=(IUnknown
* lp
)
204 if (FAILED(lp
->QueryInterface(*piid
, (void **)&this.p
)))
222 CComBSTR(LPCOLESTR pSrc
)
227 m_str
= ::SysAllocString(pSrc
);
235 m_str
= ::SysAllocStringLen(NULL
, length
);
238 CComBSTR(int length
, LPCOLESTR pSrc
)
243 m_str
= ::SysAllocStringLen(pSrc
, length
);
250 int len
= MultiByteToWideChar(CP_THREAD_ACP
, 0, pSrc
, -1, NULL
, 0);
251 m_str
= ::SysAllocStringLen(NULL
, len
- 1);
254 int res
= MultiByteToWideChar(CP_THREAD_ACP
, 0, pSrc
, -1, m_str
, len
);
255 ATLASSERT(res
== len
);
258 ::SysFreeString(m_str
);
269 CComBSTR(const CComBSTR
&other
)
271 m_str
= other
.Copy();
274 CComBSTR(REFGUID guid
)
277 ::StringFromGUID2(guid
, szGuid
, 40);
278 m_str
= ::SysAllocString(szGuid
);
283 ::SysFreeString(m_str
);
287 operator BSTR () const
297 CComBSTR
&operator = (const CComBSTR
&other
)
299 ::SysFreeString(m_str
);
300 m_str
= other
.Copy();
315 return ::SysAllocStringLen(m_str
, ::SysStringLen(m_str
));
318 HRESULT
CopyTo(BSTR
*other
) const
326 bool LoadString(HMODULE module
, DWORD uID
)
328 ::SysFreeString(m_str
);
330 const wchar_t *ptr
= NULL
;
331 int len
= ::LoadStringW(module
, uID
, (PWSTR
)&ptr
, 0);
333 m_str
= ::SysAllocStringLen(ptr
, len
);
334 return m_str
!= NULL
;
337 unsigned int Length() const
339 return ::SysStringLen(m_str
);
342 unsigned int ByteLength() const
344 return ::SysStringByteLen(m_str
);
349 class CComVariant
: public tagVARIANT
357 CComVariant(const CComVariant
& other
)
359 V_VT(this) = VT_EMPTY
;
368 CComVariant(LPCOLESTR lpStr
)
370 V_VT(this) = VT_BSTR
;
371 V_BSTR(this) = ::SysAllocString(lpStr
);
374 CComVariant(LPCSTR lpStr
)
376 V_VT(this) = VT_BSTR
;
378 V_BSTR(this) = str
.Detach();
381 CComVariant(bool value
)
383 V_VT(this) = VT_BOOL
;
384 V_BOOL(this) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
387 CComVariant(char value
)
393 CComVariant(BYTE value
)
399 CComVariant(short value
)
405 CComVariant(unsigned short value
)
411 CComVariant(int value
, VARENUM type
= VT_I4
)
413 if (type
== VT_I4
|| type
== VT_INT
)
420 V_VT(this) = VT_ERROR
;
421 V_ERROR(this) = E_INVALIDARG
;
425 CComVariant(unsigned int value
, VARENUM type
= VT_UI4
)
427 if (type
== VT_UI4
|| type
== VT_UINT
)
434 V_VT(this) = VT_ERROR
;
435 V_ERROR(this) = E_INVALIDARG
;
439 CComVariant(long value
, VARENUM type
= VT_I4
)
441 if (type
== VT_I4
|| type
== VT_ERROR
)
448 V_VT(this) = VT_ERROR
;
449 V_ERROR(this) = E_INVALIDARG
;
453 CComVariant(unsigned long value
)
459 CComVariant(float value
)
465 CComVariant(double value
, VARENUM type
= VT_R8
)
467 if (type
== VT_R8
|| type
== VT_DATE
)
474 V_VT(this) = VT_ERROR
;
475 V_ERROR(this) = E_INVALIDARG
;
479 CComVariant(const LONGLONG
& value
)
485 CComVariant(const ULONGLONG
& value
)
491 CComVariant(const CY
& value
)
494 V_I8(this) = value
.int64
;
500 return ::VariantClear(this);
503 HRESULT
Copy(_In_
const VARIANT
* src
)
505 return ::VariantCopy(this, const_cast<VARIANT
*>(src
));
508 HRESULT
ChangeType(_In_ VARTYPE newType
, _In_opt_
const LPVARIANT src
= NULL
)
510 const LPVARIANT lpSrc
= src
? src
: this;
511 return ::VariantChangeType(this, lpSrc
, 0, newType
);
519 #ifndef _ATL_NO_AUTOMATIC_NAMESPACE
521 #endif //!_ATL_NO_AUTOMATIC_NAMESPACE