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.

764 lines
19 KiB

  1. <outfile:stub.h>
  2. /***************************************************************************\\
  3. *
  4. * Generated by GIDL on $<date> at $<time>
  5. *
  6. * Stub class portion
  7. * Target = $<target>
  8. *
  9. \***************************************************************************/
  10. #pragma once
  11. #include "Gadget.h"
  12. // Forward Declarations
  13. <repeat:iClass,$<classes.count>>
  14. $<namespace.open>
  15. class $<class>;
  16. $<namespace.close>
  17. </repeat>
  18. // Stub implementations
  19. <repeat:iClass,$<classes.count>>
  20. //---------------------------------------------------------------------------
  21. //
  22. // Stub class $<class.full>
  23. //
  24. $<namespace.open>
  25. <if:"$<super>"=="">
  26. class $<class> : public DUser::Gadget
  27. </if>
  28. <if:"$<super>"!="">
  29. class $<class> : public $<super.full>
  30. </if>
  31. {
  32. public:
  33. static BOOL Init();
  34. static inline $<class> * Build(DUser::Gadget::ConstructInfo * pciData = NULL)
  35. {
  36. $<class> * pctl = reinterpret_cast<$<class> *> (DUserBuildGadget(s_hclMe, pciData));
  37. return pctl;
  38. }
  39. static inline BOOL InstanceOf(const DUser::Gadget * pg)
  40. {
  41. return DUserInstanceOf(const_cast<DUser::Gadget *> (pg), s_hclMe);
  42. }
  43. static inline $<class> * Cast(const DUser::Gadget * pg)
  44. {
  45. return reinterpret_cast<$<class> *> (DUserCastClass(const_cast<DUser::Gadget *> (pg), s_hclMe));
  46. }
  47. static inline $<class> * Cast(HGADGET hgad)
  48. {
  49. return Cast(DUserCastDirect(hgad));
  50. }
  51. static HCLASS GetClass()
  52. {
  53. ASSERT(s_hclMe != NULL); // Ensure class is properly initialized
  54. return s_hclMe;
  55. }
  56. $<helper>
  57. // Convenience wrappers
  58. <repeat:iFunc,$<funcs.count>>
  59. <if:$<func.isInherited>=="false">
  60. inline dapi $<func.return> $<func.short>($<params.proto>)
  61. { ASSERT(IsInsideContext(GetHandle()));
  62. \
  63. <if:"$<func.return>"!="void">
  64. return \
  65. </if>
  66. Call$<func.short>($<params.call>);
  67. }
  68. </if> ; !isInherited
  69. </repeat> ; iFunc
  70. // Call API's- direct invocation
  71. <repeat:iFunc,$<funcs.count>>
  72. <if:$<func.isInherited>=="false">
  73. dapi $<func.return> Call$<func.short>($<params.proto>);
  74. </if>
  75. </repeat> ; iFunc
  76. // Send API's- wrappers around DUserSendMethod()
  77. <repeat:iFunc,$<funcs.count>>
  78. <if:$<func.isInherited>=="false">
  79. $<func.return> Send$<func.short>($<params.proto>);
  80. </if> ; !isInherited
  81. </repeat> ; iFunc
  82. // Post API's- wrappers around DUserPostMethod()
  83. <repeat:iFunc,$<funcs.count>>
  84. <if:$<func.isInherited>=="false">
  85. void Post$<func.short>($<params.proto>);
  86. </if> ; !isInherited
  87. </repeat> ; iFunc
  88. // Message structures
  89. <repeat:iFunc,$<funcs.count>>
  90. <if:$<func.isInherited>=="false">
  91. struct GMSG_$<func.short> : public MethodMsg
  92. {
  93. <repeat:iParam,$<params.count>>
  94. $<param.type> m_$<param>;
  95. </repeat>
  96. <if:"$<func.return>"!="void">
  97. $<func.return> m_result;
  98. </if>
  99. };
  100. </if> : !isInherited
  101. </repeat> ; iFunc
  102. protected:
  103. static HCLASS s_hclMe;
  104. static DUser::MessageClassStub s_mc;
  105. }; // stub class $<class.full>
  106. <if:$<funcs.count>!=0>
  107. DUser::MessageInfoStub s_rgmi$<class>[];
  108. </if>
  109. $<namespace.close>
  110. </repeat> ; iClass
  111. //
  112. // Setup a class to automatically initialize the stubs.
  113. //
  114. class InitStub
  115. {
  116. public:
  117. InitStub();
  118. };
  119. </outfile>
  120. <outfile:stub.cpp>
  121. /***************************************************************************\\
  122. *
  123. * Generated by GIDL on $<date> at $<time>
  124. *
  125. * Stub class portion
  126. * Target = $<target>
  127. *
  128. \***************************************************************************/
  129. #include "stdafx.h"
  130. <if:"$<project>"!="">
  131. #include "$<project>"
  132. </if>
  133. #include "stub.h"
  134. #pragma warning(disable:4100) // unreferenced formal parameter
  135. using namespace DUser;
  136. <repeat:iClass,$<classes.count>>
  137. /***************************************************************************\\
  138. *
  139. * class $<class.full>
  140. *
  141. \***************************************************************************/
  142. $<namespace.open>
  143. HCLASS $<class>::s_hclMe = NULL;
  144. MessageClassStub $<class>::s_mc;
  145. <if:$<funcs.count>!=0>
  146. MessageInfoStub s_rgmi$<class>[] = {
  147. <repeat:iFunc,$<funcs.count>>
  148. { -1, L"$<func.short>" },
  149. </repeat>
  150. };
  151. </if>
  152. //---------------------------------------------------------------------------
  153. BOOL $<class>::Init()
  154. {
  155. ZeroMemory(&s_mc, sizeof(s_mc));
  156. s_mc.cbSize = sizeof(s_mc);
  157. s_mc.nClassVersion = $<class.version>;
  158. s_mc.pszClassName = L"$<class.full>";
  159. <if:$<funcs.count>==0>
  160. s_mc.rgMsgInfo = NULL;
  161. </if>
  162. <if:$<funcs.count>!=0>
  163. s_mc.rgMsgInfo = s_rgmi$<class>;
  164. </if>
  165. s_mc.cMsgs = $<funcs.count>;
  166. s_hclMe = DUserRegisterStub(&s_mc);
  167. return s_hclMe != NULL;
  168. }
  169. <if:$<target>=="x86">
  170. <repeat:iFunc,$<funcs.count>>
  171. <if:$<func.isInherited>=="false">
  172. //---------------------------------------------------------------------------
  173. __declspec(naked)
  174. $<func.return>
  175. $<class>::Call$<func.short>($<params.proto>)
  176. {
  177. <repeat:iParam,$<params.count>>
  178. UNREFERENCED_PARAMETER($<param>);
  179. </repeat>
  180. {
  181. __asm
  182. {
  183. lea eax, s_rgmi$<class>;
  184. mov edx, dword ptr [ecx]; // edx = start of message table
  185. add edx, dword ptr [eax + ($<iFunc> * SIZE MessageInfoStub) + 0];
  186. // edx = MsgSlot for msg
  187. mov eax, dword ptr [edx + 4]; // ecx = cbThisOffset
  188. mov ecx, dword ptr [ecx + 4]; // eax = start of 'this' array
  189. add eax, ecx; // ecx = &'this' ptr
  190. mov edx, dword ptr [edx + 0]; // edx = get function ptr
  191. mov ecx, dword ptr [eax]; // ecx = 'this' ptr
  192. jmp edx; // jump (call will mess stack up)
  193. };
  194. }
  195. } // end $<class>::$<func.short>
  196. </if> ; !func.isInherited
  197. </repeat> ; iFunc
  198. </if> ; $<target>=="x86">
  199. <if:$<target>!="x86">
  200. class Dummy$<class>
  201. {
  202. public:
  203. };
  204. <repeat:iFunc,$<funcs.count>>
  205. <if:$<func.isInherited>=="false">
  206. //---------------------------------------------------------------------------
  207. $<func.return>
  208. $<class>::Call$<func.short>($<params.proto>)
  209. {
  210. BYTE * pdwData = reinterpret_cast<BYTE *> (this);
  211. MessageInfoStub * pStub = &s_rgmi$<class>[$<iFunc>];
  212. BYTE * pbMT = * (reinterpret_cast<BYTE **> (pdwData));
  213. BYTE * pbrgThis = * (reinterpret_cast<BYTE **> (pdwData + sizeof(void *)));
  214. BYTE * pbSlot = (reinterpret_cast<BYTE *> (pbMT + pStub->cbSlotOffset));
  215. int cbThisOffset= * (reinterpret_cast<int *> (pbSlot + sizeof(void *)));
  216. union
  217. {
  218. $<func.return> (Dummy$<class>::*pfn$<func.short>)($<params.proto>);
  219. void * pfn;
  220. };
  221. pfn = * (reinterpret_cast<void **> (pbSlot));
  222. void * pvThis = * (reinterpret_cast<void **> (pbrgThis + cbThisOffset));
  223. Dummy$<class> * pDummy
  224. = reinterpret_cast<Dummy$<class> *> (pvThis);
  225. <if:"$<func.return>"!="void">
  226. return \
  227. </if>
  228. (pDummy->*pfn$<func.short>)($<params.call>);
  229. } // end $<class>::$<func.short>
  230. </if> ; !func.isInherited
  231. </repeat> ; iFunc
  232. </if> ; $<target>=="ALL">
  233. <repeat:iFunc,$<funcs.count>>
  234. <if:$<func.isInherited>=="false">
  235. //---------------------------------------------------------------------------
  236. $<func.return>
  237. $<class>::Send$<func.short>($<params.proto>)
  238. {
  239. GMSG_$<func.short> msg;
  240. msg.cbSize = sizeof(msg);
  241. msg.nMsg = s_rgmi$<class>[$<iFunc>].cbSlotOffset;
  242. msg.hgadMsg = GetHandle();
  243. <repeat:iParam,$<params.count>>
  244. msg.m_$<param> = $<param>;
  245. </repeat>
  246. DUserSendMethod(&msg);
  247. <if:"$<func.return>"!="void">
  248. return msg.m_result;
  249. </if> ; "$<func.return>"!="void">
  250. } // end $<class>::Send$<func.short>
  251. //---------------------------------------------------------------------------
  252. void
  253. $<class>::Post$<func.short>($<params.proto>)
  254. {
  255. GMSG_$<func.short> msg;
  256. msg.cbSize = sizeof(msg);
  257. msg.nMsg = s_rgmi$<class>[$<iFunc>].cbSlotOffset;
  258. msg.hgadMsg = GetHandle();
  259. <repeat:iParam,$<params.count>>
  260. msg.m_$<param> = $<param>;
  261. </repeat>
  262. DUserPostMethod(&msg);
  263. } // end $<class>::Post$<func.short>
  264. </if> ; $<func.isInherited>=="false">
  265. </repeat> ; iFunc
  266. $<namespace.close>
  267. </repeat> ; iClass
  268. //
  269. // Setup a class to automatically initialize the stubs.
  270. //
  271. InitStub::InitStub()
  272. {
  273. <repeat:iClass,$<classes.count>>
  274. $<class.full>::Init();
  275. </repeat>
  276. }
  277. #ifndef DUSER_EXPORTS
  278. InitStub g_InitStub;
  279. #endif
  280. </outfile>
  281. <outfile:super.h>
  282. /***************************************************************************\\
  283. *
  284. * Generated by GIDL on $<date> at $<time>
  285. *
  286. * Super class portion
  287. * Target = $<target>
  288. *
  289. \***************************************************************************/
  290. #pragma once
  291. #include "stub.h"
  292. #include "Gadget.h"
  293. // Forward Declarations
  294. <repeat:iClass,$<classes.count>>
  295. $<namespace.open>
  296. class S$<class>;
  297. $<namespace.close>
  298. </repeat>
  299. /***************************************************************************\\
  300. *
  301. * Implementation class helpers
  302. *
  303. \***************************************************************************/
  304. <repeat:iClass,$<classes.count>>
  305. //---------------------------------------------------------------------------
  306. //
  307. // Implementation class $<class.full>
  308. //
  309. $<namespace.open>
  310. template <class T, class base>
  311. class $<class>Impl : public base
  312. {
  313. public:
  314. static BOOL Init$<class.string>()
  315. {
  316. if (FAILED(T::InitClass())) {
  317. return FALSE;
  318. }
  319. <if:"$<super>"!="">
  320. if (!$<super.namespace>::S$<super.short>::Init$<super.string>()) {
  321. return FALSE;
  322. }
  323. </if>
  324. ZeroMemory(&s_mc, sizeof(s_mc));
  325. s_mc.cbSize = sizeof(s_mc);
  326. s_mc.nClassVersion = $<class.version>;
  327. s_mc.pszClassName = L"$<class.full>";
  328. s_mc.pszSuperName = L"$<super.full>";
  329. s_mc.rgMsgInfo = s_rgmi;
  330. s_mc.cMsgs = $<funcs.count>;
  331. s_mc.pfnPromote = T::Promote$<class>;
  332. s_mc.pfnDemote = T::Demote$<class>;
  333. return DUserRegisterGuts(&s_mc) != NULL;
  334. }
  335. static inline HRESULT
  336. InitClass()
  337. {
  338. return S_OK;
  339. }
  340. static inline HRESULT
  341. PreBuild(DUser::Gadget::ConstructInfo * pciData)
  342. {
  343. UNREFERENCED_PARAMETER(pciData);
  344. return S_OK;
  345. }
  346. inline HRESULT
  347. PostBuild(DUser::Gadget::ConstructInfo * pciData)
  348. {
  349. UNREFERENCED_PARAMETER(pciData);
  350. return S_OK;
  351. }
  352. static HRESULT CALLBACK
  353. Promote$<class>(DUser::ConstructProc pfnCS, HCLASS hclCur, DUser::Gadget * pgad, DUser::Gadget::ConstructInfo * pciData)
  354. {
  355. HRESULT hr;
  356. hr = T::PreBuild(pciData);
  357. if (FAILED(hr)) {
  358. return hr;
  359. }
  360. hr = (pfnCS)(DUser::Gadget::ccSuper, T::s_hclSuper, pgad, pciData);
  361. if (FAILED(hr)) {
  362. return hr;
  363. }
  364. T * pc = new T;
  365. if (pc == NULL) {
  366. return E_OUTOFMEMORY;
  367. }
  368. pc->m_pgad = pgad;
  369. hr = (pfnCS)(DUser::Gadget::ccSetThis, hclCur, pgad, pc);
  370. if (FAILED(hr)) {
  371. return hr;
  372. }
  373. hr = pc->PostBuild(pciData);
  374. if (FAILED(hr)) {
  375. delete pc;
  376. return E_OUTOFMEMORY;
  377. }
  378. return S_OK;
  379. }
  380. static HCLASS CALLBACK
  381. Demote$<class>(HCLASS hclCur, DUser::Gadget * pgad, void * pvData)
  382. {
  383. UNREFERENCED_PARAMETER(hclCur);
  384. UNREFERENCED_PARAMETER(pgad);
  385. T * pc = reinterpret_cast<T *> (pvData);
  386. delete pc;
  387. <if:"$<super>"!="">
  388. return T::s_hclSuper;
  389. </if>
  390. <if:"$<super>"=="">
  391. return NULL;
  392. </if>
  393. }
  394. $<class> * GetStub() const
  395. {
  396. return reinterpret_cast<$<class> *> (m_pgad);
  397. }
  398. <repeat:iFunc,$<funcs.count>>
  399. inline dapi $<func.return> Call$<func.short>($<params.proto>)
  400. { \
  401. <if:"$<func.return>"!="void">
  402. return \
  403. </if>
  404. GetStub()->Call$<func.short>($<params.call>);
  405. }
  406. </repeat> ; iFunc
  407. <repeat:iFunc,$<funcs.count>>
  408. <if:$<func.isInherited>=="false">
  409. static void CALLBACK Decode$<func.short>(DUser::Gadget * pg, MethodMsg * pmsg)
  410. {
  411. $<class>::GMSG_$<func.short> * pmsgD = ($<class>::GMSG_$<func.short> *) pmsg;
  412. $<class> * p = ($<class> *) pg;
  413. UNREFERENCED_PARAMETER(pmsgD);
  414. ASSERT($<class>::InstanceOf(pg)); // Must be of correct type
  415. <if:"$<func.return>"!="void">
  416. pmsgD->m_result = p->Call$<func.short>(\
  417. </if>
  418. <if:"$<func.return>"=="void">
  419. p->$<func.short>($<params.call>);
  420. </if>
  421. }
  422. </if>
  423. </repeat>
  424. $<helper>
  425. protected:
  426. static DUser::MessageClassGuts s_mc;
  427. public:
  428. static DUser::MessageInfoGuts s_rgmi[];
  429. }; // implementation class $<class.full>
  430. #define IMPLEMENT_GUTS_$<class.string>(me, super) \\
  431. DUser::MessageClassGuts $<class.full>Impl<me, super>::s_mc; \\
  432. DUser::MessageInfoGuts $<class.full>Impl<me, super>::s_rgmi[] = { \\
  433. <repeat:iFunc,$<funcs.count>>
  434. <if:$<func.isInherited>=="false">
  435. { member(me::Api$<func.short>), Decode$<func.short>, L"$<func.short>" }, \\
  436. </if>
  437. <if:$<func.isInherited>=="true">
  438. { member(me::Api$<func.short>) != member(super::Api$<func.short>) ? member(me::Api$<func.short>) : NULL, NULL, L"$<func.short>" }, \\
  439. </if>
  440. </repeat> ; iFunc
  441. }; \\
  442. $<namespace.close>
  443. </repeat> ; iClass
  444. /***************************************************************************\\
  445. *
  446. * Super class helpers
  447. *
  448. * NOTE: Unlike the stub class, the super class does NOT inherit from any
  449. * base class. This is because it is illegal to jump multiple levels of
  450. * inheritence and scope a function for the super's super.
  451. *
  452. \***************************************************************************/
  453. <repeat:iClass,$<classes.count>>
  454. //---------------------------------------------------------------------------
  455. //
  456. // Super class $<class.full>
  457. //
  458. $<namespace.open>
  459. <if:"$<super>"=="">
  460. class S$<class> : public DUser::SGadget
  461. </if>
  462. <if:"$<super>"!="">
  463. class S$<class> : public $<super.namespace>::S$<super.short>
  464. </if>
  465. {
  466. public:
  467. static BOOL Init$<class.string>();
  468. <repeat:iFunc,$<funcs.count>>
  469. <if:$<func.isInherited>=="false">
  470. dapi $<func.return> Api$<func.short>($<params.proto>);
  471. </if>
  472. </repeat> ; iFunc
  473. public:
  474. static HCLASS s_hclSuper; // HCLASS for THIS super-class
  475. }; // stub class $<class.full>
  476. extern DUser::MessageClassSuper
  477. s_mcsS$<class>; // Super information
  478. $<namespace.close>
  479. </repeat> ; iClass
  480. </outfile> ; super.h
  481. <outfile:super.cpp>
  482. /***************************************************************************\\
  483. *
  484. * Generated by GIDL on $<date> at $<time>
  485. *
  486. * Super class portion
  487. * Target = $<target>
  488. *
  489. \***************************************************************************/
  490. #include "stdafx.h"
  491. <if:"$<project>"!="">
  492. #include "$<project>"
  493. </if>
  494. #include "super.h"
  495. #include "stub.h"
  496. #include <stddef.h>
  497. #pragma warning(disable:4100) // unreferenced formal parameter
  498. using namespace DUser;
  499. HCLASS SGadget::s_hclSuper = NULL;
  500. <repeat:iClass,$<classes.count>>
  501. <if:"$<class.namespace>"=="">
  502. MessageClassSuper s_mcsS$<class>;
  503. </if>
  504. <if:"$<class.namespace>"!="">
  505. MessageClassSuper $<class.namespace>::s_mcsS$<class>;
  506. </if>
  507. </repeat>
  508. <repeat:iClass,$<classes.count>>
  509. /***************************************************************************\\
  510. *
  511. * class $<class.full>
  512. *
  513. \***************************************************************************/
  514. $<namespace.open>
  515. <if:$<target>=="x86">
  516. const int off$<class>Direct = offsetof(S$<class>, m_pgad);
  517. </if>
  518. HCLASS S$<class>::s_hclSuper = NULL;
  519. //---------------------------------------------------------------------------
  520. BOOL
  521. S$<class>::Init$<class.string>()
  522. {
  523. if (s_hclSuper != NULL) {
  524. return TRUE;
  525. }
  526. <if:"$<super>"!="">
  527. if (!$<super.namespace>::S$<super.short>::Init$<super.string>()) {
  528. return FALSE;
  529. }
  530. </if>
  531. ZeroMemory(&s_mcsS$<class>, sizeof(s_mcsS$<class>));
  532. s_mcsS$<class>.cbSize = sizeof(s_mcsS$<class>);
  533. s_mcsS$<class>.nClassVersion = 1;
  534. s_mcsS$<class>.pszClassName = L"$<class.full>";
  535. s_hclSuper = DUserRegisterSuper(&s_mcsS$<class>);
  536. return s_hclSuper != NULL;
  537. }
  538. <if:$<target>=="x86">
  539. <repeat:iFunc,$<funcs.count>>
  540. <if:$<func.isInherited>=="false">
  541. //---------------------------------------------------------------------------
  542. __declspec(naked)
  543. $<func.return>
  544. S$<class>::Api$<func.short>($<params.proto>)
  545. {
  546. <repeat:iParam,$<params.count>>
  547. UNREFERENCED_PARAMETER($<param>);
  548. </repeat>
  549. {
  550. __asm
  551. {
  552. add ecx, off$<class>Direct;
  553. mov eax, dword ptr [ecx]; // eax = (this->m_pgad)
  554. lea ecx, s_rgmi$<class>;
  555. mov edx, dword ptr [s_mcsS$<class>.pmt]; // edx = start of super message table
  556. add edx, dword ptr [ecx + ($<iFunc> * SIZE MessageInfoStub) + 0];
  557. // edx = MsgSlot for msg
  558. mov ecx, dword ptr [edx + 4]; // ecx = cbThisOffset
  559. mov eax, dword ptr [eax + 4]; // eax = start of 'this' array
  560. add ecx, eax; // ecx = &'this' ptr
  561. mov edx, dword ptr [edx + 0]; // edx = get function ptr
  562. mov ecx, dword ptr [ecx]; // ecx = 'this' ptr
  563. jmp edx; // jump (call will mess stack up)
  564. };
  565. }
  566. } // end $<class>::$<func.short>
  567. </if> ; !inherited
  568. </repeat> ; iFunc
  569. </if> ; $<target>=="x86">
  570. <if:$<target>!="x86">
  571. class Dummy$<class>
  572. {
  573. public:
  574. };
  575. <repeat:iFunc,$<funcs.count>>
  576. <if:$<func.isInherited>=="false">
  577. //---------------------------------------------------------------------------
  578. $<func.return>
  579. S$<class>::Api$<func.short>($<params.proto>)
  580. {
  581. BYTE * pdwData = reinterpret_cast<BYTE *> (m_pgad);
  582. MessageInfoStub * pStub = &s_rgmi$<class>[$<iFunc>];
  583. BYTE * pbMT = reinterpret_cast<BYTE *>(s_mcsS$<class>.pmt); // Get super message table
  584. BYTE * pbrgThis = * (reinterpret_cast<BYTE **> (pdwData + sizeof(void *)));
  585. BYTE * pbSlot = (reinterpret_cast<BYTE *> (pbMT + pStub->cbSlotOffset));
  586. int cbThisOffset= * (reinterpret_cast<int *> (pbSlot+ sizeof(void *)));
  587. union
  588. {
  589. $<func.return> (Dummy$<class>::*pfn$<func.short>)($<params.proto>);
  590. void * pfn;
  591. };
  592. pfn = * (reinterpret_cast<void **> (pbSlot));
  593. void * pvThis = * (reinterpret_cast<void **> (pbrgThis + cbThisOffset));
  594. Dummy$<class> * pDummy
  595. = reinterpret_cast<Dummy$<class> *> (pvThis);
  596. <if:"$<func.return>"!="void">
  597. return \
  598. </if>
  599. (pDummy->*pfn$<func.short>)($<params.call>);
  600. } // end $<class>::$<func.short>
  601. </if> ; !inherited
  602. </repeat> ; iFunc
  603. </if> ; $<target>=="ALL">
  604. $<namespace.close>
  605. </repeat> ; iClass
  606. </outfile> ; super.cpp