1 /****************************************************************************
3 * $Id: pncom.h 7 2003-05-30 02:18:02Z gabest $
5 * Copyright (C) 1995-1999 RealNetworks, Inc. All rights reserved.
7 * http://www.real.com/devzone
9 * This program contains proprietary
10 * information of Progressive Networks, Inc, and is licensed
11 * subject to restrictions on use and distribution.
14 * Component Object Model defines, and macros
16 * This file defines items required for COM interfaces in RealMedia and
17 * Progressive Networks SDKs.
25 #include "pntypes.h" /* Needed for most type definitions */
28 // have to use the double expansion to get the prescan level
30 #define STATCONCAT1(w,x,y,z) STATCONCAT2(w,x,y,z)
31 #define STATCONCAT2(w,x,y,z) w##x##y##z
33 #ifdef _STATICALLY_LINKED
35 #define ENTRYPOINT(func) STATCONCAT1(entrypoint_error_symbol_should_not_be_needed,_PLUGINNAME,_,func)
36 #else /* _PLUGINNAME */
37 #define ENTRYPOINT(func) STATCONCAT1(entrypoint_for_,_PLUGINNAME,_,func)
39 #else /* _STATICALLY_LINKED */
40 #define ENTRYPOINT(func) func
44 * We include objbase.h when building for windows so that pncom.h can
45 * easily be used in any windows code.
55 * Use this for reference parameters, so that C users can
56 * use the interface as well.
58 #if defined(__cplusplus)
59 #define REF(type) type&
61 #define REF(type) const type * const
66 * Use this for constant methods in an interface
67 * Compiles away under C
69 #if !defined( CONSTMETHOD )
71 #if defined(__cplusplus)
72 #define CONSTMETHOD const
81 * Used by C users to easily call a function through an interface
85 * pIFooObject->CALL(IFoo,DoSomething)(bar);
88 #if !defined(__cplusplus) || defined(CINTERFACE)
89 #define CALL(iface, func) iface##Vtbl->func
93 #define _INTERFACE struct
96 * If useing windows.h or the windows implementation of COM
97 * these defines are not needed.
99 #if !defined( _OBJBASE_H_ )
102 typedef unsigned int MMRESULT
;
107 #define PASCAL _pascal
115 #define EXTERN_C extern "C"
117 #define EXTERN_C extern
123 #define MAKE_HRESULT(sev,fac,code) ((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))))
124 #endif /*MAKE_HRESULT*/
125 #endif /* OLDERRORCODES */
130 #ifndef STDMETHODCALLTYPE
131 #if defined(_WIN32) || defined(_MPPC_)
133 #define STDMETHODCALLTYPE __cdecl
135 #define STDMETHODCALLTYPE __stdcall
137 #elif defined(_WIN16)
138 #define STDMETHODCALLTYPE __export FAR CDECL
140 #define STDMETHODCALLTYPE
147 #ifndef STDMETHODVCALLTYPE
148 #if defined(_WINDOWS) || defined(_MPPC_)
149 #define STDMETHODVCALLTYPE __cdecl
151 #define STDMETHODVCALLTYPE
158 #ifndef STDAPICALLTYPE
159 #if defined(_WIN32) || defined(_MPPC_)
160 #define STDAPICALLTYPE __stdcall
161 #elif defined(_WIN16)
162 #define STDAPICALLTYPE __export FAR PASCAL
164 #define STDAPICALLTYPE
171 #ifndef STDAPIVCALLTYPE
172 #if defined(_WINDOWS) || defined(_MPPC_)
173 #define STDAPIVCALLTYPE __cdecl
175 #define STDAPIVCALLTYPE
180 * Standard API defines:
182 * NOTE: the 'V' versions allow Variable Argument lists.
190 #define STDAPI EXTERN_C PN_RESULT STDAPICALLTYPE
193 #define STDAPI_(type) EXTERN_C type STDAPICALLTYPE
196 #define STDAPIV EXTERN_C PN_RESULT STDAPIVCALLTYPE
199 #define STDAPIV_(type) EXTERN_C type STDAPIVCALLTYPE
204 * Standard Interface Method defines:
206 * NOTE: the 'V' versions allow Variable Argument lists.
209 * STDMETHODIMP_(type)
211 * STDMETHODIMPV_(type)
214 #define STDMETHODIMP PN_RESULT STDMETHODCALLTYPE
216 #ifndef STDMETHODIMP_
217 #define STDMETHODIMP_(type) type STDMETHODCALLTYPE
219 #ifndef STDMETHODIMPV
220 #define STDMETHODIMPV PN_RESULT STDMETHODVCALLTYPE
222 #ifndef STDMETHODIMPV_
223 #define STDMETHODIMPV_(type) type STDMETHODVCALLTYPE
229 * Interface Declaration
231 * These are macros for declaring interfaces. They exist so that
232 * a single definition of the interface is simulataneously a proper
233 * declaration of the interface structures (C++ abstract classes)
234 * for both C and C++.
236 * DECLARE_INTERFACE(iface) is used to declare an interface that does
237 * not derive from a base interface.
238 * DECLARE_INTERFACE_(iface, baseiface) is used to declare an interface
239 * that does derive from a base interface.
241 * By default if the source file has a .c extension the C version of
242 * the interface declaratations will be expanded; if it has a .cpp
243 * extension the C++ version will be expanded. if you want to force
244 * the C version expansion even though the source file has a .cpp
245 * extension, then define the macro "CINTERFACE".
246 * eg. cl -DCINTERFACE file.cpp
248 * Example Interface declaration:
251 * #define INTERFACE IClassFactory
253 * DECLARE_INTERFACE_(IClassFactory, IUnknown)
255 * // *** IUnknown methods
256 * STDMETHOD(QueryInterface) (THIS_
258 * LPVOID FAR* ppvObj) PURE;
259 * STDMETHOD_(ULONG,AddRef) (THIS) PURE;
260 * STDMETHOD_(ULONG,Release) (THIS) PURE;
262 * // *** IClassFactory methods ***
263 * STDMETHOD(CreateInstance) (THIS_
264 * LPUNKNOWN pUnkOuter,
266 * LPVOID FAR* ppvObject) PURE;
269 * Example C++ expansion:
271 * struct FAR IClassFactory : public IUnknown
273 * virtual PN_RESULT STDMETHODCALLTYPE QueryInterface(
275 * LPVOID FAR* ppvObj) = 0;
276 * virtual PN_RESULT STDMETHODCALLTYPE AddRef(void) = 0;
277 * virtual PN_RESULT STDMETHODCALLTYPE Release(void) = 0;
278 * virtual PN_RESULT STDMETHODCALLTYPE CreateInstance(
279 * LPUNKNOWN pUnkOuter,
281 * LPVOID FAR* ppvObject) = 0;
284 * NOTE: Our documentation says '#define interface class' but we use
285 * 'struct' instead of 'class' to keep a lot of 'public:' lines
286 * out of the interfaces. The 'FAR' forces the 'this' pointers to
287 * be far, which is what we need.
289 * Example C expansion:
291 * typedef struct IClassFactory
293 * const struct IClassFactoryVtbl FAR* lpVtbl;
296 * typedef struct IClassFactoryVtbl IClassFactoryVtbl;
298 * struct IClassFactoryVtbl
300 * PN_RESULT (STDMETHODCALLTYPE * QueryInterface) (
301 * IClassFactory FAR* This,
303 * LPVOID FAR* ppvObj) ;
304 * PN_RESULT (STDMETHODCALLTYPE * AddRef) (IClassFactory FAR* This) ;
305 * PN_RESULT (STDMETHODCALLTYPE * Release) (IClassFactory FAR* This) ;
306 * PN_RESULT (STDMETHODCALLTYPE * CreateInstance) (
307 * IClassFactory FAR* This,
308 * LPUNKNOWN pUnkOuter,
310 * LPVOID FAR* ppvObject);
311 * PN_RESULT (STDMETHODCALLTYPE * LockServer) (
312 * IClassFactory FAR* This,
318 #if defined(__cplusplus) && !defined(CINTERFACE)
319 #define _INTERFACE struct
320 #define STDMETHOD(method) virtual PN_RESULT STDMETHODCALLTYPE method
321 #define STDMETHOD_(type,method) virtual type STDMETHODCALLTYPE method
326 #if defined(_WINDOWS) && defined(EXPORT_CLASSES)
327 #define DECLARE_INTERFACE(iface) _INTERFACE PNEXPORT_CLASS iface
328 #define DECLARE_INTERFACE_(iface, baseiface) _INTERFACE PNEXPORT_CLASS iface : public baseiface
330 #define DECLARE_INTERFACE(iface) _INTERFACE iface
331 #define DECLARE_INTERFACE_(iface, baseiface) _INTERFACE iface : public baseiface
332 #endif // defined(_WINDOWS) && defined(EXPORT_CLASSES)
334 #if !defined(BEGIN_INTERFACE)
335 #if defined(_MPPC_) && \
336 ( (defined(_MSC_VER) || defined(__SC__) || defined(__MWERKS__)) && \
337 !defined(NO_NULL_VTABLE_ENTRY) )
338 #define BEGIN_INTERFACE virtual void a() {}
339 #define END_INTERFACE
341 #define BEGIN_INTERFACE
342 #define END_INTERFACE
349 #define _INTERFACE struct
351 #define STDMETHOD(method) PN_RESULT (STDMETHODCALLTYPE * method)
352 #define STDMETHOD_(type,method) type (STDMETHODCALLTYPE * method)
354 #if !defined(BEGIN_INTERFACE)
356 #define BEGIN_INTERFACE void *b;
357 #define END_INTERFACE
359 #define BEGIN_INTERFACE
360 #define END_INTERFACE
366 #define THIS_ INTERFACE FAR* This,
367 #define THIS INTERFACE FAR* This
370 #define CONST_VTBL const
371 #define DECLARE_INTERFACE(iface) typedef _INTERFACE iface { \
372 const struct iface##Vtbl FAR* lpVtbl; \
374 typedef const struct iface##Vtbl iface##Vtbl; \
375 const struct iface##Vtbl
379 #define DECLARE_INTERFACE(iface) typedef _INTERFACE iface { \
380 struct iface##Vtbl FAR* lpVtbl; \
382 typedef struct iface##Vtbl iface##Vtbl; \
385 #define DECLARE_INTERFACE_(iface, baseiface) DECLARE_INTERFACE(iface)
405 #if !defined( __IID_DEFINED__ )
406 #define __IID_DEFINED__
408 #define IID_NULL GUID_NULL
410 #define CLSID_NULL GUID_NULL
412 #if defined(__cplusplus)
413 #ifndef _REFGUID_DEFINED
414 #define _REFGUID_DEFINED
415 #define REFGUID const GUID &
418 #ifndef _REFIID_DEFINED
419 #define _REFIID_DEFINED
420 #define REFIID const IID &
423 #ifndef _REFCLSID_DEFINED
424 #define _REFCLSID_DEFINED
425 #define REFCLSID const CLSID &
429 #ifndef _REFGUID_DEFINED
430 #define _REFGUID_DEFINED
431 #define REFGUID const GUID * const
433 #ifndef _REFIID_DEFINED
434 #define _REFIID_DEFINED
435 #define REFIID const IID * const
437 #ifndef _REFCLSID_DEFINED
438 #define _REFCLSID_DEFINED
439 #define REFCLSID const CLSID * const
447 * macros to define byte pattern for a GUID.
448 * Example: DEFINE_GUID(GUID_XXX, a, b, c, ...);
450 * Each dll/exe must initialize the GUIDs once. This is done in one of
451 * two ways. If you are not using precompiled headers for the file(s) which
452 * initializes the GUIDs, define INITGUID before including objbase.h. This
453 * is how OLE builds the initialized versions of the GUIDs which are included
454 * in ole2.lib. The GUIDs in ole2.lib are all defined in the same text
457 * The alternative (which some versions of the compiler don't handle properly;
458 * they wind up with the initialized GUIDs in a data, not a text segment),
459 * is to use a precompiled version of objbase.h and then include initguid.h
460 * after objbase.h followed by one or more of the guid defintion files.
464 #if !defined (INITGUID) || (defined (_STATICALLY_LINKED) && !defined(NCIHACK))
465 #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
466 EXTERN_C const GUID FAR name
469 #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
470 EXTERN_C const GUID name \
471 = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
475 #include <memory.h> /* for memcmp */
479 inline BOOL
IsEqualGUID(REFGUID rguid1
, REFGUID rguid2
)
481 return !memcmp(&rguid1
, &rguid2
, sizeof(GUID
));
484 inline void SetGUID(GUID
& rguid1
, REFGUID rguid2
)
486 memcpy(&rguid1
, &rguid2
, sizeof(GUID
));
489 #define IsEqualGUID(rguid1, rguid2) (!memcmp(rguid1, rguid2, sizeof(GUID)))
490 #define SetGUID(rguid1, rguid2) (memcpy(rguid1, rguid2, sizeof(GUID)))
493 #define IsEqualIID(riid1, riid2) IsEqualGUID(riid1, riid2)
494 #define IsEqualCLSID(rclsid1, rclsid2) IsEqualGUID(rclsid1, rclsid2)
496 #define SetIID(riid1, riid2) SetGUID(riid1, riid2)
497 #define SetCLSID(rclsid1, rclsid2) SetGUID(rclsid1, rclsid2)
502 * Because GUID is defined elsewhere in WIN32 land, the operator == and !=
503 * are moved outside the class to global scope.
506 inline BOOL
operator==(const GUID
& guidOne
, const GUID
& guidOther
)
508 return !memcmp(&guidOne
,&guidOther
,sizeof(GUID
));
511 inline BOOL
operator!=(const GUID
& guidOne
, const GUID
& guidOther
)
513 return !(guidOne
== guidOther
);
519 /****************************************************************************
527 * Base class of all interfaces. Defines life time management and
528 * support for dynamic cast.
532 * {00000000-0000-0000-C000000000000046}
535 DEFINE_GUID(IID_IUnknown
, 0x00000000, 0x0000, 0x0000, 0xC0, 0x00,
536 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
539 #define INTERFACE IUnknown
541 DECLARE_INTERFACE(IUnknown
)
543 STDMETHOD(QueryInterface
) (THIS_
547 STDMETHOD_(ULONG
,AddRef
) (THIS
) PURE
;
549 STDMETHOD_(ULONG
,Release
) (THIS
) PURE
;
553 /****************************************************************************
561 * Basic memory management interface.
565 * {00000002-0000-0000-C000000000000046}
568 DEFINE_GUID(IID_IMalloc
, 00000002, 0x0000, 0x0000, 0xC0, 0x00,
569 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
572 #define INTERFACE IMalloc
574 DECLARE_INTERFACE_(IMalloc
, IUnknown
)
579 STDMETHOD(QueryInterface
) (THIS_
583 STDMETHOD_(ULONG
,AddRef
) (THIS
) PURE
;
585 STDMETHOD_(ULONG
,Release
) (THIS
) PURE
;
590 STDMETHOD_(void*,Alloc
) (THIS_
591 UINT32
/*IN*/ count
) PURE
;
593 STDMETHOD_(void*,Realloc
) (THIS_
595 UINT32
/*IN*/ count
) PURE
;
597 STDMETHOD_(void,Free
) (THIS_
598 void* /*IN*/ pMem
) PURE
;
600 STDMETHOD_(UINT32
,GetSize
) (THIS_
601 void* /*IN*/ pMem
) PURE
;
603 STDMETHOD_(BOOL
,DidAlloc
) (THIS_
604 void* /*IN*/ pMem
) PURE
;
606 STDMETHOD_(void,HeapMinimize
) (THIS
) PURE
;
611 * Synchronization: NOTE: These should be made thread safe or use built
612 * in synchronization support in an OS that supports it.
615 #define InterlockedIncrement(plong) (++(*(plong)))
616 #define InterlockedDecrement(plong) (--(*(plong)))
618 #else /* else case of !defined( _OBJBASE_H_ ) && !defined( _COMPOBJ_H_ ) */
621 /* Even in windows we want these GUID's defined... */
623 #if !(defined(INITGUID) && defined(USE_IUNKNOWN_AND_IMALLOC_FROM_UUID_LIB))
624 DEFINE_GUID(IID_IUnknown
, 0x00000000, 0x0000, 0x0000, 0xC0, 0x00,
625 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
627 DEFINE_GUID(IID_IMalloc
, 00000002, 0x0000, 0x0000, 0xC0, 0x00,
628 0x00, 0x00, 0x00, 0x00, 0x00, 0x46);
631 #include <memory.h> /* for memcmp */
634 inline void SetGUID(REFGUID rguid1
, REFGUID rguid2
)
636 memcpy((void*)&rguid1
, (void*)&rguid2
, sizeof(GUID
));
639 #define SetGUID(rguid1, rguid2) (memcpy((void*)rguid1, (void*)rguid2, sizeof(GUID)))
641 #define SetIID(riid1, riid2) SetGUID(riid1, riid2)
642 #define SetCLSID(rclsid1, rclsid2) SetGUID(rclsid1, rclsid2)
644 #endif /* !defined( _OBJBASE_H_ ) && !defined( _COMPOBJ_H_ )*/
654 #define IsEqualIID(riid1, riid2) RNIsEqualGUID(riid1, riid2)
655 #define IsEqualCLSID(rclsid1, rclsid2) RNIsEqualGUID(rclsid1, rclsid2)
658 inline BOOL
RNIsEqualGUID(REFGUID rguid1
, REFGUID rguid2
)
660 return (((UINT32
*) &rguid1
)[0] == ((UINT32
*) &rguid2
)[0] &&
661 ((UINT32
*) &rguid1
)[1] == ((UINT32
*) &rguid2
)[1] &&
662 ((UINT32
*) &rguid1
)[2] == ((UINT32
*) &rguid2
)[2] &&
663 ((UINT32
*) &rguid1
)[3] == ((UINT32
*) &rguid2
)[3]);
666 #define RNIsEqualGUID(rguid1, rguid2) \
667 (((UINT32*) &rguid1)[0] == ((UINT32*) &rguid2)[0] && \
668 ((UINT32*) &rguid1)[1] == ((UINT32*) &rguid2)[1] && \
669 ((UINT32*) &rguid1)[2] == ((UINT32*) &rguid2)[2] && \
670 ((UINT32*) &rguid1)[3] == ((UINT32*) &rguid2)[3]);
673 /****************************************************************************
675 * Putting the following macro in the definition of your class will overload
676 * new and delete for that object. New will then take an IMalloc* from
677 * which to allocate memory from and store it in the begining of the
678 * memory which it will return. Delete will grab this IMalloc* from
679 * the beginning of the mem and use this pointer to deallocate the mem.
692 * m_pContext->QueryInterface(IID_IMalloc, (void**)&pMalloc);
693 * A* p = new(pMalloc) A(0);
694 * pMalloc->Release();
699 void* operator new(size_t size, IMalloc* pMalloc)\
701 void* pMem = pMalloc->Alloc(size + sizeof(IMalloc*));\
702 *(IMalloc**)pMem = pMalloc;\
704 return ((unsigned char*)pMem + sizeof(IMalloc*));\
707 void operator delete(void* pMem)\
709 pMem = (unsigned char*)pMem - sizeof(IMalloc*);\
710 IMalloc* pMalloc = *(IMalloc**)pMem;\
711 pMalloc->Free(pMem);\
715 #endif /* _PNCOM_H_ */