Leaked source code of windows server 2003
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.

416 lines
9.7 KiB

  1. <outfile:BridgeCP.def>
  2. LIBRARY DUserCP
  3. EXPORTS
  4. ; DLL entry point
  5. DllMain
  6. BuildBridgeGadget
  7. InitBridge
  8. ; Api's
  9. <repeat:iClass,$<num_class>>
  10. Override$<class>Message
  11. <repeat:iFunc,$<num_funcs>>
  12. <if:$<func_isInherited>=="false">
  13. $<class>$<func>
  14. </if> ; !isInherited
  15. </repeat> ; iFunc
  16. <repeat:iFunc,$<num_funcs>>
  17. <if:$<func_isInherited>=="false">
  18. S$<class>$<func>
  19. </if> ; !isInherited
  20. </repeat> ; iFunc
  21. </repeat> ; iClass
  22. </outfile>
  23. <outfile:Api.h>
  24. /***************************************************************************\\
  25. *
  26. * Generated by GIDL on $<date> at $<time>
  27. *
  28. * Flat-Api portion
  29. * Target = $<target>
  30. *
  31. \***************************************************************************/
  32. #pragma once
  33. #include "Gadget.h"
  34. </outfile>
  35. <outfile:Api.cpp>
  36. /***************************************************************************\\
  37. *
  38. * Generated by GIDL on $<date> at $<time>
  39. *
  40. * Flat-Api portion
  41. * Target = $<target>
  42. *
  43. \***************************************************************************/
  44. #include "stdafx.h"
  45. <if:"$<project>"!="">
  46. #include "$<project>"
  47. </if>
  48. #include "super.h"
  49. #include "stub.h"
  50. #include <stddef.h>
  51. #pragma warning(disable:4100) // unreferenced formal parameter
  52. /***************************************************************************\\
  53. *
  54. * class DLL entry points for flat API's
  55. *
  56. \***************************************************************************/
  57. <repeat:iClass,$<num_class>>
  58. <repeat:iFunc,$<num_funcs>>
  59. <if:$<func_isInherited>=="false">
  60. //---------------------------------------------------------------------------
  61. extern "C"
  62. $<func_type> CALLBACK $<class>$<func>($<class> * p\
  63. <if:"$<num_params>"!="0">
  64. , \
  65. </if>
  66. $<func_params>)
  67. {
  68. <if:"$<func_type>"!="void">
  69. return p->$<func>(\
  70. </if>
  71. <if:"$<func_type>"=="void">
  72. p->$<func>(\
  73. </if>
  74. <repeat:iParam,$<num_params>>
  75. $<param>\
  76. <if:! #last iParam>
  77. , \
  78. </if>
  79. </repeat>
  80. );
  81. }
  82. </if> ; !isInherited
  83. </repeat> ; iFunc
  84. <repeat:iFunc,$<num_funcs>>
  85. <if:$<func_isInherited>=="false">
  86. //---------------------------------------------------------------------------
  87. extern "C"
  88. $<func_type> CALLBACK S$<class>$<func>($<class> * p\
  89. <if:"$<num_params>"!="0">
  90. , \
  91. </if>
  92. $<func_params>)
  93. {
  94. S$<class> s;
  95. s.m_pgad = p;
  96. <if:"$<func_type>"!="void">
  97. return s.Api$<func>(\
  98. </if>
  99. <if:"$<func_type>"=="void">
  100. s.Api$<func>(\
  101. </if>
  102. <repeat:iParam,$<num_params>>
  103. $<param>\
  104. <if:! #last iParam>
  105. , \
  106. </if>
  107. </repeat>
  108. );
  109. }
  110. </if> ; !isInherited
  111. </repeat> ; iFunc
  112. </repeat> ; iClass
  113. </outfile>
  114. <outfile:Bridge.h>
  115. /***************************************************************************\\
  116. *
  117. * Generated by GIDL on $<date> at $<time>
  118. *
  119. * COM+ Bridge class portion
  120. * Target = $<target>
  121. *
  122. \***************************************************************************/
  123. #if !defined(BRIDGECP__Bridge_h__INCLUDED)
  124. #define BRIDGECP__Bridge_h__INCLUDED
  125. #pragma once
  126. #include "Gadget.h"
  127. #include "stub.h"
  128. #include "super.h"
  129. BOOL InitBridges();
  130. BOOL IsMsgOverride(int idxFunc, BYTE rgMsg[]);
  131. void SetMsgOverride(int idxFunc, BOOL fOverride, BYTE rgMsg[]);
  132. <repeat:iClass,$<num_class>>
  133. //------------------------------------------------------------------------------
  134. class $<class>Bridge : $<class>Impl<$<class>Bridge, S$<class>>
  135. {
  136. // Construction
  137. public:
  138. $<class>Bridge()
  139. {
  140. m_pfnEvent = NULL;
  141. m_pfnMethod = NULL;
  142. ZeroMemory(m_rgMsg, sizeof(m_rgMsg));
  143. }
  144. // Public API
  145. public:
  146. <repeat:iFunc,$<num_funcs>>
  147. dapi $<func_type> Api$<func>($<func_params>);
  148. </repeat>
  149. // Implementation
  150. public:
  151. static BOOL Init$<class>()
  152. {
  153. <if:"$<super>"!="">
  154. if (!S$<super>::Init$<super>()) {
  155. return FALSE;
  156. }
  157. </if>
  158. ZeroMemory(&s_mc, sizeof(s_mc));
  159. s_mc.cbSize = sizeof(s_mc);
  160. s_mc.nClassVersion = $<class.version>;
  161. s_mc.pszClassName = L"$<class>Bridge";
  162. s_mc.pszSuperName = L"$<class>";
  163. s_mc.rgMsgInfo = s_rgmi;
  164. s_mc.cMsgs = $<num_funcs>;
  165. s_mc.pfnPromote = Promote$<class>;
  166. s_mc.pfnDemote = Demote$<class>;
  167. return DUserRegisterGuts(&s_mc) != NULL;
  168. }
  169. static HRESULT CALLBACK
  170. Promote$<class>(DUser::ConstructProc pfnCS, HCLASS hclCur, DUser::Gadget * pgad, DUser::Gadget::ConstructInfo * pciData)
  171. {
  172. HRESULT hr;
  173. BridgeData * pbd = GetBridgeData();
  174. hr = (pfnCS)(DUser::Gadget::ccSuper, s_hclSuper, pgad, pciData);
  175. if (FAILED(hr)) {
  176. return hr;
  177. }
  178. $<class>Bridge * pc = new $<class>Bridge;
  179. if (pc == NULL) {
  180. return E_OUTOFMEMORY;
  181. }
  182. pc->m_pgad = pgad;
  183. pc->m_pfnEvent = pbd->pfnEvent;
  184. pc->m_pfnMethod = pbd->pfnMethod;
  185. hr = (pfnCS)(DUser::Gadget::ccSetThis, hclCur, pgad, pc);
  186. if (FAILED(hr)) {
  187. return hr;
  188. }
  189. return S_OK;
  190. }
  191. inline BOOL IsMsgOverride(int idxMsg)
  192. {
  193. return ::IsMsgOverride(idxMsg, m_rgMsg);
  194. }
  195. inline void SetMsgOverride(int idxMsg, BOOL fOverride)
  196. {
  197. ::SetMsgOverride(idxMsg, fOverride, m_rgMsg);
  198. }
  199. // Data
  200. protected:
  201. EventProc m_pfnEvent;
  202. MethodProc m_pfnMethod;
  203. BYTE m_rgMsg[($<num_funcs>+7)/8];
  204. static DUser::MessageInfoGuts s_rgmi[];
  205. public:
  206. static DUser::MessageClassGuts s_mc;
  207. }; // class $<class>Bridge
  208. </repeat>; ; iClass
  209. <repeat:iClass,$<num_class>>
  210. #define IMPLEMENT_BRIDGE_$<class>(me) \\
  211. DUser::MessageClassGuts $<class>Bridge::s_mc; \\
  212. DUser::MessageInfoGuts $<class>Bridge::s_rgmi[] = { \\
  213. <repeat:iFunc,$<num_funcs>>
  214. { member(me::Api$<func>), NULL, L"$<func>" }, \\
  215. </repeat> ; iFunc
  216. };
  217. </repeat>; ; iClass
  218. #endif // BRIDGECP__Bridge_h__INCLUDED
  219. </outfile>
  220. <outfile:Bridge.cpp>
  221. /***************************************************************************\\
  222. *
  223. * Generated by GIDL on $<date> at $<time>
  224. *
  225. * COM+ Bridge class portion
  226. * Target = $<target>
  227. *
  228. \***************************************************************************/
  229. #include "stdafx.h"
  230. <if:"$<project>"!="">
  231. #include "$<project>"
  232. </if>
  233. #include "Bridge.h"
  234. <repeat:iClass,$<num_class>>
  235. IMPLEMENT_BRIDGE_$<class>($<class>Bridge)
  236. </repeat> ; iClass
  237. //------------------------------------------------------------------------------
  238. BOOL InitBridges()
  239. {
  240. return
  241. <repeat:iClass,$<num_class>>
  242. $<class>Bridge::Init$<class>() &&
  243. </repeat> ; iClass
  244. TRUE;
  245. }
  246. //------------------------------------------------------------------------------
  247. BOOL IsMsgOverride(int idxFunc, BYTE rgMsg[])
  248. {
  249. //
  250. // NOTE: idxFunc is NOT the same as the message ID. idxFunc is determined
  251. // at COMPILE time, where-as the message ID is determined at RUNTIME.
  252. //
  253. UINT idxMajor = (UINT) idxFunc / 8;
  254. return (rgMsg[idxMajor]) & ((BYTE) (1 << (idxFunc & 7)));
  255. }
  256. //------------------------------------------------------------------------------
  257. void SetMsgOverride(int idxFunc, BOOL fOverride, BYTE rgMsg[])
  258. {
  259. //
  260. // NOTE: idxFunc is NOT the same as the message ID. idxFunc is determined
  261. // at COMPILE time, where-as the message ID is determined at RUNTIME.
  262. //
  263. UINT idxMajor = idxFunc / 8;
  264. BYTE idxMinor = (BYTE) (1 << (idxFunc & 7));
  265. BYTE b = rgMsg[idxMajor];
  266. if (fOverride) {
  267. // Turn on
  268. b |= idxMinor;
  269. } else {
  270. // Turn off
  271. b &= ~idxMinor;
  272. }
  273. rgMsg[idxMajor] = b;
  274. }
  275. <repeat:iClass,$<num_class>>
  276. /***************************************************************************\\
  277. *
  278. * class $<class>Bridge
  279. *
  280. \***************************************************************************/
  281. //------------------------------------------------------------------------------
  282. extern "C"
  283. BOOL WINAPI
  284. Override$<class>Message($<class> * pg, LPCWSTR pszMessage, BOOL fOverride)
  285. {
  286. $<class>Bridge * pb = reinterpret_cast<$<class>Bridge *>
  287. (DUserGetGutsData(pg, $<class>Bridge::s_mc.hclNew));
  288. if (pb == NULL) {
  289. SetError(E_INVALIDARG);
  290. return FALSE;
  291. }
  292. <repeat:iFunc,$<num_funcs>>
  293. if (wcscmp(pszMessage, L"$<func>") == 0) {
  294. pb->SetMsgOverride($<iFunc>, fOverride);
  295. return TRUE;
  296. }
  297. </repeat>
  298. SetError(DU_E_MESSAGENOTFOUND);
  299. return FALSE;
  300. }
  301. <repeat:iFunc,$<num_funcs>>
  302. //------------------------------------------------------------------------------
  303. $<func_type>
  304. $<class>Bridge::Api$<func>($<func_params>)
  305. {
  306. Assert(m_pfnMethod != NULL);
  307. if (IsMsgOverride($<iFunc>)) {
  308. <if:"$<func>"=="OnEvent">
  309. return (m_pfnEvent)(\
  310. <repeat:iParam,$<num_params>>
  311. $<param>\
  312. <if:! #last iParam>
  313. , \
  314. </if> ; ! #last iParam
  315. </repeat>
  316. );
  317. </if> ; $<func> == OnEvent
  318. <if:"$<func>"!="OnEvent">
  319. $<class>::GMSG_$<func> msg;
  320. ZeroMemory(&msg, sizeof(msg));
  321. msg.cbSize = sizeof(msg);
  322. msg.nMsg = s_rgmi$<class>[$<iFunc>].cbSlotOffset;
  323. msg.hgadMsg = GetHandle();
  324. <repeat:iParam,$<num_params>>
  325. msg.m_$<param> = $<param>;
  326. </repeat>
  327. (m_pfnMethod)(&msg);
  328. <if:"$<func_type>"!="void">
  329. return msg.m_result;
  330. </if>
  331. </if> ; $<func> != OnEvent
  332. } else {
  333. <if:"$<func_type>"!="void">
  334. return \
  335. </if>
  336. S$<class>::Api$<func>(\
  337. <repeat:iParam,$<num_params>>
  338. $<param>\
  339. <if:! #last iParam>
  340. , \
  341. </if>
  342. </repeat>
  343. );
  344. };
  345. }
  346. </repeat> ; iFunc
  347. </repeat> ; iClass
  348. </outfile>