📄 hxcom.h
字号:
#define SetGUID(rguid1, rguid2) (memcpy(rguid1, rguid2, sizeof(GUID))) /* Flawfinder: ignore */
#else // HELIX_FEATURE_FULLGUID
#define IsEqualGUID(rguid1, rguid2) ((rguid1) == (rguid2))
#define SetGUID(rguid1, rguid2) ((rguid1) = (rguid2))
#endif // HELIX_FEATURE_FULLGUID
#endif // __cplusplus
#define IsEqualIID(riid1, riid2) IsEqualGUID(riid1, riid2)
#define IsEqualCLSID(rclsid1, rclsid2) IsEqualGUID(rclsid1, rclsid2)
#define SetIID(riid1, riid2) SetGUID(riid1, riid2)
#define SetCLSID(rclsid1, rclsid2) SetGUID(rclsid1, rclsid2)
#ifdef __cplusplus
/*
* Because GUID is defined elsewhere in WIN32 land, the operator == and !=
* are moved outside the class to global scope.
*/
#if defined(HELIX_FEATURE_FULLGUID)
inline BOOL operator==(const GUID& guidOne, const GUID& guidOther)
{
return !memcmp(&guidOne,&guidOther,sizeof(GUID));
}
inline BOOL operator!=(const GUID& guidOne, const GUID& guidOther)
{
return !(guidOne == guidOther);
}
#endif // HELIX_FEATURE_FULLGUID
#endif
/****************************************************************************
*
* Interface:
*
* IUnknown
*
* Purpose:
*
* Base class of all interfaces. Defines life time management and
* support for dynamic cast.
*
* IID_IUnknown:
*
* {00000000-0000-0000-C000000000000046}
*
*/
DEFINE_GUID(IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xC0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
#undef INTERFACE
#define INTERFACE IUnknown
DECLARE_INTERFACE(IUnknown)
{
STDMETHOD(QueryInterface) (THIS_
REFIID riid,
void** ppvObj) PURE;
STDMETHOD_(ULONG32,AddRef) (THIS) PURE;
STDMETHOD_(ULONG32,Release) (THIS) PURE;
};
/****************************************************************************
*
* Interface:
*
* IMalloc
*
* Purpose:
*
* Basic memory management interface.
*
* IID_IMalloc:
*
* {00000002-0000-0000-C000000000000046}
*
*/
DEFINE_GUID(IID_IMalloc, 00000002, 0x0000, 0x0000, 0xC0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
#undef INTERFACE
#define INTERFACE IMalloc
DECLARE_INTERFACE_(IMalloc, IUnknown)
{
/*
* IUnknown methods
*/
STDMETHOD(QueryInterface) (THIS_
REFIID riid,
void** ppvObj) PURE;
STDMETHOD_(ULONG32,AddRef) (THIS) PURE;
STDMETHOD_(ULONG32,Release) (THIS) PURE;
/*
* IMalloc methods
*/
STDMETHOD_(void*,Alloc) (THIS_
UINT32 /*IN*/ count) PURE;
STDMETHOD_(void*,Realloc) (THIS_
void* /*IN*/ pMem,
UINT32 /*IN*/ count) PURE;
STDMETHOD_(void,Free) (THIS_
void* /*IN*/ pMem) PURE;
STDMETHOD_(UINT32,GetSize) (THIS_
void* /*IN*/ pMem) PURE;
STDMETHOD_(BOOL,DidAlloc) (THIS_
void* /*IN*/ pMem) PURE;
STDMETHOD_(void,HeapMinimize) (THIS) PURE;
};
#else /* else case of !defined( _OBJBASE_H_ ) && !defined( _COMPOBJ_H_ ) */
// For now, we always use full guids on Windows
#ifndef HELIX_FEATURE_FULLGUID
#define HELIX_FEATURE_FULLGUID
#endif /* HELIX_FEATURE_FULLGUID */
#ifdef DEFINE_GUID
#undef DEFINE_GUID
#endif
#if !defined (INITGUID) || (defined (_STATICALLY_LINKED) && !defined(NCIHACK))
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
EXTERN_C const GUID FAR name
#define DEFINE_GUID_ENUM(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
EXTERN_C const GUID FAR name;
#else
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
EXTERN_C const GUID name \
= { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
#define DEFINE_GUID_ENUM(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
EXTERN_C const GUID name \
= { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } };
#endif
/* Even in windows we want these GUID's defined... */
#if !(defined(INITGUID) && defined(USE_IUNKNOWN_AND_IMALLOC_FROM_UUID_LIB))
DEFINE_GUID(IID_IUnknown, 0x00000000, 0x0000, 0x0000, 0xC0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
DEFINE_GUID(IID_IMalloc, 00000002, 0x0000, 0x0000, 0xC0, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
#endif
#include <memory.h> /* for memcmp */
#ifdef __cplusplus
inline void SetGUID(REFGUID rguid1, REFGUID rguid2)
{
memcpy((void*)&rguid1, (void*)&rguid2, sizeof(GUID)); /* Flawfinder: ignore */
}
#else
#define SetGUID(rguid1, rguid2) (memcpy((void*)rguid1, (void*)rguid2, sizeof(GUID))) /* Flawfinder: ignore */
#endif
#define SetIID(riid1, riid2) SetGUID(riid1, riid2)
#define SetCLSID(rclsid1, rclsid2) SetGUID(rclsid1, rclsid2)
#endif /* !defined( _OBJBASE_H_ ) && !defined( _COMPOBJ_H_ )*/
#ifdef __cplusplus
/*
* This operator is defined for all platforms
*/
#if defined(HELIX_FEATURE_FULLGUID)
inline BOOL operator<(const GUID& lhs, const GUID& rhs)
{
return memcmp(&lhs, &rhs, sizeof(GUID)) < 0;
}
#endif // HELIX_FEATURE_FULLGUID
#endif // __cplusplus
#ifdef IsEqualIID
#undef IsEqualIID
#endif
#ifdef IsEqualCLSID
#undef IsEqualCLSID
#endif
#define IsEqualIID(riid1, riid2) HXIsEqualGUID(riid1, riid2)
#define IsEqualCLSID(rclsid1, rclsid2) HXIsEqualGUID(rclsid1, rclsid2)
#ifdef __cplusplus
inline BOOL HXIsEqualGUID(REFGUID rguid1, REFGUID rguid2)
{
#if defined(HELIX_FEATURE_FULLGUID)
return (((UINT32*) &rguid1)[0] == ((UINT32*) &rguid2)[0] &&
((UINT32*) &rguid1)[1] == ((UINT32*) &rguid2)[1] &&
((UINT32*) &rguid1)[2] == ((UINT32*) &rguid2)[2] &&
((UINT32*) &rguid1)[3] == ((UINT32*) &rguid2)[3]);
#else
return( (rguid1) == (rguid2) );
#endif
}
#else
#if defined(HELIX_FEATURE_FULLGUID)
#define HXIsEqualGUID(rguid1, rguid2) \
(((UINT32*) &rguid1)[0] == ((UINT32*) &rguid2)[0] && \
((UINT32*) &rguid1)[1] == ((UINT32*) &rguid2)[1] && \
((UINT32*) &rguid1)[2] == ((UINT32*) &rguid2)[2] && \
((UINT32*) &rguid1)[3] == ((UINT32*) &rguid2)[3]);
#else
#define HXIsEqualGUID(rguid1, rguid2) \
( (rguid1) == (rguid2) );
#endif
#endif
/****************************************************************************
*
* QueryInterface size reduction structs and functions.
*
* Example Usage:
*
* QInterfaceList qiList[] =
* {
* { GET_IIDHANDLE(IID_IUnknown), (IUnknown*) (IHXPlugin*) this},
* { GET_IIDHANDLE(IID_IHXPlugin), (IHXPlugin*) this},
* { GET_IIDHANDLE(IID_IHXFileFormatObject), (IHXFileFormatObject*) this},
* { GET_IIDHANDLE(IID_IHXAtomizerResponse), (IHXAtomizerResponse*) this},
* { GET_IIDHANDLE(IID_IHXAtomizationCommander), (IHXAtomizationCommander*) this},
* { GET_IIDHANDLE(IID_IHXASMSource), (IHXASMSource*) this},
* { GET_IIDHANDLE(IID_IHXPacketFormat), (IHXPacketFormat*) this},
* { GET_IIDHANDLE(IID_IHXFileSwitcher), (IHXFileSwitcher*) m_pFileSwitcher},
* { GET_IIDHANDLE(IID_IHXCommonClassFactory), m_pClassFactory},
* { GET_IIDHANDLE(IID_IHXScheduler), m_pScheduler}
* };
*
* return QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
*/
#if !defined(HELIX_FEATURE_FULLGUID)
#define IIDHANDLE IID
#define GET_IIDHANDLE(x) (x)
#define DREF_IIDHANDLE(x) (x)
#else // HELIX_FEATURE_FULLGUID
#define IIDHANDLE const IID*
#define GET_IIDHANDLE(x) (&(x))
#define DREF_IIDHANDLE(x) (*(x))
#endif // HELIX_FEATURE_FULLGUID
typedef struct
{
IIDHANDLE hiid;
void* pIFace;
} QInterfaceList;
#define QILISTSIZE(x) sizeof(x)/sizeof(QInterfaceList)
#if !defined(INITGUID) || (defined(_STATICALLY_LINKED) && !defined(NCIHACK))
EXTERN_C HX_RESULT QIFind(QInterfaceList* qiList, UINT32 ulqiListSize,
REFIID riid, void** ppvObj);
#else // !INITGUID || (_STATICALLY_LINKED && NCIHACK)
EXTERN_C HX_RESULT QIFind(QInterfaceList* qiList, UINT32 ulqiListSize,
REFIID riid, void** ppvObj)
{
do
{
if (IsEqualIID(DREF_IIDHANDLE(qiList->hiid), riid))
{
*ppvObj = (qiList->pIFace);
if (*ppvObj)
{
((IUnknown*) (*ppvObj))->AddRef();
return HXR_OK;
}
return HXR_NOINTERFACE;
}
qiList++;
} while ((--ulqiListSize) != 0);
*ppvObj = NULL;
return HXR_NOINTERFACE;
}
#endif // !INITGUID || (_STATICALLY_LINKED && NCIHACK)
/****************************************************************************
*
* Putting the following macro in the definition of your class will overload
* new and delete for that object. New will then take an IMalloc* from
* which to allocate memory from and store it in the begining of the
* memory which it will return. Delete will grab this IMalloc* from
* the beginning of the mem and use this pointer to deallocate the mem.
*
* Example useage:
* class A
* {
* public:
* A(int);
* ~A();
*
* IMALLOC_MEM
* };
*
* IMalloc* pMalloc;
* m_pContext->QueryInterface(IID_IMalloc, (void**)&pMalloc);
* A* p = new(pMalloc) A(0);
* pMalloc->Release();
* delete p;
*/
#define IMALLOC_MEM\
void* operator new(size_t size, IMalloc* pMalloc)\
{\
void* pMem = pMalloc->Alloc(size + sizeof(IMalloc*));\
*(IMalloc**)pMem = pMalloc;\
pMalloc->AddRef();\
return ((unsigned char*)pMem + sizeof(IMalloc*));\
}\
\
void operator delete(void* pMem)\
{\
pMem = (unsigned char*)pMem - sizeof(IMalloc*);\
IMalloc* pMalloc = *(IMalloc**)pMem;\
pMalloc->Free(pMem);\
pMalloc->Release();\
}\
/****************************************************************************
*
* By default, we attempt to use atomic InterlockedIncrement/Decrement
* implementations. Add HELIX_FEATURE_DISABLE_INTERLOCKED_INC_DEC to
* your profile's .pf or to your Umakefil/.pcf file to use non-threadsafe
* implementations.
*/
#include "atomicbase.h"
#if !defined HAVE_INTERLOCKED_INCREMENT
#undef InterlockedIncrement
#undef InterlockedDecrement
#define InterlockedIncrement(plong) (++(*(plong)))
#define InterlockedDecrement(plong) (--(*(plong)))
#endif /* !defined HAVE_INTERLOCKED_INCREMENT */
#if defined(HELIX_CONFIG_COMPACT_COM_MACROS)
EXTERN_C void HX_AddRefFunc(IUnknown** pUnk);
EXTERN_C void HX_ReleaseFunc(IUnknown** pUnk);
#if defined(INITGUID) && (!defined(_STATICALLY_LINKED) || defined(NCIHACK))
void HX_AddRefFunc(IUnknown** pUnk)
{
if (*pUnk)
{
(*pUnk)->AddRef();
}
}
void HX_ReleaseFunc(IUnknown** pUnk)
{
if (*pUnk)
{
(*pUnk)->Release();
*pUnk = 0;
}
}
#endif // INITGUID && (!_STATICALLY_LINKED || NCIHACK)
#if defined(HELIX_CONFIG_TYPE_CHECK_COM_MACROS)
#if defined(HELIX_CONFIG_TYPE_CHECK_COM_MACROS_IMPLICIT_CAST)
#define HX_RELEASE(x) (HX_ReleaseFunc(&x))
#define HX_ADDREF(x) (HX_AddRefFunc(&x))
#else // defined(HELIX_CONFIG_TYPE_CHECK_COM_MACROS_IMPLICIT_CAST)
// we don't want to build with this; this should be compiled only
// to ensure that we have a COM object in the code base
#define HX_RELEASE(x) \
{ \
if (x) \
{ \
IUnknown* pUnk; \
(x)->QueryInterface(IID_IUnknown, (void**)&pUnk); \
if (pUnk) \
{ \
pUnk->Release(); \
} \
(x)->Release(); \
(x) = 0; \
} \
} \
#define HX_ADDREF(x) \
{ \
if (x) \
{ \
IUnknown* pUnk; \
(x)->QueryInterface(IID_IUnknown, (void**)&pUnk); \
if (pUnk) \
{ \
pUnk->Release(); \
} \
(x)->AddRef(); \
} \
} \
#endif // defined(HELIX_CONFIG_TYPE_CHECK_COM_MACROS_IMPLICIT_CAST)
#else // defined(HELIX_CONFIG_TYPE_CHECK_COM_MACROS)
#define HX_RELEASE(x) (HX_ReleaseFunc((IUnknown**)&(x)))
#define HX_ADDREF(x) (HX_AddRefFunc((IUnknown**)&(x)))
#endif // defined(HELIX_CONFIG_TYPE_CHECK_COM_MACROS)
#else // defined(HELIX_CONFIG_COMPACT_COM_MACROS)
#define HX_RELEASE(x) ((x) ? ((x)->Release(), (x) = 0) : 0)
#define HX_ADDREF(x) ((x) ? ((x)->AddRef()) : 0)
#endif // defined(HELIX_CONFIG_COMPACT_COM_MACROS)
#endif /* _HXCOM_H_ */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -