Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

346 lines
10 KiB

  1. /* ole2sp.h - semi-private info; only for test apps within the development group
  2. */
  3. #if !defined( _OLE2SP_H_ )
  4. #define _OLE2SP_H_
  5. #include <shellapi.h>
  6. // For MAC, M_PROLOG and M_EPILOG are macros which assist us in setting up the A5
  7. // world for a DLL when a method in the DLL is called from outside the DLL.
  8. #ifdef _MAC
  9. #define _MAX_PATH 260
  10. #ifdef __cplusplus
  11. class CSetA5
  12. {
  13. public:
  14. CSetA5 (ULONG savedA5){ A5save = SetA5(savedA5);}
  15. ~CSetA5 (){ SetA5(A5save);}
  16. private:
  17. ULONG A5save;
  18. };
  19. pascal long GetA5(void) = 0x2E8D;
  20. #define M_PROLOG(where) CSetA5 Dummy((where)->savedA5)
  21. #define SET_A5 ULONG savedA5
  22. #define GET_A5() savedA5 = GetA5()
  23. // These macros assist Mac in manually saving/setting/restoring A5 in routines that contain
  24. // goto's.
  25. #define A5_PROLOG(where) ULONG A5save = SetA5(where->savedA5)
  26. #define RESTORE_A5() SetA5(A5save)
  27. // Lets MAC name our segments without ifdef's.
  28. #define NAME_SEG(x)
  29. #endif // ccplus
  30. #else
  31. #define M_PROLOG(where)
  32. #define SET_A5
  33. #define GET_A5()
  34. #define A5_PROLOG(where)
  35. #define RESTORE_A5()
  36. #define NAME_SEG(x)
  37. #define IGetProcAddress(a,b) GetProcAddress((a),(b))
  38. #endif
  39. #define ReportResult(a,b,c,d) ResultFromScode(b)
  40. #ifdef WIN32
  41. #define MAP16(v16)
  42. #define MAP32(v32) v32
  43. #define MAP1632(v16,v32) v32
  44. #else
  45. #define MAP16(v16) v16
  46. #define MAP32(v32)
  47. #define MAP1632(v16,v32) v16
  48. #endif
  49. /****** Misc defintions ***************************************************/
  50. #ifdef __TURBOC__
  51. #define implement struct huge
  52. #else
  53. #define implement struct
  54. #endif
  55. #define ctor_dtor private
  56. #define implementations private
  57. #define shared_state private
  58. // helpers for internal methods and functions which follow the same convention
  59. // as the external ones
  60. #ifdef __cplusplus
  61. #define INTERNALAPI_(type) extern "C" type
  62. #else
  63. #define INTERNALAPI_(type) type
  64. #endif
  65. #define INTERNAL HRESULT
  66. #define INTERNAL_(type) type
  67. #define FARINTERNAL HRESULT FAR
  68. #define FARINTERNAL_(type) type FAR
  69. #define NEARINTERNAL HRESULT NEAR
  70. #define NEARINTERNAL_(type) type NEAR
  71. //BEGIN REVIEW: We may not need all the following ones
  72. #define OT_LINK 1L
  73. #define OT_EMBEDDED 2L
  74. #define OT_STATIC 3L
  75. //END REVIEW .....
  76. /****** Old Error Codes ************************************************/
  77. #define S_OOM E_OUTOFMEMORY
  78. #define S_BADARG E_INVALIDARG
  79. #define S_BLANK E_BLANK
  80. #define S_FORMAT E_FORMAT
  81. #define S_NOT_RUNNING E_NOTRUNNING
  82. #define E_UNSPEC E_FAIL
  83. /****** Macros for nested clases ******************************************/
  84. /* To overcome problems with nested classes on MAC
  85. *
  86. * NC(a,b) is used to define a member function of a nested class:
  87. *
  88. * STDMETHODIMP_(type) NC(ClassName,NestedClassName)::MemberFunction(...)
  89. *
  90. * DECLARE_NC(a,b) is used within a class declaration to let a nested class
  91. * access it container class:
  92. *
  93. * class ClassName {
  94. * ..............
  95. *
  96. * class NestedClassName {
  97. * .............
  98. * };
  99. * DECLARE_NC(ClassName,NestedClassName)
  100. * ..............
  101. * };
  102. */
  103. #ifdef _MAC
  104. #define NESTED_CLASS(a,b) struct a##_##b
  105. #define NC(a,b) a##__##b
  106. #define NC1(a,b) a##_##b
  107. #define DECLARE_NC(a,b) typedef a##::##b a##__##b; friend a##__##b;
  108. #define DECLARE_NC2(a,b) typedef a##::a##_##b a##__##b; friend a##__##b;
  109. #else
  110. #define NC(a,b) a##::##b
  111. #define DECLARE_NC(a,b) friend b;
  112. #endif
  113. /****** More Misc defintions **********************************************/
  114. // LPLPVOID should not be made a typedef. typedef won't compile; worse
  115. // within complicated macros the compiler generates unclear error messages
  116. //
  117. #define LPLPVOID void FAR * FAR *
  118. #define UNREFERENCED(a) ((void)(a))
  119. #ifndef BASED_CODE
  120. #ifdef WIN32
  121. #define BASED_CODE
  122. #else
  123. #define BASED_CODE __based(__segname("_CODE"))
  124. #endif
  125. #endif
  126. /****** Standard IUnknown Implementation **********************************/
  127. /*
  128. * The following macro declares a nested class CUnknownImpl,
  129. * creates an object of that class in the outer class, and
  130. * declares CUnknownImpl to be a friend of the outer class. After
  131. * writing about 20 class headers, it became evident that the
  132. * implementation of CUnknownImpl was very similar in all cases,
  133. * and this macro captures the similarity. The classname
  134. * parameter is the name of the outer class WITHOUT the leading
  135. * "C"; i.e., for CFileMoniker, classname is FileMoniker.
  136. */
  137. #define noError return NOERROR
  138. #ifdef _MAC
  139. #define STDUNKDECL(cclassname,classname) NESTED_CLASS(cclassname, CUnknownImpl):IUnknown { public: \
  140. NC1(cclassname,CUnknownImpl)( cclassname FAR * p##classname ) { m_p##classname = p##classname;} \
  141. STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPLPVOID ppvObj); \
  142. STDMETHOD_(ULONG,AddRef)(THIS); \
  143. STDMETHOD_(ULONG,Release)(THIS); \
  144. private: cclassname FAR* m_p##classname; }; \
  145. DECLARE_NC2(cclassname, CUnknownImpl) \
  146. NC(cclassname, CUnknownImpl) m_Unknown;
  147. #else // _MAC
  148. #define STDUNKDECL( ignore, classname ) implement CUnknownImpl:IUnknown { public: \
  149. CUnknownImpl( C##classname FAR * p##classname ) { m_p##classname = p##classname;} \
  150. STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPLPVOID ppvObj); \
  151. STDMETHOD_(ULONG,AddRef)(THIS); \
  152. STDMETHOD_(ULONG,Release)(THIS); \
  153. private: C##classname FAR* m_p##classname; }; \
  154. DECLARE_NC(C##classname, CUnknownImpl) \
  155. CUnknownImpl m_Unknown;
  156. #endif
  157. /*
  158. * The following macro implements all the methods of a nested
  159. * CUnknownImpl class EXCEPT FOR QUERYINTERFACE. This macro was
  160. * written after about 20 classes were written in which the
  161. * implementations of CUnknownImpl were all the same.
  162. */
  163. #define STDUNKIMPL(classname) \
  164. STDMETHODIMP_(ULONG) NC(C##classname,CUnknownImpl)::AddRef( void ){ \
  165. return ++m_p##classname->m_refs; } \
  166. STDMETHODIMP_(ULONG) NC(C##classname,CUnknownImpl)::Release( void ){ \
  167. if (--m_p##classname->m_refs == 0) { delete m_p##classname; return 0; } \
  168. return m_p##classname->m_refs;}
  169. /*
  170. * The following macro implements class::CUnknownImpl::QueryInterface IN
  171. * THE SPECIAL CASE IN WHICH THE OUTER CLASS PRESENTS ONLY ONE INTERFACE
  172. * OTHER THAN IUNKNOWN AND IDEBUG. This is not universally the case,
  173. * but it is common enough that this macro will save time and space.
  174. */
  175. #ifdef _DEBUG
  176. #define STDDEB_QI(classname) \
  177. if (iidInterface == IID_IDebug) {*ppv = (void FAR *)&(m_p##classname->m_Debug); return 0;} else
  178. #else
  179. #define STDDEB_QI(classname)
  180. #endif
  181. #define STDUNK_QI_IMPL(classname, interfacename) \
  182. STDMETHODIMP NC(C##classname,CUnknownImpl)::QueryInterface \
  183. (REFIID iidInterface, void FAR * FAR * ppv) { \
  184. if (iidInterface == IID_IUnknown) {\
  185. *ppv = (void FAR *)&m_p##classname->m_Unknown;\
  186. AddRef(); noError;\
  187. } else if (iidInterface == IID_I##interfacename) { \
  188. *ppv = (void FAR *) &(m_p##classname->m_##classname); \
  189. m_p##classname->m_pUnkOuter->AddRef(); return NOERROR; \
  190. } else \
  191. STDDEB_QI(classname) \
  192. {*ppv = NULL; return ResultFromScode(E_NOINTERFACE);} \
  193. }
  194. /*
  195. * The following macro implements the IUnknown methods inherited
  196. * by the implementation of another interface. The implementation
  197. * is simply to delegate all calls to m_pUnkOuter. Parameters:
  198. * ocname is the outer class name, icname is the implementation
  199. * class name.
  200. *
  201. */
  202. #define STDUNKIMPL_FORDERIVED(ocname, icname) \
  203. STDMETHODIMP NC(C##ocname,C##icname)::QueryInterface \
  204. (REFIID iidInterface, LPLPVOID ppvObj) { \
  205. return m_p##ocname->m_pUnkOuter->QueryInterface(iidInterface, ppvObj);} \
  206. STDMETHODIMP_(ULONG) NC(C##ocname,C##icname)::AddRef(void) { \
  207. return m_p##ocname->m_pUnkOuter->AddRef(); } \
  208. STDMETHODIMP_(ULONG) NC(C##ocname,C##icname)::Release(void) { \
  209. return m_p##ocname->m_pUnkOuter->Release(); }
  210. /****** Debug defintions **************************************************/
  211. #include <debug.h>
  212. /****** Other API defintions **********************************************/
  213. // Utility function not in the spec; in ole2.dll.
  214. // Read and write length-prefixed strings. Open/Create stream.
  215. // ReadStringStream does allocation, returns length of
  216. // required buffer (strlen + 1 for terminating null)
  217. STDAPI ReadStringStream( LPSTREAM pstm, LPSTR FAR * ppsz );
  218. STDAPI WriteStringStream( LPSTREAM pstm, LPCSTR psz );
  219. STDAPI OpenOrCreateStream( IStorage FAR * pstg, const char FAR * pwcsName,
  220. IStream FAR* FAR* ppstm);
  221. // read and write ole control stream (in ole2.dll)
  222. STDAPI WriteOleStg (LPSTORAGE pstg, IOleObject FAR* pOleObj,
  223. DWORD dwReserved, LPSTREAM FAR* ppstmOut);
  224. STDAPI ReadOleStg (LPSTORAGE pstg, DWORD FAR* pdwFlags,
  225. DWORD FAR* pdwOptUpdate, DWORD FAR* pdwReserved,
  226. LPMONIKER FAR* ppmk, LPSTREAM FAR* pstmOut);
  227. STDAPI ReadM1ClassStm(LPSTREAM pStm, CLSID FAR* pclsid);
  228. STDAPI WriteM1ClassStm(LPSTREAM pStm, REFCLSID rclsid);
  229. // low level reg.dat access (in compobj.dll)
  230. STDAPI CoGetInProcDll(REFCLSID rclsid, BOOL fServer, LPSTR lpszDll, int cbMax);
  231. STDAPI CoGetLocalExe(REFCLSID rclsid, LPSTR lpszExe, int cbMax);
  232. STDAPI CoGetPSClsid(REFIID iid, LPCLSID lpclsid);
  233. // simpler alternatives to public apis
  234. #define StringFromCLSID2(rclsid, lpsz, cbMax) \
  235. StringFromGUID2(rclsid, lpsz, cbMax)
  236. #define StringFromIID2(riid, lpsz, cbMax) \
  237. StringFromGUID2(riid, lpsz, cbMax)
  238. STDAPI_(int) Ole1ClassFromCLSID2(REFCLSID rclsid, LPSTR lpsz, int cbMax);
  239. STDAPI_(BOOL) GUIDFromString(LPCSTR lpsz, LPGUID pguid);
  240. STDAPI CLSIDFromOle1Class(LPCSTR lpsz, LPCLSID lpclsid, BOOL fForceAssign=FALSE);
  241. STDAPI_(BOOL) CoIsHashedOle1Class(REFCLSID rclsid);
  242. STDAPI CoOpenClassKey(REFCLSID clsid, HKEY FAR* lphkeyClsid);
  243. // were public; now not
  244. STDAPI SetDocumentBitStg(LPSTORAGE pStg, BOOL fDocument);
  245. STDAPI GetDocumentBitStg(LPSTORAGE pStg);
  246. /*
  247. * Some docfiles stuff
  248. */
  249. #define STGM_DFRALL (STGM_READWRITE | STGM_TRANSACTED | STGM_SHARE_DENY_WRITE)
  250. #define STGM_DFALL (STGM_READWRITE | STGM_TRANSACTED | STGM_SHARE_EXCLUSIVE)
  251. #define STGM_SALL (STGM_READWRITE | STGM_SHARE_EXCLUSIVE)
  252. #endif // _OLE2SP_H_