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
>
160 // Let's tell GCC how to find a symbol.
166 CComQIIDPtr(_Inout_opt_ T
* lp
) :
170 CComQIIDPtr(_Inout_
const CComQIIDPtr
<T
,piid
>& lp
):
174 CComQIIDPtr(_Inout_opt_ IUnknown
* lp
)
178 if (FAILED(lp
->QueryInterface(*piid
, reinterpret_cast<void **>(&p
))))
182 T
*operator = (T
*lp
)
192 T
*operator = (const CComQIIDPtr
<T
,piid
> &lp
)
202 T
* operator=(IUnknown
* lp
)
207 if (FAILED(lp
->QueryInterface(*piid
, reinterpret_cast<void **>(&p
))))
225 CComBSTR(LPCOLESTR pSrc
)
230 m_str
= ::SysAllocString(pSrc
);
238 m_str
= ::SysAllocStringLen(NULL
, length
);
241 CComBSTR(int length
, LPCOLESTR pSrc
)
246 m_str
= ::SysAllocStringLen(pSrc
, length
);
253 int len
= MultiByteToWideChar(CP_THREAD_ACP
, 0, pSrc
, -1, NULL
, 0);
254 m_str
= ::SysAllocStringLen(NULL
, len
- 1);
257 int res
= MultiByteToWideChar(CP_THREAD_ACP
, 0, pSrc
, -1, m_str
, len
);
258 ATLASSERT(res
== len
);
261 ::SysFreeString(m_str
);
272 CComBSTR(const CComBSTR
&other
)
274 m_str
= other
.Copy();
277 CComBSTR(REFGUID guid
)
280 ::StringFromGUID2(guid
, szGuid
, 40);
281 m_str
= ::SysAllocString(szGuid
);
286 ::SysFreeString(m_str
);
290 operator BSTR () const
300 CComBSTR
&operator = (const CComBSTR
&other
)
302 ::SysFreeString(m_str
);
303 m_str
= other
.Copy();
307 void Attach(BSTR bstr
)
309 ::SysFreeString(m_str
);
324 return ::SysAllocStringLen(m_str
, ::SysStringLen(m_str
));
327 HRESULT
CopyTo(BSTR
*other
) const
335 bool LoadString(HMODULE module
, DWORD uID
)
337 ::SysFreeString(m_str
);
339 const wchar_t *ptr
= NULL
;
340 int len
= ::LoadStringW(module
, uID
, (PWSTR
)&ptr
, 0);
342 m_str
= ::SysAllocStringLen(ptr
, len
);
343 return m_str
!= NULL
;
346 unsigned int Length() const
348 return ::SysStringLen(m_str
);
351 unsigned int ByteLength() const
353 return ::SysStringByteLen(m_str
);
358 class CComVariant
: public tagVARIANT
366 CComVariant(const CComVariant
& other
)
368 V_VT(this) = VT_EMPTY
;
377 CComVariant(LPCOLESTR lpStr
)
379 V_VT(this) = VT_BSTR
;
380 V_BSTR(this) = ::SysAllocString(lpStr
);
383 CComVariant(LPCSTR lpStr
)
385 V_VT(this) = VT_BSTR
;
387 V_BSTR(this) = str
.Detach();
390 CComVariant(bool value
)
392 V_VT(this) = VT_BOOL
;
393 V_BOOL(this) = value
? VARIANT_TRUE
: VARIANT_FALSE
;
396 CComVariant(char value
)
402 CComVariant(BYTE value
)
408 CComVariant(short value
)
414 CComVariant(unsigned short value
)
420 CComVariant(int value
, VARENUM type
= VT_I4
)
422 if (type
== VT_I4
|| type
== VT_INT
)
429 V_VT(this) = VT_ERROR
;
430 V_ERROR(this) = E_INVALIDARG
;
434 CComVariant(unsigned int value
, VARENUM type
= VT_UI4
)
436 if (type
== VT_UI4
|| type
== VT_UINT
)
443 V_VT(this) = VT_ERROR
;
444 V_ERROR(this) = E_INVALIDARG
;
448 CComVariant(long value
, VARENUM type
= VT_I4
)
450 if (type
== VT_I4
|| type
== VT_ERROR
)
457 V_VT(this) = VT_ERROR
;
458 V_ERROR(this) = E_INVALIDARG
;
462 CComVariant(unsigned long value
)
468 CComVariant(float value
)
474 CComVariant(double value
, VARENUM type
= VT_R8
)
476 if (type
== VT_R8
|| type
== VT_DATE
)
483 V_VT(this) = VT_ERROR
;
484 V_ERROR(this) = E_INVALIDARG
;
488 CComVariant(const LONGLONG
& value
)
494 CComVariant(const ULONGLONG
& value
)
500 CComVariant(const CY
& value
)
503 V_I8(this) = value
.int64
;
509 return ::VariantClear(this);
512 HRESULT
Copy(_In_
const VARIANT
* src
)
514 return ::VariantCopy(this, const_cast<VARIANT
*>(src
));
517 HRESULT
ChangeType(_In_ VARTYPE newType
, _In_opt_
const LPVARIANT src
= NULL
)
519 const LPVARIANT lpSrc
= src
? src
: this;
520 return ::VariantChangeType(this, lpSrc
, 0, newType
);
528 #ifndef _ATL_NO_AUTOMATIC_NAMESPACE
530 #endif //!_ATL_NO_AUTOMATIC_NAMESPACE