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.

2494 lines
63 KiB

  1. /*++
  2. Microsoft Windows
  3. Copyright (c) 1994-2000 Microsoft Corporation. All rights reserved.
  4. Module Name:
  5. factory.c
  6. Abstract:
  7. Implements the IPSFactoryBuffer interface.
  8. Author:
  9. ShannonC 12-Oct-1994
  10. Environment:
  11. Windows NT, Windows 95 and PowerMac.
  12. We do not support DOS and Win16 or Mac.
  13. Revision History:
  14. YongQu 1-Oct-1998 Unlimit vtbl
  15. --*/
  16. #define CINTERFACE
  17. #define USE_STUBLESS_PROXY
  18. #include <ndrp.h>
  19. #include <ndrole.h>
  20. #include <rpcproxy.h>
  21. //
  22. // Internal CLSCTX used for loading Proxy/Stub DLLs
  23. //
  24. #define CLSCTX_PS_DLL 0x80000000
  25. extern void ** StublessClientVtbl;
  26. EXTERN_C extern const void * g_StublessClientVtbl[];
  27. #define MAX_STUBLESS_PROC 128
  28. ULONG g_dwVtblSize = MAX_STUBLESS_PROC;
  29. ULONG g_dwForwardVtblSize = MAX_STUBLESS_PROC;
  30. static I_RPC_MUTEX TemplateMutex = 0 ,VtblMutex = 0 ;
  31. HRESULT CreateStublessProcBuffer(ULONG numMethods, void *** lpTempVtbl);
  32. HRESULT CreateForwardProcBuffer(ULONG numMethods, void *** lpTempVtbl);
  33. HRESULT STDMETHODCALLTYPE
  34. CStdPSFactoryBuffer_QueryInterface (
  35. IPSFactoryBuffer *This,
  36. REFIID iid,
  37. void **ppv );
  38. ULONG STDMETHODCALLTYPE
  39. CStdPSFactoryBuffer_AddRef(
  40. IPSFactoryBuffer *This);
  41. ULONG STDMETHODCALLTYPE
  42. CStdPSFactoryBuffer_Release(
  43. IPSFactoryBuffer *This);
  44. HRESULT STDMETHODCALLTYPE
  45. CStdPSFactoryBuffer_CreateProxy
  46. (
  47. IPSFactoryBuffer *This,
  48. IUnknown *punkOuter,
  49. REFIID riid,
  50. IRpcProxyBuffer **ppProxy,
  51. void **ppv
  52. );
  53. HRESULT STDMETHODCALLTYPE
  54. CStdPSFactoryBuffer_CreateStub
  55. (
  56. IPSFactoryBuffer *This,
  57. REFIID riid,
  58. IUnknown *punkServer,
  59. IRpcStubBuffer **ppStub
  60. );
  61. HRESULT STDMETHODCALLTYPE
  62. CStdPSFactoryBuffer_HkGetProxyFileInfo
  63. (
  64. IN IPSFactoryBuffer *This,
  65. IN REFIID riid,
  66. OUT PINT pOffset,
  67. OUT PVOID *ppProxyFileInfo
  68. );
  69. extern "C"
  70. {
  71. void STDMETHODCALLTYPE
  72. NdrProxyForwardingFunction3(void);
  73. void STDMETHODCALLTYPE
  74. NdrProxyForwardingFunction4(void);
  75. void STDMETHODCALLTYPE
  76. NdrProxyForwardingFunction5(void);
  77. void STDMETHODCALLTYPE
  78. NdrProxyForwardingFunction6(void);
  79. void STDMETHODCALLTYPE
  80. NdrProxyForwardingFunction7(void);
  81. void STDMETHODCALLTYPE
  82. NdrProxyForwardingFunction8(void);
  83. void STDMETHODCALLTYPE
  84. NdrProxyForwardingFunction9(void);
  85. void STDMETHODCALLTYPE
  86. NdrProxyForwardingFunction10(void);
  87. void STDMETHODCALLTYPE
  88. NdrProxyForwardingFunction11(void);
  89. void STDMETHODCALLTYPE
  90. NdrProxyForwardingFunction12(void);
  91. void STDMETHODCALLTYPE
  92. NdrProxyForwardingFunction13(void);
  93. void STDMETHODCALLTYPE
  94. NdrProxyForwardingFunction14(void);
  95. void STDMETHODCALLTYPE
  96. NdrProxyForwardingFunction15(void);
  97. void STDMETHODCALLTYPE
  98. NdrProxyForwardingFunction16(void);
  99. void STDMETHODCALLTYPE
  100. NdrProxyForwardingFunction17(void);
  101. void STDMETHODCALLTYPE
  102. NdrProxyForwardingFunction18(void);
  103. void STDMETHODCALLTYPE
  104. NdrProxyForwardingFunction19(void);
  105. void STDMETHODCALLTYPE
  106. NdrProxyForwardingFunction20(void);
  107. void STDMETHODCALLTYPE
  108. NdrProxyForwardingFunction21(void);
  109. void STDMETHODCALLTYPE
  110. NdrProxyForwardingFunction22(void);
  111. void STDMETHODCALLTYPE
  112. NdrProxyForwardingFunction23(void);
  113. void STDMETHODCALLTYPE
  114. NdrProxyForwardingFunction24(void);
  115. void STDMETHODCALLTYPE
  116. NdrProxyForwardingFunction25(void);
  117. void STDMETHODCALLTYPE
  118. NdrProxyForwardingFunction26(void);
  119. void STDMETHODCALLTYPE
  120. NdrProxyForwardingFunction27(void);
  121. void STDMETHODCALLTYPE
  122. NdrProxyForwardingFunction28(void);
  123. void STDMETHODCALLTYPE
  124. NdrProxyForwardingFunction29(void);
  125. void STDMETHODCALLTYPE
  126. NdrProxyForwardingFunction30(void);
  127. void STDMETHODCALLTYPE
  128. NdrProxyForwardingFunction31(void);
  129. void STDMETHODCALLTYPE
  130. NdrProxyForwardingFunction32(void);
  131. void STDMETHODCALLTYPE
  132. NdrProxyForwardingFunction33(void);
  133. void STDMETHODCALLTYPE
  134. NdrProxyForwardingFunction34(void);
  135. void STDMETHODCALLTYPE
  136. NdrProxyForwardingFunction35(void);
  137. void STDMETHODCALLTYPE
  138. NdrProxyForwardingFunction36(void);
  139. void STDMETHODCALLTYPE
  140. NdrProxyForwardingFunction37(void);
  141. void STDMETHODCALLTYPE
  142. NdrProxyForwardingFunction38(void);
  143. void STDMETHODCALLTYPE
  144. NdrProxyForwardingFunction39(void);
  145. void STDMETHODCALLTYPE
  146. NdrProxyForwardingFunction40(void);
  147. void STDMETHODCALLTYPE
  148. NdrProxyForwardingFunction41(void);
  149. void STDMETHODCALLTYPE
  150. NdrProxyForwardingFunction42(void);
  151. void STDMETHODCALLTYPE
  152. NdrProxyForwardingFunction43(void);
  153. void STDMETHODCALLTYPE
  154. NdrProxyForwardingFunction44(void);
  155. void STDMETHODCALLTYPE
  156. NdrProxyForwardingFunction45(void);
  157. void STDMETHODCALLTYPE
  158. NdrProxyForwardingFunction46(void);
  159. void STDMETHODCALLTYPE
  160. NdrProxyForwardingFunction47(void);
  161. void STDMETHODCALLTYPE
  162. NdrProxyForwardingFunction48(void);
  163. void STDMETHODCALLTYPE
  164. NdrProxyForwardingFunction49(void);
  165. void STDMETHODCALLTYPE
  166. NdrProxyForwardingFunction50(void);
  167. void STDMETHODCALLTYPE
  168. NdrProxyForwardingFunction51(void);
  169. void STDMETHODCALLTYPE
  170. NdrProxyForwardingFunction52(void);
  171. void STDMETHODCALLTYPE
  172. NdrProxyForwardingFunction53(void);
  173. void STDMETHODCALLTYPE
  174. NdrProxyForwardingFunction54(void);
  175. void STDMETHODCALLTYPE
  176. NdrProxyForwardingFunction55(void);
  177. void STDMETHODCALLTYPE
  178. NdrProxyForwardingFunction56(void);
  179. void STDMETHODCALLTYPE
  180. NdrProxyForwardingFunction57(void);
  181. void STDMETHODCALLTYPE
  182. NdrProxyForwardingFunction58(void);
  183. void STDMETHODCALLTYPE
  184. NdrProxyForwardingFunction59(void);
  185. void STDMETHODCALLTYPE
  186. NdrProxyForwardingFunction60(void);
  187. void STDMETHODCALLTYPE
  188. NdrProxyForwardingFunction61(void);
  189. void STDMETHODCALLTYPE
  190. NdrProxyForwardingFunction62(void);
  191. void STDMETHODCALLTYPE
  192. NdrProxyForwardingFunction63(void);
  193. void STDMETHODCALLTYPE
  194. NdrProxyForwardingFunction64(void);
  195. void STDMETHODCALLTYPE
  196. NdrProxyForwardingFunction65(void);
  197. void STDMETHODCALLTYPE
  198. NdrProxyForwardingFunction66(void);
  199. void STDMETHODCALLTYPE
  200. NdrProxyForwardingFunction67(void);
  201. void STDMETHODCALLTYPE
  202. NdrProxyForwardingFunction68(void);
  203. void STDMETHODCALLTYPE
  204. NdrProxyForwardingFunction69(void);
  205. void STDMETHODCALLTYPE
  206. NdrProxyForwardingFunction70(void);
  207. void STDMETHODCALLTYPE
  208. NdrProxyForwardingFunction71(void);
  209. void STDMETHODCALLTYPE
  210. NdrProxyForwardingFunction72(void);
  211. void STDMETHODCALLTYPE
  212. NdrProxyForwardingFunction73(void);
  213. void STDMETHODCALLTYPE
  214. NdrProxyForwardingFunction74(void);
  215. void STDMETHODCALLTYPE
  216. NdrProxyForwardingFunction75(void);
  217. void STDMETHODCALLTYPE
  218. NdrProxyForwardingFunction76(void);
  219. void STDMETHODCALLTYPE
  220. NdrProxyForwardingFunction77(void);
  221. void STDMETHODCALLTYPE
  222. NdrProxyForwardingFunction78(void);
  223. void STDMETHODCALLTYPE
  224. NdrProxyForwardingFunction79(void);
  225. void STDMETHODCALLTYPE
  226. NdrProxyForwardingFunction80(void);
  227. void STDMETHODCALLTYPE
  228. NdrProxyForwardingFunction81(void);
  229. void STDMETHODCALLTYPE
  230. NdrProxyForwardingFunction82(void);
  231. void STDMETHODCALLTYPE
  232. NdrProxyForwardingFunction83(void);
  233. void STDMETHODCALLTYPE
  234. NdrProxyForwardingFunction84(void);
  235. void STDMETHODCALLTYPE
  236. NdrProxyForwardingFunction85(void);
  237. void STDMETHODCALLTYPE
  238. NdrProxyForwardingFunction86(void);
  239. void STDMETHODCALLTYPE
  240. NdrProxyForwardingFunction87(void);
  241. void STDMETHODCALLTYPE
  242. NdrProxyForwardingFunction88(void);
  243. void STDMETHODCALLTYPE
  244. NdrProxyForwardingFunction89(void);
  245. void STDMETHODCALLTYPE
  246. NdrProxyForwardingFunction90(void);
  247. void STDMETHODCALLTYPE
  248. NdrProxyForwardingFunction91(void);
  249. void STDMETHODCALLTYPE
  250. NdrProxyForwardingFunction92(void);
  251. void STDMETHODCALLTYPE
  252. NdrProxyForwardingFunction93(void);
  253. void STDMETHODCALLTYPE
  254. NdrProxyForwardingFunction94(void);
  255. void STDMETHODCALLTYPE
  256. NdrProxyForwardingFunction95(void);
  257. void STDMETHODCALLTYPE
  258. NdrProxyForwardingFunction96(void);
  259. void STDMETHODCALLTYPE
  260. NdrProxyForwardingFunction97(void);
  261. void STDMETHODCALLTYPE
  262. NdrProxyForwardingFunction98(void);
  263. void STDMETHODCALLTYPE
  264. NdrProxyForwardingFunction99(void);
  265. void STDMETHODCALLTYPE
  266. NdrProxyForwardingFunction100(void);
  267. void STDMETHODCALLTYPE
  268. NdrProxyForwardingFunction101(void);
  269. void STDMETHODCALLTYPE
  270. NdrProxyForwardingFunction102(void);
  271. void STDMETHODCALLTYPE
  272. NdrProxyForwardingFunction103(void);
  273. void STDMETHODCALLTYPE
  274. NdrProxyForwardingFunction104(void);
  275. void STDMETHODCALLTYPE
  276. NdrProxyForwardingFunction105(void);
  277. void STDMETHODCALLTYPE
  278. NdrProxyForwardingFunction106(void);
  279. void STDMETHODCALLTYPE
  280. NdrProxyForwardingFunction107(void);
  281. void STDMETHODCALLTYPE
  282. NdrProxyForwardingFunction108(void);
  283. void STDMETHODCALLTYPE
  284. NdrProxyForwardingFunction109(void);
  285. void STDMETHODCALLTYPE
  286. NdrProxyForwardingFunction110(void);
  287. void STDMETHODCALLTYPE
  288. NdrProxyForwardingFunction111(void);
  289. void STDMETHODCALLTYPE
  290. NdrProxyForwardingFunction112(void);
  291. void STDMETHODCALLTYPE
  292. NdrProxyForwardingFunction113(void);
  293. void STDMETHODCALLTYPE
  294. NdrProxyForwardingFunction114(void);
  295. void STDMETHODCALLTYPE
  296. NdrProxyForwardingFunction115(void);
  297. void STDMETHODCALLTYPE
  298. NdrProxyForwardingFunction116(void);
  299. void STDMETHODCALLTYPE
  300. NdrProxyForwardingFunction117(void);
  301. void STDMETHODCALLTYPE
  302. NdrProxyForwardingFunction118(void);
  303. void STDMETHODCALLTYPE
  304. NdrProxyForwardingFunction119(void);
  305. void STDMETHODCALLTYPE
  306. NdrProxyForwardingFunction120(void);
  307. void STDMETHODCALLTYPE
  308. NdrProxyForwardingFunction121(void);
  309. void STDMETHODCALLTYPE
  310. NdrProxyForwardingFunction122(void);
  311. void STDMETHODCALLTYPE
  312. NdrProxyForwardingFunction123(void);
  313. void STDMETHODCALLTYPE
  314. NdrProxyForwardingFunction124(void);
  315. void STDMETHODCALLTYPE
  316. NdrProxyForwardingFunction125(void);
  317. void STDMETHODCALLTYPE
  318. NdrProxyForwardingFunction126(void);
  319. void STDMETHODCALLTYPE
  320. NdrProxyForwardingFunction127(void);
  321. #if defined(_AMD64_) || defined(_IA64_)
  322. void STDMETHODCALLTYPE
  323. NdrProxyForwardingFunction128(void);
  324. void STDMETHODCALLTYPE
  325. NdrProxyForwardingFunction129(void);
  326. void STDMETHODCALLTYPE
  327. NdrProxyForwardingFunction130(void);
  328. void STDMETHODCALLTYPE
  329. NdrProxyForwardingFunction131(void);
  330. void STDMETHODCALLTYPE
  331. NdrProxyForwardingFunction132(void);
  332. void STDMETHODCALLTYPE
  333. NdrProxyForwardingFunction133(void);
  334. void STDMETHODCALLTYPE
  335. NdrProxyForwardingFunction134(void);
  336. void STDMETHODCALLTYPE
  337. NdrProxyForwardingFunction135(void);
  338. void STDMETHODCALLTYPE
  339. NdrProxyForwardingFunction136(void);
  340. void STDMETHODCALLTYPE
  341. NdrProxyForwardingFunction137(void);
  342. void STDMETHODCALLTYPE
  343. NdrProxyForwardingFunction138(void);
  344. void STDMETHODCALLTYPE
  345. NdrProxyForwardingFunction139(void);
  346. void STDMETHODCALLTYPE
  347. NdrProxyForwardingFunction140(void);
  348. void STDMETHODCALLTYPE
  349. NdrProxyForwardingFunction141(void);
  350. void STDMETHODCALLTYPE
  351. NdrProxyForwardingFunction142(void);
  352. void STDMETHODCALLTYPE
  353. NdrProxyForwardingFunction143(void);
  354. void STDMETHODCALLTYPE
  355. NdrProxyForwardingFunction144(void);
  356. void STDMETHODCALLTYPE
  357. NdrProxyForwardingFunction145(void);
  358. void STDMETHODCALLTYPE
  359. NdrProxyForwardingFunction146(void);
  360. void STDMETHODCALLTYPE
  361. NdrProxyForwardingFunction147(void);
  362. void STDMETHODCALLTYPE
  363. NdrProxyForwardingFunction148(void);
  364. void STDMETHODCALLTYPE
  365. NdrProxyForwardingFunction149(void);
  366. void STDMETHODCALLTYPE
  367. NdrProxyForwardingFunction150(void);
  368. void STDMETHODCALLTYPE
  369. NdrProxyForwardingFunction151(void);
  370. void STDMETHODCALLTYPE
  371. NdrProxyForwardingFunction152(void);
  372. void STDMETHODCALLTYPE
  373. NdrProxyForwardingFunction153(void);
  374. void STDMETHODCALLTYPE
  375. NdrProxyForwardingFunction154(void);
  376. void STDMETHODCALLTYPE
  377. NdrProxyForwardingFunction155(void);
  378. void STDMETHODCALLTYPE
  379. NdrProxyForwardingFunction156(void);
  380. void STDMETHODCALLTYPE
  381. NdrProxyForwardingFunction157(void);
  382. void STDMETHODCALLTYPE
  383. NdrProxyForwardingFunction158(void);
  384. void STDMETHODCALLTYPE
  385. NdrProxyForwardingFunction159(void);
  386. void STDMETHODCALLTYPE
  387. NdrProxyForwardingFunction160(void);
  388. void STDMETHODCALLTYPE
  389. NdrProxyForwardingFunction161(void);
  390. void STDMETHODCALLTYPE
  391. NdrProxyForwardingFunction162(void);
  392. void STDMETHODCALLTYPE
  393. NdrProxyForwardingFunction163(void);
  394. void STDMETHODCALLTYPE
  395. NdrProxyForwardingFunction164(void);
  396. void STDMETHODCALLTYPE
  397. NdrProxyForwardingFunction165(void);
  398. void STDMETHODCALLTYPE
  399. NdrProxyForwardingFunction166(void);
  400. void STDMETHODCALLTYPE
  401. NdrProxyForwardingFunction167(void);
  402. void STDMETHODCALLTYPE
  403. NdrProxyForwardingFunction168(void);
  404. void STDMETHODCALLTYPE
  405. NdrProxyForwardingFunction169(void);
  406. void STDMETHODCALLTYPE
  407. NdrProxyForwardingFunction170(void);
  408. void STDMETHODCALLTYPE
  409. NdrProxyForwardingFunction171(void);
  410. void STDMETHODCALLTYPE
  411. NdrProxyForwardingFunction172(void);
  412. void STDMETHODCALLTYPE
  413. NdrProxyForwardingFunction173(void);
  414. void STDMETHODCALLTYPE
  415. NdrProxyForwardingFunction174(void);
  416. void STDMETHODCALLTYPE
  417. NdrProxyForwardingFunction175(void);
  418. void STDMETHODCALLTYPE
  419. NdrProxyForwardingFunction176(void);
  420. void STDMETHODCALLTYPE
  421. NdrProxyForwardingFunction177(void);
  422. void STDMETHODCALLTYPE
  423. NdrProxyForwardingFunction178(void);
  424. void STDMETHODCALLTYPE
  425. NdrProxyForwardingFunction179(void);
  426. void STDMETHODCALLTYPE
  427. NdrProxyForwardingFunction180(void);
  428. void STDMETHODCALLTYPE
  429. NdrProxyForwardingFunction181(void);
  430. void STDMETHODCALLTYPE
  431. NdrProxyForwardingFunction182(void);
  432. void STDMETHODCALLTYPE
  433. NdrProxyForwardingFunction183(void);
  434. void STDMETHODCALLTYPE
  435. NdrProxyForwardingFunction184(void);
  436. void STDMETHODCALLTYPE
  437. NdrProxyForwardingFunction185(void);
  438. void STDMETHODCALLTYPE
  439. NdrProxyForwardingFunction186(void);
  440. void STDMETHODCALLTYPE
  441. NdrProxyForwardingFunction187(void);
  442. void STDMETHODCALLTYPE
  443. NdrProxyForwardingFunction188(void);
  444. void STDMETHODCALLTYPE
  445. NdrProxyForwardingFunction189(void);
  446. void STDMETHODCALLTYPE
  447. NdrProxyForwardingFunction190(void);
  448. void STDMETHODCALLTYPE
  449. NdrProxyForwardingFunction191(void);
  450. void STDMETHODCALLTYPE
  451. NdrProxyForwardingFunction192(void);
  452. void STDMETHODCALLTYPE
  453. NdrProxyForwardingFunction193(void);
  454. void STDMETHODCALLTYPE
  455. NdrProxyForwardingFunction194(void);
  456. void STDMETHODCALLTYPE
  457. NdrProxyForwardingFunction195(void);
  458. void STDMETHODCALLTYPE
  459. NdrProxyForwardingFunction196(void);
  460. void STDMETHODCALLTYPE
  461. NdrProxyForwardingFunction197(void);
  462. void STDMETHODCALLTYPE
  463. NdrProxyForwardingFunction198(void);
  464. void STDMETHODCALLTYPE
  465. NdrProxyForwardingFunction199(void);
  466. void STDMETHODCALLTYPE
  467. NdrProxyForwardingFunction200(void);
  468. void STDMETHODCALLTYPE
  469. NdrProxyForwardingFunction201(void);
  470. void STDMETHODCALLTYPE
  471. NdrProxyForwardingFunction202(void);
  472. void STDMETHODCALLTYPE
  473. NdrProxyForwardingFunction203(void);
  474. void STDMETHODCALLTYPE
  475. NdrProxyForwardingFunction204(void);
  476. void STDMETHODCALLTYPE
  477. NdrProxyForwardingFunction205(void);
  478. void STDMETHODCALLTYPE
  479. NdrProxyForwardingFunction206(void);
  480. void STDMETHODCALLTYPE
  481. NdrProxyForwardingFunction207(void);
  482. void STDMETHODCALLTYPE
  483. NdrProxyForwardingFunction208(void);
  484. void STDMETHODCALLTYPE
  485. NdrProxyForwardingFunction209(void);
  486. void STDMETHODCALLTYPE
  487. NdrProxyForwardingFunction210(void);
  488. void STDMETHODCALLTYPE
  489. NdrProxyForwardingFunction211(void);
  490. void STDMETHODCALLTYPE
  491. NdrProxyForwardingFunction212(void);
  492. void STDMETHODCALLTYPE
  493. NdrProxyForwardingFunction213(void);
  494. void STDMETHODCALLTYPE
  495. NdrProxyForwardingFunction214(void);
  496. void STDMETHODCALLTYPE
  497. NdrProxyForwardingFunction215(void);
  498. void STDMETHODCALLTYPE
  499. NdrProxyForwardingFunction216(void);
  500. void STDMETHODCALLTYPE
  501. NdrProxyForwardingFunction217(void);
  502. void STDMETHODCALLTYPE
  503. NdrProxyForwardingFunction218(void);
  504. void STDMETHODCALLTYPE
  505. NdrProxyForwardingFunction219(void);
  506. void STDMETHODCALLTYPE
  507. NdrProxyForwardingFunction220(void);
  508. void STDMETHODCALLTYPE
  509. NdrProxyForwardingFunction221(void);
  510. void STDMETHODCALLTYPE
  511. NdrProxyForwardingFunction222(void);
  512. void STDMETHODCALLTYPE
  513. NdrProxyForwardingFunction223(void);
  514. void STDMETHODCALLTYPE
  515. NdrProxyForwardingFunction224(void);
  516. void STDMETHODCALLTYPE
  517. NdrProxyForwardingFunction225(void);
  518. void STDMETHODCALLTYPE
  519. NdrProxyForwardingFunction226(void);
  520. void STDMETHODCALLTYPE
  521. NdrProxyForwardingFunction227(void);
  522. void STDMETHODCALLTYPE
  523. NdrProxyForwardingFunction228(void);
  524. void STDMETHODCALLTYPE
  525. NdrProxyForwardingFunction229(void);
  526. void STDMETHODCALLTYPE
  527. NdrProxyForwardingFunction230(void);
  528. void STDMETHODCALLTYPE
  529. NdrProxyForwardingFunction231(void);
  530. void STDMETHODCALLTYPE
  531. NdrProxyForwardingFunction232(void);
  532. void STDMETHODCALLTYPE
  533. NdrProxyForwardingFunction233(void);
  534. void STDMETHODCALLTYPE
  535. NdrProxyForwardingFunction234(void);
  536. void STDMETHODCALLTYPE
  537. NdrProxyForwardingFunction235(void);
  538. void STDMETHODCALLTYPE
  539. NdrProxyForwardingFunction236(void);
  540. void STDMETHODCALLTYPE
  541. NdrProxyForwardingFunction237(void);
  542. void STDMETHODCALLTYPE
  543. NdrProxyForwardingFunction238(void);
  544. void STDMETHODCALLTYPE
  545. NdrProxyForwardingFunction239(void);
  546. void STDMETHODCALLTYPE
  547. NdrProxyForwardingFunction240(void);
  548. void STDMETHODCALLTYPE
  549. NdrProxyForwardingFunction241(void);
  550. void STDMETHODCALLTYPE
  551. NdrProxyForwardingFunction242(void);
  552. void STDMETHODCALLTYPE
  553. NdrProxyForwardingFunction243(void);
  554. void STDMETHODCALLTYPE
  555. NdrProxyForwardingFunction244(void);
  556. void STDMETHODCALLTYPE
  557. NdrProxyForwardingFunction245(void);
  558. void STDMETHODCALLTYPE
  559. NdrProxyForwardingFunction246(void);
  560. void STDMETHODCALLTYPE
  561. NdrProxyForwardingFunction247(void);
  562. void STDMETHODCALLTYPE
  563. NdrProxyForwardingFunction248(void);
  564. void STDMETHODCALLTYPE
  565. NdrProxyForwardingFunction249(void);
  566. void STDMETHODCALLTYPE
  567. NdrProxyForwardingFunction250(void);
  568. void STDMETHODCALLTYPE
  569. NdrProxyForwardingFunction251(void);
  570. void STDMETHODCALLTYPE
  571. NdrProxyForwardingFunction252(void);
  572. void STDMETHODCALLTYPE
  573. NdrProxyForwardingFunction253(void);
  574. void STDMETHODCALLTYPE
  575. NdrProxyForwardingFunction254(void);
  576. void STDMETHODCALLTYPE
  577. NdrProxyForwardingFunction255(void);
  578. #endif // defined(_AMD64_) || defined(_IA64_)
  579. }
  580. //+-------------------------------------------------------------------------
  581. //
  582. // Global data
  583. //
  584. //--------------------------------------------------------------------------
  585. // Hook Factory
  586. extern const IPSFactoryHookVtbl CStdPSFactoryBufferVtbl = {
  587. CStdPSFactoryBuffer_QueryInterface,
  588. CStdPSFactoryBuffer_AddRef,
  589. CStdPSFactoryBuffer_Release,
  590. CStdPSFactoryBuffer_CreateProxy,
  591. CStdPSFactoryBuffer_CreateStub,
  592. CStdPSFactoryBuffer_HkGetProxyFileInfo };
  593. // Nondelegated synchronous StubBuffer vtable
  594. extern const IRpcStubBufferVtbl CStdStubBufferVtbl= {
  595. CStdStubBuffer_QueryInterface,
  596. CStdStubBuffer_AddRef,
  597. 0, // sync stub is not aggregated
  598. CStdStubBuffer_Connect,
  599. CStdStubBuffer_Disconnect,
  600. CStdStubBuffer_Invoke,
  601. CStdStubBuffer_IsIIDSupported,
  602. CStdStubBuffer_CountRefs,
  603. CStdStubBuffer_DebugServerQueryInterface,
  604. CStdStubBuffer_DebugServerRelease };
  605. // Delegated synchronous StubBuffer vtable
  606. extern const IRpcStubBufferVtbl CStdStubBuffer2Vtbl= {
  607. CStdStubBuffer_QueryInterface,
  608. CStdStubBuffer_AddRef,
  609. 0, // sync stub is not aggregated
  610. CStdStubBuffer2_Connect,
  611. CStdStubBuffer2_Disconnect,
  612. CStdStubBuffer_Invoke,
  613. CStdStubBuffer_IsIIDSupported,
  614. CStdStubBuffer2_CountRefs,
  615. CStdStubBuffer_DebugServerQueryInterface,
  616. CStdStubBuffer_DebugServerRelease };
  617. extern const IRpcProxyBufferVtbl CStdProxyBufferVtbl;
  618. extern const IRpcProxyBufferVtbl CStdProxyBuffer2Vtbl;
  619. extern const ICallFactoryVtbl CStdProxyBuffer_CallFactoryVtbl;
  620. extern const ICallFactoryVtbl CStdProxyBuffer2_CallFactoryVtbl;
  621. extern const ICallFactoryVtbl CStdStubBuffer_CallFactoryVtbl;
  622. extern const ICallFactoryVtbl CStdStubBuffer2_CallFactoryVtbl;
  623. extern const IReleaseMarshalBuffersVtbl CStdProxyBuffer_ReleaseMarshalBuffersVtbl;
  624. extern const IReleaseMarshalBuffersVtbl CStdStubBuffer_ReleaseMarshalBuffersVtbl;
  625. extern const IReleaseMarshalBuffersVtbl CStdAsyncProxyBuffer_ReleaseMarshalBuffersVtbl;
  626. extern const IReleaseMarshalBuffersVtbl CStdAsyncStubBuffer_ReleaseMarshalBuffersVtbl;
  627. extern const IRpcStubBufferVtbl CStdAsyncStubBufferVtbl= {
  628. CStdAsyncStubBuffer_QueryInterface,
  629. CStdAsyncStubBuffer_AddRef,
  630. CStdAsyncStubBuffer_Release,
  631. CStdAsyncStubBuffer_Connect, //
  632. CStdAsyncStubBuffer_Disconnect, //
  633. CStdAsyncStubBuffer_Invoke,
  634. CStdStubBuffer_IsIIDSupported,
  635. CStdStubBuffer_CountRefs,
  636. CStdStubBuffer_DebugServerQueryInterface,
  637. CStdStubBuffer_DebugServerRelease };
  638. extern const IRpcStubBufferVtbl CStdAsyncStubBuffer2Vtbl= {
  639. CStdAsyncStubBuffer_QueryInterface,
  640. CStdAsyncStubBuffer_AddRef,
  641. CStdAsyncStubBuffer2_Release,
  642. CStdAsyncStubBuffer2_Connect, //
  643. CStdAsyncStubBuffer2_Disconnect, //
  644. CStdAsyncStubBuffer_Invoke,
  645. CStdStubBuffer_IsIIDSupported,
  646. CStdStubBuffer2_CountRefs,
  647. CStdStubBuffer_DebugServerQueryInterface,
  648. CStdStubBuffer_DebugServerRelease };
  649. extern void * const g_ForwardingVtbl[] = {
  650. Forwarding_QueryInterface,
  651. Forwarding_AddRef,
  652. Forwarding_Release,
  653. NdrProxyForwardingFunction3,
  654. NdrProxyForwardingFunction4,
  655. NdrProxyForwardingFunction5,
  656. NdrProxyForwardingFunction6,
  657. NdrProxyForwardingFunction7,
  658. NdrProxyForwardingFunction8,
  659. NdrProxyForwardingFunction9,
  660. NdrProxyForwardingFunction10,
  661. NdrProxyForwardingFunction11,
  662. NdrProxyForwardingFunction12,
  663. NdrProxyForwardingFunction13,
  664. NdrProxyForwardingFunction14,
  665. NdrProxyForwardingFunction15,
  666. NdrProxyForwardingFunction16,
  667. NdrProxyForwardingFunction17,
  668. NdrProxyForwardingFunction18,
  669. NdrProxyForwardingFunction19,
  670. NdrProxyForwardingFunction20,
  671. NdrProxyForwardingFunction21,
  672. NdrProxyForwardingFunction22,
  673. NdrProxyForwardingFunction23,
  674. NdrProxyForwardingFunction24,
  675. NdrProxyForwardingFunction25,
  676. NdrProxyForwardingFunction26,
  677. NdrProxyForwardingFunction27,
  678. NdrProxyForwardingFunction28,
  679. NdrProxyForwardingFunction29,
  680. NdrProxyForwardingFunction30,
  681. NdrProxyForwardingFunction31,
  682. NdrProxyForwardingFunction32,
  683. NdrProxyForwardingFunction33,
  684. NdrProxyForwardingFunction34,
  685. NdrProxyForwardingFunction35,
  686. NdrProxyForwardingFunction36,
  687. NdrProxyForwardingFunction37,
  688. NdrProxyForwardingFunction38,
  689. NdrProxyForwardingFunction39,
  690. NdrProxyForwardingFunction40,
  691. NdrProxyForwardingFunction41,
  692. NdrProxyForwardingFunction42,
  693. NdrProxyForwardingFunction43,
  694. NdrProxyForwardingFunction44,
  695. NdrProxyForwardingFunction45,
  696. NdrProxyForwardingFunction46,
  697. NdrProxyForwardingFunction47,
  698. NdrProxyForwardingFunction48,
  699. NdrProxyForwardingFunction49,
  700. NdrProxyForwardingFunction50,
  701. NdrProxyForwardingFunction51,
  702. NdrProxyForwardingFunction52,
  703. NdrProxyForwardingFunction53,
  704. NdrProxyForwardingFunction54,
  705. NdrProxyForwardingFunction55,
  706. NdrProxyForwardingFunction56,
  707. NdrProxyForwardingFunction57,
  708. NdrProxyForwardingFunction58,
  709. NdrProxyForwardingFunction59,
  710. NdrProxyForwardingFunction60,
  711. NdrProxyForwardingFunction61,
  712. NdrProxyForwardingFunction62,
  713. NdrProxyForwardingFunction63,
  714. NdrProxyForwardingFunction64,
  715. NdrProxyForwardingFunction65,
  716. NdrProxyForwardingFunction66,
  717. NdrProxyForwardingFunction67,
  718. NdrProxyForwardingFunction68,
  719. NdrProxyForwardingFunction69,
  720. NdrProxyForwardingFunction70,
  721. NdrProxyForwardingFunction71,
  722. NdrProxyForwardingFunction72,
  723. NdrProxyForwardingFunction73,
  724. NdrProxyForwardingFunction74,
  725. NdrProxyForwardingFunction75,
  726. NdrProxyForwardingFunction76,
  727. NdrProxyForwardingFunction77,
  728. NdrProxyForwardingFunction78,
  729. NdrProxyForwardingFunction79,
  730. NdrProxyForwardingFunction80,
  731. NdrProxyForwardingFunction81,
  732. NdrProxyForwardingFunction82,
  733. NdrProxyForwardingFunction83,
  734. NdrProxyForwardingFunction84,
  735. NdrProxyForwardingFunction85,
  736. NdrProxyForwardingFunction86,
  737. NdrProxyForwardingFunction87,
  738. NdrProxyForwardingFunction88,
  739. NdrProxyForwardingFunction89,
  740. NdrProxyForwardingFunction90,
  741. NdrProxyForwardingFunction91,
  742. NdrProxyForwardingFunction92,
  743. NdrProxyForwardingFunction93,
  744. NdrProxyForwardingFunction94,
  745. NdrProxyForwardingFunction95,
  746. NdrProxyForwardingFunction96,
  747. NdrProxyForwardingFunction97,
  748. NdrProxyForwardingFunction98,
  749. NdrProxyForwardingFunction99,
  750. NdrProxyForwardingFunction100,
  751. NdrProxyForwardingFunction101,
  752. NdrProxyForwardingFunction102,
  753. NdrProxyForwardingFunction103,
  754. NdrProxyForwardingFunction104,
  755. NdrProxyForwardingFunction105,
  756. NdrProxyForwardingFunction106,
  757. NdrProxyForwardingFunction107,
  758. NdrProxyForwardingFunction108,
  759. NdrProxyForwardingFunction109,
  760. NdrProxyForwardingFunction110,
  761. NdrProxyForwardingFunction111,
  762. NdrProxyForwardingFunction112,
  763. NdrProxyForwardingFunction113,
  764. NdrProxyForwardingFunction114,
  765. NdrProxyForwardingFunction115,
  766. NdrProxyForwardingFunction116,
  767. NdrProxyForwardingFunction117,
  768. NdrProxyForwardingFunction118,
  769. NdrProxyForwardingFunction119,
  770. NdrProxyForwardingFunction120,
  771. NdrProxyForwardingFunction121,
  772. NdrProxyForwardingFunction122,
  773. NdrProxyForwardingFunction123,
  774. NdrProxyForwardingFunction124,
  775. NdrProxyForwardingFunction125,
  776. NdrProxyForwardingFunction126,
  777. NdrProxyForwardingFunction127
  778. #if defined (_AMD64_) || defined(_IA64_)
  779. ,
  780. NdrProxyForwardingFunction128,
  781. NdrProxyForwardingFunction129,
  782. NdrProxyForwardingFunction130,
  783. NdrProxyForwardingFunction131,
  784. NdrProxyForwardingFunction132,
  785. NdrProxyForwardingFunction133,
  786. NdrProxyForwardingFunction134,
  787. NdrProxyForwardingFunction135,
  788. NdrProxyForwardingFunction136,
  789. NdrProxyForwardingFunction137,
  790. NdrProxyForwardingFunction138,
  791. NdrProxyForwardingFunction139,
  792. NdrProxyForwardingFunction140,
  793. NdrProxyForwardingFunction141,
  794. NdrProxyForwardingFunction142,
  795. NdrProxyForwardingFunction143,
  796. NdrProxyForwardingFunction144,
  797. NdrProxyForwardingFunction145,
  798. NdrProxyForwardingFunction146,
  799. NdrProxyForwardingFunction147,
  800. NdrProxyForwardingFunction148,
  801. NdrProxyForwardingFunction149,
  802. NdrProxyForwardingFunction150,
  803. NdrProxyForwardingFunction151,
  804. NdrProxyForwardingFunction152,
  805. NdrProxyForwardingFunction153,
  806. NdrProxyForwardingFunction154,
  807. NdrProxyForwardingFunction155,
  808. NdrProxyForwardingFunction156,
  809. NdrProxyForwardingFunction157,
  810. NdrProxyForwardingFunction158,
  811. NdrProxyForwardingFunction159,
  812. NdrProxyForwardingFunction160,
  813. NdrProxyForwardingFunction161,
  814. NdrProxyForwardingFunction162,
  815. NdrProxyForwardingFunction163,
  816. NdrProxyForwardingFunction164,
  817. NdrProxyForwardingFunction165,
  818. NdrProxyForwardingFunction166,
  819. NdrProxyForwardingFunction167,
  820. NdrProxyForwardingFunction168,
  821. NdrProxyForwardingFunction169,
  822. NdrProxyForwardingFunction170,
  823. NdrProxyForwardingFunction171,
  824. NdrProxyForwardingFunction172,
  825. NdrProxyForwardingFunction173,
  826. NdrProxyForwardingFunction174,
  827. NdrProxyForwardingFunction175,
  828. NdrProxyForwardingFunction176,
  829. NdrProxyForwardingFunction177,
  830. NdrProxyForwardingFunction178,
  831. NdrProxyForwardingFunction179,
  832. NdrProxyForwardingFunction180,
  833. NdrProxyForwardingFunction181,
  834. NdrProxyForwardingFunction182,
  835. NdrProxyForwardingFunction183,
  836. NdrProxyForwardingFunction184,
  837. NdrProxyForwardingFunction185,
  838. NdrProxyForwardingFunction186,
  839. NdrProxyForwardingFunction187,
  840. NdrProxyForwardingFunction188,
  841. NdrProxyForwardingFunction189,
  842. NdrProxyForwardingFunction190,
  843. NdrProxyForwardingFunction191,
  844. NdrProxyForwardingFunction192,
  845. NdrProxyForwardingFunction193,
  846. NdrProxyForwardingFunction194,
  847. NdrProxyForwardingFunction195,
  848. NdrProxyForwardingFunction196,
  849. NdrProxyForwardingFunction197,
  850. NdrProxyForwardingFunction198,
  851. NdrProxyForwardingFunction199,
  852. NdrProxyForwardingFunction200,
  853. NdrProxyForwardingFunction201,
  854. NdrProxyForwardingFunction202,
  855. NdrProxyForwardingFunction203,
  856. NdrProxyForwardingFunction204,
  857. NdrProxyForwardingFunction205,
  858. NdrProxyForwardingFunction206,
  859. NdrProxyForwardingFunction207,
  860. NdrProxyForwardingFunction208,
  861. NdrProxyForwardingFunction209,
  862. NdrProxyForwardingFunction210,
  863. NdrProxyForwardingFunction211,
  864. NdrProxyForwardingFunction212,
  865. NdrProxyForwardingFunction213,
  866. NdrProxyForwardingFunction214,
  867. NdrProxyForwardingFunction215,
  868. NdrProxyForwardingFunction216,
  869. NdrProxyForwardingFunction217,
  870. NdrProxyForwardingFunction218,
  871. NdrProxyForwardingFunction219,
  872. NdrProxyForwardingFunction220,
  873. NdrProxyForwardingFunction221,
  874. NdrProxyForwardingFunction222,
  875. NdrProxyForwardingFunction223,
  876. NdrProxyForwardingFunction224,
  877. NdrProxyForwardingFunction225,
  878. NdrProxyForwardingFunction226,
  879. NdrProxyForwardingFunction227,
  880. NdrProxyForwardingFunction228,
  881. NdrProxyForwardingFunction229,
  882. NdrProxyForwardingFunction230,
  883. NdrProxyForwardingFunction231,
  884. NdrProxyForwardingFunction232,
  885. NdrProxyForwardingFunction233,
  886. NdrProxyForwardingFunction234,
  887. NdrProxyForwardingFunction235,
  888. NdrProxyForwardingFunction236,
  889. NdrProxyForwardingFunction237,
  890. NdrProxyForwardingFunction238,
  891. NdrProxyForwardingFunction239,
  892. NdrProxyForwardingFunction240,
  893. NdrProxyForwardingFunction241,
  894. NdrProxyForwardingFunction242,
  895. NdrProxyForwardingFunction243,
  896. NdrProxyForwardingFunction244,
  897. NdrProxyForwardingFunction245,
  898. NdrProxyForwardingFunction246,
  899. NdrProxyForwardingFunction247,
  900. NdrProxyForwardingFunction248,
  901. NdrProxyForwardingFunction249,
  902. NdrProxyForwardingFunction250,
  903. NdrProxyForwardingFunction251,
  904. NdrProxyForwardingFunction252,
  905. NdrProxyForwardingFunction253,
  906. NdrProxyForwardingFunction254,
  907. NdrProxyForwardingFunction255
  908. #endif // defined(_AMD64_) || defined(_IA64_)
  909. };
  910. void ** ProxyForwardVtbl = (void **)g_ForwardingVtbl;
  911. #pragma code_seg(".orpc")
  912. //+---------------------------------------------------------------------------
  913. //
  914. // Function: GetTemplateVtbl
  915. //
  916. // Synopsis: retrieve a copy of stublessclientvtbl and addref it.
  917. //
  918. // Arguments: void *** pppVtbl stublessclientvtbl to return.
  919. //
  920. // Note: StublessClientVtbl - sizeof(LONG) is the ref count .
  921. //
  922. // Returns:
  923. //
  924. //----------------------------------------------------------------------------
  925. void GetTemplateVtbl(void *** pppVtbl)
  926. {
  927. LPLONG pTemp;
  928. void **ppVtbl;
  929. I_RpcRequestMutex(&TemplateMutex);
  930. ppVtbl = StublessClientVtbl;
  931. pTemp = (LPLONG)ppVtbl;
  932. *pppVtbl = ppVtbl;
  933. if (ppVtbl == (void**)g_StublessClientVtbl)
  934. {
  935. I_RpcClearMutex(TemplateMutex);
  936. return ;
  937. }
  938. pTemp--;
  939. (*pTemp) ++ ;
  940. I_RpcClearMutex(TemplateMutex);
  941. }
  942. // release the vtbl, free the memory if necessary.
  943. void ReleaseTemplateVtbl(void ** pVtbl)
  944. {
  945. LPLONG pTemp;
  946. I_RpcRequestMutex(&TemplateMutex);
  947. pTemp = (LPLONG)pVtbl;
  948. if (pVtbl == (void**)g_StublessClientVtbl)
  949. {
  950. I_RpcClearMutex(TemplateMutex);
  951. return;
  952. }
  953. pTemp--;
  954. (*pTemp)--;
  955. if (0 == *pTemp )
  956. {
  957. I_RpcFree(pTemp);
  958. }
  959. I_RpcClearMutex(TemplateMutex);
  960. }
  961. //+---------------------------------------------------------------------------
  962. //
  963. // Function: GetTemplateForwardVtbl
  964. //
  965. // Synopsis: retrieve a copy of stublessclientvtbl and addref it.
  966. //
  967. // Arguments: void *** pppVtbl stublessclientvtbl to return.
  968. //
  969. // Note: StublessClientVtbl - sizeof(LONG) is the ref count .
  970. //
  971. // Returns:
  972. //
  973. //----------------------------------------------------------------------------
  974. void GetTemplateForwardVtbl(void *** pppVtbl)
  975. {
  976. LPLONG pTemp;
  977. void **ppVtbl;
  978. I_RpcRequestMutex(&TemplateMutex);
  979. ppVtbl = ProxyForwardVtbl;
  980. pTemp = (LPLONG)ppVtbl;
  981. *pppVtbl = ppVtbl;
  982. if (ppVtbl == g_ForwardingVtbl)
  983. {
  984. I_RpcClearMutex(TemplateMutex);
  985. return ;
  986. }
  987. pTemp--;
  988. (*pTemp) ++ ;
  989. I_RpcClearMutex(TemplateMutex);
  990. }
  991. // release the vtbl, free the memory if necessary.
  992. void ReleaseTemplateForwardVtbl(void ** pVtbl)
  993. {
  994. LPLONG pTemp;
  995. I_RpcRequestMutex(&TemplateMutex);
  996. pTemp = (LPLONG)pVtbl;
  997. if (pVtbl == g_ForwardingVtbl)
  998. {
  999. I_RpcClearMutex(TemplateMutex);
  1000. return;
  1001. }
  1002. pTemp--;
  1003. (*pTemp)--;
  1004. if (0 == *pTemp )
  1005. {
  1006. I_RpcFree(pTemp);
  1007. }
  1008. I_RpcClearMutex(TemplateMutex);
  1009. }
  1010. //+---------------------------------------------------------------------------
  1011. //
  1012. // Function: NdrpInitializeStublessVtbl
  1013. //
  1014. // Synopsis: Initialize a stubless vtbl list for current process. increase the size of
  1015. // vtbl link list and regenerate the vtbl array if necessary.
  1016. //
  1017. // Note: The actural vtbl size created might be larger than requested: we will fill
  1018. // in the whole block of link list .
  1019. //
  1020. // Arguments: numMethods number of methods in the interface.
  1021. //
  1022. // Returns:
  1023. // S_OK
  1024. //
  1025. //----------------------------------------------------------------------------
  1026. HRESULT NdrpInitializeStublessVtbl(ULONG numMethods)
  1027. {
  1028. void ** TempVtbl, ** pOldVtbl = NULL; // ole vtbl template to be freed.
  1029. HRESULT hr;
  1030. #if defined(_AMD64_) || defined(_IA64_)
  1031. if (numMethods <= 1024)
  1032. return S_OK;
  1033. else
  1034. return E_FAIL;
  1035. #else
  1036. if (numMethods <= MAX_STUBLESS_PROC)
  1037. return S_OK;
  1038. // request a mutex might fail because of OUT_OF_MEMORY, and exception would be thrown.
  1039. // we don't want to throw exception in ole call, so we initialize it first and catch the exceptions.
  1040. if ( VtblMutex == NULL )
  1041. {
  1042. hr = NdrpInitializeMutex( &VtblMutex );
  1043. if ( FAILED( hr ) )
  1044. return hr;
  1045. }
  1046. if ( TemplateMutex == NULL )
  1047. {
  1048. hr = NdrpInitializeMutex( &TemplateMutex );
  1049. if ( FAILED( hr ) )
  1050. return hr;
  1051. }
  1052. I_RpcRequestMutex(&VtblMutex);
  1053. if (numMethods > g_dwVtblSize)
  1054. {
  1055. // create a
  1056. hr = CreateStublessProcBuffer(numMethods,&TempVtbl);
  1057. if (FAILED(hr))
  1058. {
  1059. I_RpcClearMutex(VtblMutex);
  1060. return hr;
  1061. }
  1062. pOldVtbl = StublessClientVtbl;
  1063. StublessClientVtbl = TempVtbl;
  1064. }
  1065. I_RpcClearMutex(VtblMutex);
  1066. if (pOldVtbl)
  1067. ReleaseTemplateVtbl(pOldVtbl);
  1068. return S_OK;
  1069. #endif // defined(_AMD64_) || defined(_IA64_)
  1070. }
  1071. //+---------------------------------------------------------------------------
  1072. //
  1073. // Function: NdrpInitializeForwardVtbl
  1074. //
  1075. // Synopsis: Initialize a stubless vtbl list for current process. increase the size of
  1076. // vtbl link list and regenerate the vtbl array if necessary.
  1077. //
  1078. // Note: The actural vtbl size created might be larger than requested: we will fill
  1079. // in the whole block of link list .
  1080. //
  1081. // Arguments: numMethods number of methods in the interface.
  1082. //
  1083. // Returns:
  1084. // S_OK
  1085. //
  1086. //----------------------------------------------------------------------------
  1087. HRESULT NdrpInitializeForwardVtbl(ULONG numMethods)
  1088. {
  1089. void ** TempVtbl, ** pOldVtbl = NULL; // ole vtbl template to be freed.
  1090. HRESULT hr;
  1091. #if defined(_AMD64_) || defined(_IA64_)
  1092. if (numMethods <= 256)
  1093. return S_OK;
  1094. else
  1095. return E_FAIL;
  1096. #else
  1097. if (numMethods <= MAX_STUBLESS_PROC)
  1098. return S_OK;
  1099. I_RpcRequestMutex(&VtblMutex);
  1100. if (numMethods > g_dwForwardVtblSize)
  1101. {
  1102. // create a
  1103. hr = CreateForwardProcBuffer(numMethods,&TempVtbl);
  1104. if (FAILED(hr) )
  1105. {
  1106. I_RpcClearMutex(VtblMutex);
  1107. return hr;
  1108. }
  1109. pOldVtbl = ProxyForwardVtbl;
  1110. ProxyForwardVtbl = TempVtbl;
  1111. }
  1112. I_RpcClearMutex(VtblMutex);
  1113. if (pOldVtbl)
  1114. ReleaseTemplateForwardVtbl(pOldVtbl);
  1115. return S_OK;
  1116. #endif // defined(_AMD64_) || defined(_IA64_)
  1117. }
  1118. BOOL NdrpFindInterface(
  1119. IN const ProxyFileInfo ** pProxyFileList,
  1120. IN REFIID riid,
  1121. OUT const ProxyFileInfo ** ppProxyFileInfo,
  1122. OUT long * pIndex)
  1123. /*++
  1124. Routine Description:
  1125. Search the ProxyFileInfo and find the specified interface.
  1126. If the count is specified in the ProxyFileInfo, then the interfaces in
  1127. the file are sorted by IID. This means that we can perform a binary
  1128. search for the IID.
  1129. Arguments:
  1130. pProxyFileList - Specifies a list of proxy files to be searched.
  1131. riid - Specifies the interface ID to be found.
  1132. ppProxyFileInfo - Returns a pointer to the proxy file info.
  1133. pIndex - Returns the index of the interface in the proxy file info.
  1134. Return Value:
  1135. TRUE - The interface was found.
  1136. FALSE - The interface was not found.
  1137. --*/
  1138. {
  1139. long j;
  1140. BOOL fFound = FALSE;
  1141. ProxyFileInfo ** ppProxyFileCur;
  1142. ProxyFileInfo * pProxyFileCur;
  1143. //Search the list of proxy files.
  1144. for( ppProxyFileCur = (ProxyFileInfo **) pProxyFileList;
  1145. (*ppProxyFileCur != 0) && (fFound != TRUE);
  1146. ppProxyFileCur++)
  1147. {
  1148. //Search for the interface proxy vtable.
  1149. pProxyFileCur = *ppProxyFileCur;
  1150. // see if it has a lookup routine already
  1151. if ( ( pProxyFileCur->TableVersion >= 1 ) &&
  1152. ( pProxyFileCur->pIIDLookupRtn ) )
  1153. {
  1154. fFound = (*pProxyFileCur->pIIDLookupRtn)( &riid, (int*)&j );
  1155. }
  1156. else //Linear search.
  1157. {
  1158. for(j = 0;
  1159. (pProxyFileCur->pProxyVtblList[j] != 0);
  1160. j++)
  1161. {
  1162. if(memcmp(&riid,
  1163. pProxyFileCur->pStubVtblList[j]->header.piid,
  1164. sizeof(IID)) == 0)
  1165. {
  1166. fFound = TRUE;
  1167. break;
  1168. }
  1169. }
  1170. }
  1171. }
  1172. if ( fFound )
  1173. {
  1174. //We found the interface!
  1175. if(ppProxyFileInfo != 0)
  1176. *ppProxyFileInfo = pProxyFileCur;
  1177. if(pIndex != 0)
  1178. *pIndex = j;
  1179. }
  1180. return fFound;
  1181. }
  1182. __inline
  1183. void NdrpInitializeProxyVtbl(
  1184. CInterfaceProxyVtbl *pProxyVtbl,
  1185. unsigned long count,
  1186. BOOL IsDelegated,
  1187. unsigned short ProxyVersion)
  1188. /*++
  1189. Routine Description:
  1190. Initialize the proxy vtbl.
  1191. Arguments:
  1192. pProxyVtbl - Supplies vtbl to be initialized.
  1193. count - Supplies number of entries in the vtbl.
  1194. IsDelegated - TRUE if the interface is delegated, FALSE otherwise.
  1195. Return Value:
  1196. None.
  1197. --*/
  1198. {
  1199. unsigned long k;
  1200. void ** Vtbl;
  1201. void ** pStublessVtbl, **pForwardingVtbl;
  1202. void ** SourceVtbl;
  1203. GetTemplateVtbl(&pStublessVtbl);
  1204. GetTemplateForwardVtbl(&pForwardingVtbl);
  1205. SourceVtbl = IsDelegated ?
  1206. pForwardingVtbl : pStublessVtbl;
  1207. Vtbl = pProxyVtbl->Vtbl;
  1208. //
  1209. // Proxies after NT 3.51 Beta have a ProxyHeader 4 bytes
  1210. // larger to support stubless proxies. So in older proxies
  1211. // subtract 4 bytes to get the the Vtable.
  1212. //
  1213. if ( ProxyVersion < 2 )
  1214. Vtbl = (void **) ((char*)Vtbl - PTR_MEM_SIZE);
  1215. // Initialize forwarding or stubless proxy functions if necessary.
  1216. if ( IsDelegated )
  1217. {
  1218. Vtbl[0] = IUnknown_QueryInterface_Proxy;
  1219. Vtbl[1] = IUnknown_AddRef_Proxy;
  1220. Vtbl[2] = IUnknown_Release_Proxy;
  1221. k = 3;
  1222. }
  1223. else
  1224. k = 0;
  1225. for( ; k < count; k++)
  1226. {
  1227. if(!Vtbl[k])
  1228. {
  1229. Vtbl[k] = SourceVtbl[k];
  1230. }
  1231. else if ( -1 == (ULONG_PTR)Vtbl[k] )
  1232. {
  1233. Vtbl[k] = pStublessVtbl[k];
  1234. }
  1235. }
  1236. ReleaseTemplateVtbl(pStublessVtbl);
  1237. ReleaseTemplateForwardVtbl(pForwardingVtbl);
  1238. }
  1239. __inline
  1240. void NdrpInitializeStubVtbl(
  1241. CInterfaceStubVtbl *pStubVtbl,
  1242. unsigned long version)
  1243. /*++
  1244. Routine Description:
  1245. Initialize the stub vtbl.
  1246. Arguments:
  1247. pStubVtbl - Supplies vtbl to be initialized.
  1248. version
  1249. Return Value:
  1250. None.
  1251. --*/
  1252. {
  1253. void * * pVtbl = (void **) &pStubVtbl->Vtbl;
  1254. void * * pSourceVtbl;
  1255. int i;
  1256. switch ( version )
  1257. {
  1258. case 2:
  1259. pSourceVtbl = (void **)&CStdStubBuffer2Vtbl;
  1260. break;
  1261. case 3:
  1262. pSourceVtbl = (void **)&CStdAsyncStubBufferVtbl;
  1263. break;
  1264. case 4:
  1265. pSourceVtbl = (void **)&CStdAsyncStubBuffer2Vtbl;
  1266. break;
  1267. default:
  1268. pSourceVtbl = (void **)&CStdStubBufferVtbl;
  1269. }
  1270. for ( i=0; i < sizeof(IRpcStubBufferVtbl)/PTR_MEM_SIZE; i++ )
  1271. {
  1272. if ( !pVtbl[i] )
  1273. pVtbl[i] = pSourceVtbl[i];
  1274. }
  1275. }
  1276. HRESULT NdrpInitializeProxyDll(
  1277. IN const ProxyFileInfo ** pProxyFileList,
  1278. IN CStdPSFactoryBuffer * pPSFactoryBuffer )
  1279. /*++
  1280. Routine Description:
  1281. Initialize the proxy DLL.
  1282. Arguments:
  1283. pProxyFileList - Specifies a list of proxy files to be searched.
  1284. pPSFactoryBuffer - Pointer to class factory for proxy DLL.
  1285. Return Value:
  1286. None.
  1287. --*/
  1288. {
  1289. long i, j;
  1290. HRESULT hr;
  1291. unsigned long version, lStublessMaxCount = 0, lForwardMaxCount = 0;
  1292. // set up the PSFactory object if we are the first
  1293. // note that the refcount is NOT altered right here to avoid races
  1294. if (pPSFactoryBuffer->lpVtbl != 0)
  1295. return S_OK;
  1296. for (i = 0; pProxyFileList[i] != 0; i++)
  1297. for (j = 0; pProxyFileList[i]->pProxyVtblList[j] != 0; j++)
  1298. {
  1299. if((pProxyFileList[i]->pDelegatedIIDs != 0) &&
  1300. (pProxyFileList[i]->pDelegatedIIDs[j] != 0))
  1301. {
  1302. if (lForwardMaxCount < pProxyFileList[i]->pStubVtblList[j]->header.DispatchTableCount)
  1303. lForwardMaxCount = pProxyFileList[i]->pStubVtblList[j]->header.DispatchTableCount;
  1304. }
  1305. if (lStublessMaxCount < pProxyFileList[i]->pStubVtblList[j]->header.DispatchTableCount)
  1306. lStublessMaxCount = pProxyFileList[i]->pStubVtblList[j]->header.DispatchTableCount;
  1307. }
  1308. hr = NdrpInitializeStublessVtbl(lStublessMaxCount);
  1309. if (SUCCEEDED(hr))
  1310. hr = NdrpInitializeForwardVtbl(lForwardMaxCount);
  1311. if (FAILED(hr))
  1312. return hr;
  1313. //iterate over the list of proxy files in the proxy DLL.
  1314. for(i = 0;
  1315. pProxyFileList[i] != 0;
  1316. i++)
  1317. {
  1318. //iterate over the list of interfaces in the proxy file.
  1319. for(j = 0;
  1320. pProxyFileList[i]->pProxyVtblList[j] != 0;
  1321. j++)
  1322. {
  1323. if((pProxyFileList[i]->pDelegatedIIDs != 0) &&
  1324. (pProxyFileList[i]->pDelegatedIIDs[j] != 0))
  1325. version = 2;
  1326. else
  1327. version = 0;
  1328. //Initialize the proxy vtbl.
  1329. NdrpInitializeProxyVtbl(pProxyFileList[i]->pProxyVtblList[j],
  1330. pProxyFileList[i]->pStubVtblList[j]->header.DispatchTableCount,
  1331. (version == 2),
  1332. pProxyFileList[i]->TableVersion);
  1333. //Initialize the stub vtbl.
  1334. // See if this is an async uuid interface.
  1335. if ( (pProxyFileList[i]->TableVersion & NDR_PROXY_FILE_ASYNC_UUID) &&
  1336. (ULONG_PTR)pProxyFileList[i]->pAsyncIIDLookup[j] == -1 )
  1337. {
  1338. if (version == 2)
  1339. {
  1340. // delegated async
  1341. version = 4;
  1342. }
  1343. else
  1344. {
  1345. // non-delegated async
  1346. version = 3;
  1347. }
  1348. }
  1349. NdrpInitializeStubVtbl(pProxyFileList[i]->pStubVtblList[j],
  1350. version);
  1351. //Initialize the stub dispatch table.
  1352. }
  1353. }
  1354. pPSFactoryBuffer->pProxyFileList = pProxyFileList;
  1355. //Set the lpVtbl. This code is safe for multiple threads.
  1356. InterlockedExchangePointer((PVOID *) &pPSFactoryBuffer->lpVtbl,
  1357. (PVOID) &CStdPSFactoryBufferVtbl);
  1358. return hr;
  1359. }
  1360. HRESULT RPC_ENTRY NdrDllGetClassObject (
  1361. IN REFCLSID rclsid,
  1362. IN REFIID riid,
  1363. OUT void ** ppv,
  1364. IN const ProxyFileInfo ** pProxyFileList,
  1365. IN const CLSID * pclsid,
  1366. IN CStdPSFactoryBuffer * pPSFactoryBuffer )
  1367. /*++
  1368. Routine Description:
  1369. Searches the linked list for the required class.
  1370. Arguments:
  1371. rclsid -- class id to find
  1372. riid -- interface to return
  1373. ppv -- output pointer
  1374. ppfinfo-- proxyfile info data structure
  1375. pclsid -- proxy file classid
  1376. pPSFactoryBuffer -- pointer to class factory for dll
  1377. Return Value:
  1378. CLASS_E_CLASSNOTAVAILABLE if class not found
  1379. Otherwise, whatever is returned by the class's QI
  1380. --*/
  1381. {
  1382. HRESULT hr;
  1383. RPC_STATUS rc;
  1384. BOOL fFound;
  1385. //Initialize the RPC heap.
  1386. rc = NdrpPerformRpcInitialization();
  1387. if (RPC_S_OK == rc)
  1388. hr = NdrpInitializeProxyDll(pProxyFileList, pPSFactoryBuffer);
  1389. else
  1390. hr = HRESULT_FROM_WIN32(rc);
  1391. if (SUCCEEDED(hr))
  1392. {
  1393. if((pclsid != 0) && (memcmp(&rclsid, pclsid, sizeof(IID)) == 0))
  1394. fFound = TRUE;
  1395. else
  1396. {
  1397. //Search the list of proxy files.
  1398. fFound = NdrpFindInterface(pProxyFileList, rclsid, 0, 0);
  1399. }
  1400. if(fFound != TRUE)
  1401. hr = CLASS_E_CLASSNOTAVAILABLE;
  1402. else
  1403. {
  1404. // see if they asked for one of our interfaces
  1405. hr = pPSFactoryBuffer->lpVtbl->QueryInterface(
  1406. (IPSFactoryBuffer *)pPSFactoryBuffer, riid, ppv);
  1407. }
  1408. }
  1409. if(FAILED(hr))
  1410. *ppv = 0;
  1411. return hr;
  1412. }
  1413. HRESULT RPC_ENTRY
  1414. NdrDllCanUnloadNow(
  1415. IN CStdPSFactoryBuffer * pPSFactoryBuffer)
  1416. /*++
  1417. Routine Description:
  1418. Arguments:
  1419. Return Value:
  1420. S_OK if DLL reference count is zero
  1421. S_FALSE otherwise
  1422. --*/
  1423. {
  1424. HRESULT hr;
  1425. if(pPSFactoryBuffer->RefCount == 0)
  1426. hr = S_OK;
  1427. else
  1428. hr = S_FALSE;
  1429. return hr;
  1430. }
  1431. EXTERN_C HRESULT NdrpCreateProxy(
  1432. IN REFIID riid,
  1433. IN IUnknown * punkOuter,
  1434. OUT IRpcProxyBuffer ** ppProxy,
  1435. OUT void ** ppv)
  1436. /*++
  1437. Routine Description:
  1438. Create a proxy for the specified interface.
  1439. Arguments:
  1440. riid - Specifies the interface ID.
  1441. punkOuter - Specifies the controlling unknown.
  1442. ppProxy - Returns a pointer to the IRpcProxyBuffer interface on the proxy.
  1443. ppv - Returns a pointer to the interface proxy.
  1444. Return Value:
  1445. S_OK
  1446. REGDB_E_IIDNOTREG
  1447. REGDB_E_READREGDB
  1448. REGDB_E_INVALIDVALUE
  1449. E_NOINTERFACE
  1450. --*/
  1451. {
  1452. HRESULT hr;
  1453. CLSID clsid;
  1454. IPSFactoryBuffer * pFactory;
  1455. hr = (*pfnCoGetPSClsid)(riid, &clsid);
  1456. if(SUCCEEDED(hr))
  1457. {
  1458. hr = (*pfnCoGetClassObject)(clsid,
  1459. CLSCTX_INPROC_SERVER | CLSCTX_PS_DLL,
  1460. 0,
  1461. IID_IPSFactoryBuffer,
  1462. (void**)&pFactory);
  1463. if(SUCCEEDED(hr))
  1464. {
  1465. hr = pFactory->lpVtbl->CreateProxy(pFactory, punkOuter, riid, ppProxy, ppv);
  1466. if(SUCCEEDED(hr))
  1467. {
  1468. //Note that CreateProxy increments the reference count on punkOuter.
  1469. //In order to eliminate the circular reference,
  1470. //we release the punkOuter here.
  1471. if((*ppv != 0) && (punkOuter != 0))
  1472. punkOuter->lpVtbl->Release(punkOuter);
  1473. }
  1474. pFactory->lpVtbl->Release(pFactory);
  1475. }
  1476. }
  1477. if(FAILED(hr))
  1478. {
  1479. *ppProxy = 0;
  1480. *ppv = 0;
  1481. }
  1482. return hr;
  1483. }
  1484. EXTERN_C HRESULT NdrpCreateStub(
  1485. IN REFIID riid,
  1486. IN IUnknown * punkServer,
  1487. OUT IRpcStubBuffer ** ppStub)
  1488. /*++
  1489. Routine Description:
  1490. Create a stub for the specified interface.
  1491. Arguments:
  1492. riid - Species the interface ID.
  1493. punkServer - Specifies the controlling unknown.
  1494. ppStub - Returns a pointer to the stub.
  1495. Return Value:
  1496. S_OK
  1497. REGDB_E_IIDNOTREG
  1498. REGDB_E_READREGDB
  1499. REGDB_E_INVALIDVALUE
  1500. E_NOINTERFACE
  1501. --*/
  1502. {
  1503. HRESULT hr;
  1504. CLSID clsid;
  1505. IPSFactoryBuffer * pFactory;
  1506. hr = (*pfnCoGetPSClsid)(riid, &clsid);
  1507. if(SUCCEEDED(hr))
  1508. {
  1509. hr = (*pfnCoGetClassObject)(clsid,
  1510. CLSCTX_INPROC_SERVER | CLSCTX_PS_DLL,
  1511. 0,
  1512. IID_IPSFactoryBuffer,
  1513. (void**)&pFactory);
  1514. if(SUCCEEDED(hr))
  1515. {
  1516. hr = pFactory->lpVtbl->CreateStub(pFactory, riid, punkServer, ppStub);
  1517. pFactory->lpVtbl->Release(pFactory);
  1518. }
  1519. }
  1520. if(FAILED(hr))
  1521. *ppStub = 0;
  1522. return hr;
  1523. }
  1524. HRESULT STDMETHODCALLTYPE
  1525. CStdPSFactoryBuffer_QueryInterface (
  1526. IN IPSFactoryBuffer * This,
  1527. IN REFIID iid,
  1528. OUT void ** ppv )
  1529. /*++
  1530. Routine Description:
  1531. Query for an interface on the PSFactoryBuffer. The PSFactoryBuffer
  1532. supports the IUnknown and IPSFactoryBuffer interfaces.
  1533. Arguments:
  1534. iid - Specifies the interface ID.
  1535. ppv - Returns a pointer to the specified interface.
  1536. Return Value:
  1537. S_OK
  1538. E_NOINTERFACE
  1539. --*/
  1540. {
  1541. HRESULT hr;
  1542. if ((memcmp(&iid, &IID_IUnknown, sizeof(IID)) == 0) ||
  1543. (memcmp(&iid, &IID_IPSFactoryBuffer, sizeof(IID)) == 0) ||
  1544. (memcmp(&iid, &IID_IPSFactoryHook, sizeof(IID)) == 0))
  1545. {
  1546. *ppv = This;
  1547. This->lpVtbl->AddRef(This);
  1548. hr = S_OK;
  1549. }
  1550. else
  1551. {
  1552. *ppv = 0;
  1553. hr = E_NOINTERFACE;
  1554. }
  1555. return hr;
  1556. }
  1557. ULONG STDMETHODCALLTYPE
  1558. CStdPSFactoryBuffer_AddRef(
  1559. IN IPSFactoryBuffer *This)
  1560. /*++
  1561. Routine Description:
  1562. Increment reference count. Since we have a single instance of the
  1563. CStdPSFactoryBuffer per DLL, we can use the PSFactory reference
  1564. count as the DLL reference count.
  1565. Arguments:
  1566. Return Value:
  1567. Reference count.
  1568. --*/
  1569. {
  1570. InterlockedIncrement(&((CStdPSFactoryBuffer *) This)->RefCount);
  1571. return (unsigned long) ((CStdPSFactoryBuffer *) This)->RefCount;
  1572. }
  1573. ULONG STDMETHODCALLTYPE
  1574. CStdPSFactoryBuffer_Release(
  1575. IN IPSFactoryBuffer *This)
  1576. /*++
  1577. Routine Description:
  1578. Decrement reference count.
  1579. Arguments:
  1580. Return Value:
  1581. Reference count.
  1582. --*/
  1583. {
  1584. ULONG count;
  1585. NDR_ASSERT(((CStdPSFactoryBuffer *)This)->RefCount > 0, "Invalid reference count");
  1586. count = (ULONG) ((CStdPSFactoryBuffer *)This)->RefCount - 1;
  1587. if(InterlockedDecrement(&((CStdPSFactoryBuffer *)This)->RefCount) == 0)
  1588. {
  1589. count = 0;
  1590. }
  1591. return count;
  1592. }
  1593. HRESULT STDMETHODCALLTYPE
  1594. CStdPSFactoryBuffer_CreateProxy
  1595. (
  1596. IN IPSFactoryBuffer * This,
  1597. IN IUnknown * punkOuter,
  1598. IN REFIID riid,
  1599. OUT IRpcProxyBuffer ** ppProxy,
  1600. OUT void ** ppv
  1601. )
  1602. /*++
  1603. Routine Description:
  1604. Create a proxy for the specified interface.
  1605. Arguments:
  1606. punkOuter - Specifies the controlling unknown.
  1607. riid - Specifies the interface ID.
  1608. ppProxy - Returns a pointer to the IRpcProxyBuffer interface.
  1609. ppv - Returns a pointer to the specified interface.
  1610. Return Value:
  1611. S_OK
  1612. E_NOINTERFACE
  1613. E_OUTOFMEMORY
  1614. --*/
  1615. {
  1616. HRESULT hr;
  1617. BOOL fFound;
  1618. long j;
  1619. BOOL fDelegate = FALSE;
  1620. const ProxyFileInfo *pProxyFileInfo;
  1621. fFound = NdrpFindInterface(((CStdPSFactoryBuffer *)This)->pProxyFileList, riid, &pProxyFileInfo, &j);
  1622. if(fFound != TRUE)
  1623. hr = E_NOINTERFACE;
  1624. else if ( (pProxyFileInfo->TableVersion & NDR_PROXY_FILE_ASYNC_UUID) &&
  1625. (ULONG_PTR)pProxyFileInfo->pAsyncIIDLookup[j] == -1 )
  1626. {
  1627. // An attempt to create a sync proxy for an async interface.
  1628. hr = E_NOINTERFACE;
  1629. }
  1630. else
  1631. {
  1632. if((pProxyFileInfo->pDelegatedIIDs != 0) &&
  1633. (pProxyFileInfo->pDelegatedIIDs[j] != 0) &&
  1634. (!IsEqualIID(*pProxyFileInfo->pDelegatedIIDs[j], IID_IUnknown)))
  1635. {
  1636. //Need to delegate to the proxy for the base interface..
  1637. //Allocate memory for the new proxy buffer.
  1638. CStdProxyBuffer2 *pProxyBuffer =
  1639. (CStdProxyBuffer2*)(*pfnCoTaskMemAlloc)(sizeof(CStdProxyBuffer2));
  1640. if(0 == pProxyBuffer)
  1641. hr = E_OUTOFMEMORY;
  1642. else
  1643. {
  1644. hr = S_OK;
  1645. //Initialize the new proxy buffer.
  1646. memset(pProxyBuffer, 0, sizeof(CStdProxyBuffer2));
  1647. pProxyBuffer->lpVtbl = &CStdProxyBuffer2Vtbl;
  1648. pProxyBuffer->RefCount = 1;
  1649. pProxyBuffer->punkOuter = punkOuter ? punkOuter : (IUnknown *) pProxyBuffer;
  1650. pProxyBuffer->pProxyVtbl = &pProxyFileInfo->
  1651. pProxyVtblList[j]->Vtbl;
  1652. if ( pProxyFileInfo->TableVersion < 2 )
  1653. pProxyBuffer->pRMBVtbl = NULL;
  1654. else
  1655. pProxyBuffer->pRMBVtbl = &CStdProxyBuffer_ReleaseMarshalBuffersVtbl;
  1656. if ( (pProxyFileInfo->TableVersion & NDR_PROXY_FILE_ASYNC_UUID) &&
  1657. pProxyFileInfo->pAsyncIIDLookup[j] != 0 )
  1658. {
  1659. // The interface has an async counterpart.
  1660. pProxyBuffer->pCallFactoryVtbl = & CStdProxyBuffer2_CallFactoryVtbl;
  1661. pProxyBuffer->pAsyncIID = pProxyFileInfo->pAsyncIIDLookup[j];
  1662. pProxyBuffer->pRMBVtbl = &CStdAsyncProxyBuffer_ReleaseMarshalBuffersVtbl;
  1663. }
  1664. //
  1665. // Proxies after NT 3.51 Beta have a ProxyHeader 4 bytes
  1666. // larger to support stubless proxies. So in older proxies
  1667. // subtract 4 bytes to get the the Vtable.
  1668. //
  1669. if ( pProxyFileInfo->TableVersion < 2 )
  1670. pProxyBuffer->pProxyVtbl = (void *)
  1671. ((char *)pProxyBuffer->pProxyVtbl - PTR_MEM_SIZE);
  1672. //Increment the DLL reference count for DllCanUnloadNow.
  1673. This->lpVtbl->AddRef(This);
  1674. pProxyBuffer->pPSFactory = This;
  1675. pProxyBuffer->iidBase = *pProxyFileInfo->pDelegatedIIDs[j];
  1676. //Create a proxy for the base interface.
  1677. hr = NdrpCreateProxy(*pProxyFileInfo->pDelegatedIIDs[j],
  1678. (IUnknown *) pProxyBuffer,
  1679. &pProxyBuffer->pBaseProxyBuffer,
  1680. (void**)&pProxyBuffer->pBaseProxy);
  1681. if(FAILED(hr))
  1682. {
  1683. (*pfnCoTaskMemFree)(pProxyBuffer);
  1684. }
  1685. else
  1686. {
  1687. *ppProxy = (IRpcProxyBuffer *) pProxyBuffer;
  1688. *ppv = (void *) &pProxyBuffer->pProxyVtbl;
  1689. ((IUnknown *) *ppv)->lpVtbl->AddRef((IUnknown *) *ppv);
  1690. }
  1691. }
  1692. }
  1693. else
  1694. {
  1695. //Allocate memory for the new proxy buffer.
  1696. CStdProxyBuffer *pProxyBuffer =
  1697. (CStdProxyBuffer*)(*pfnCoTaskMemAlloc)(sizeof(CStdProxyBuffer));
  1698. if(0 == pProxyBuffer)
  1699. hr = E_OUTOFMEMORY;
  1700. else
  1701. {
  1702. hr = S_OK;
  1703. //Initialize the new proxy buffer.
  1704. memset(pProxyBuffer, 0, sizeof(CStdProxyBuffer));
  1705. pProxyBuffer->lpVtbl = &CStdProxyBufferVtbl;
  1706. pProxyBuffer->RefCount = 1;
  1707. pProxyBuffer->punkOuter = punkOuter ? punkOuter : (IUnknown *) pProxyBuffer;
  1708. pProxyBuffer->pProxyVtbl = &pProxyFileInfo->
  1709. pProxyVtblList[j]->Vtbl;
  1710. if ( pProxyFileInfo->TableVersion < 2 )
  1711. pProxyBuffer->pRMBVtbl = NULL;
  1712. else
  1713. pProxyBuffer->pRMBVtbl = &CStdProxyBuffer_ReleaseMarshalBuffersVtbl;
  1714. if ( (pProxyFileInfo->TableVersion & NDR_PROXY_FILE_ASYNC_UUID) &&
  1715. pProxyFileInfo->pAsyncIIDLookup[j] != 0 )
  1716. {
  1717. pProxyBuffer->pCallFactoryVtbl = & CStdProxyBuffer_CallFactoryVtbl;
  1718. pProxyBuffer->pAsyncIID = pProxyFileInfo->pAsyncIIDLookup[j];
  1719. pProxyBuffer->pRMBVtbl = &CStdAsyncProxyBuffer_ReleaseMarshalBuffersVtbl;
  1720. }
  1721. //
  1722. // Proxies after NT 3.51 Beta have a ProxyHeader 4 bytes
  1723. // larger to support stubless proxies. So in older proxies
  1724. // subtract 4 bytes to get the the Vtable.
  1725. //
  1726. if ( pProxyFileInfo->TableVersion < 2 )
  1727. pProxyBuffer->pProxyVtbl = (void *)
  1728. ((char*)pProxyBuffer->pProxyVtbl - PTR_MEM_SIZE);
  1729. //Increment the DLL reference count for DllCanUnloadNow.
  1730. This->lpVtbl->AddRef(This);
  1731. pProxyBuffer->pPSFactory = This;
  1732. *ppProxy = (IRpcProxyBuffer *) pProxyBuffer;
  1733. *ppv = (void *) &pProxyBuffer->pProxyVtbl;
  1734. ((IUnknown *) *ppv)->lpVtbl->AddRef((IUnknown *) *ppv);
  1735. }
  1736. }
  1737. }
  1738. if(FAILED(hr))
  1739. {
  1740. *ppProxy = 0;
  1741. *ppv = 0;
  1742. }
  1743. return hr;
  1744. }
  1745. HRESULT STDMETHODCALLTYPE
  1746. CStdPSFactoryBuffer_CreateStub
  1747. (
  1748. IN IPSFactoryBuffer * This,
  1749. IN REFIID riid,
  1750. IN IUnknown * punkServer,
  1751. OUT IRpcStubBuffer ** ppStub
  1752. )
  1753. /*++
  1754. Routine Description:
  1755. Create a stub for the specified interface.
  1756. Arguments:
  1757. Return Value:
  1758. --*/
  1759. {
  1760. HRESULT hr;
  1761. const ProxyFileInfo * pProxyFileInfo;
  1762. long j;
  1763. BOOL fFound = NdrpFindInterface(((CStdPSFactoryBuffer *)This)->pProxyFileList,
  1764. riid,
  1765. &pProxyFileInfo,
  1766. &j);
  1767. if(fFound != TRUE)
  1768. hr = E_NOINTERFACE;
  1769. else if ( (pProxyFileInfo->TableVersion & NDR_PROXY_FILE_ASYNC_UUID) &&
  1770. (ULONG_PTR)pProxyFileInfo->pAsyncIIDLookup[j] == -1 )
  1771. {
  1772. // An attempt to create a sync stub for an async interface.
  1773. hr = E_NOINTERFACE;
  1774. }
  1775. else
  1776. {
  1777. if((pProxyFileInfo->pDelegatedIIDs != 0) &&
  1778. (pProxyFileInfo->pDelegatedIIDs[j] != 0) &&
  1779. (!IsEqualIID(*pProxyFileInfo->pDelegatedIIDs[j], IID_IUnknown)))
  1780. {
  1781. IUnknown * punkForward;
  1782. //We need to delegate to the stub for the base interface.
  1783. CStdStubBuffer2 *pStubBuffer =
  1784. (CStdStubBuffer2*)(*pfnCoTaskMemAlloc)(sizeof(CStdStubBuffer2));
  1785. if(0 == pStubBuffer)
  1786. hr = E_OUTOFMEMORY;
  1787. else
  1788. {
  1789. void ** pForwardingVtbl;
  1790. GetTemplateForwardVtbl(&pForwardingVtbl);
  1791. //Initialize the new stub buffer.
  1792. memset(pStubBuffer, 0, sizeof(CStdStubBuffer2));
  1793. pStubBuffer->lpForwardingVtbl = pForwardingVtbl;
  1794. pStubBuffer->lpVtbl = &pProxyFileInfo->pStubVtblList[j]->Vtbl;
  1795. pStubBuffer->RefCount= 1;
  1796. pStubBuffer->pPSFactory = This;
  1797. if ( pProxyFileInfo->TableVersion < 2 )
  1798. pStubBuffer->pRMBVtbl = NULL;
  1799. else
  1800. pStubBuffer->pRMBVtbl = &CStdStubBuffer_ReleaseMarshalBuffersVtbl;
  1801. if ( (pProxyFileInfo->TableVersion & NDR_PROXY_FILE_ASYNC_UUID) &&
  1802. pProxyFileInfo->pAsyncIIDLookup[j] != 0 )
  1803. {
  1804. pStubBuffer->pCallFactoryVtbl = &CStdStubBuffer2_CallFactoryVtbl;
  1805. pStubBuffer->pAsyncIID = pProxyFileInfo->pAsyncIIDLookup[j];
  1806. pStubBuffer->pRMBVtbl = &CStdAsyncStubBuffer_ReleaseMarshalBuffersVtbl;
  1807. }
  1808. //Increment the DLL reference count for DllCanUnloadNow.
  1809. This->lpVtbl->AddRef(This);
  1810. *ppStub = (IRpcStubBuffer *) &pStubBuffer->lpVtbl;
  1811. //Connect the stub to the server object.
  1812. if(punkServer != 0)
  1813. {
  1814. hr = punkServer->lpVtbl->QueryInterface(
  1815. punkServer,
  1816. riid,
  1817. (void**)&pStubBuffer->pvServerObject);
  1818. }
  1819. else
  1820. {
  1821. hr = S_OK;
  1822. }
  1823. if(SUCCEEDED(hr))
  1824. {
  1825. if(punkServer != 0)
  1826. punkForward = (IUnknown *) &pStubBuffer->lpForwardingVtbl;
  1827. else
  1828. punkForward = 0;
  1829. //Create a stub for the base interface
  1830. hr = NdrpCreateStub(*pProxyFileInfo->pDelegatedIIDs[j],
  1831. punkForward,
  1832. &pStubBuffer->pBaseStubBuffer);
  1833. }
  1834. if(FAILED(hr))
  1835. {
  1836. ReleaseTemplateForwardVtbl(pForwardingVtbl);
  1837. (*pfnCoTaskMemFree)(pStubBuffer);
  1838. }
  1839. }
  1840. }
  1841. else
  1842. {
  1843. //Create an ordinary stub buffer.
  1844. CStdStubBuffer *pStubBuffer =
  1845. (CStdStubBuffer*)(*pfnCoTaskMemAlloc)(sizeof(CStdStubBuffer));
  1846. if(0 == pStubBuffer)
  1847. hr = E_OUTOFMEMORY;
  1848. else
  1849. {
  1850. //Initialize the new stub buffer.
  1851. memset(pStubBuffer, 0, sizeof(CStdStubBuffer));
  1852. pStubBuffer->lpVtbl = &pProxyFileInfo->pStubVtblList[j]->Vtbl;
  1853. pStubBuffer->RefCount= 1;
  1854. pStubBuffer->pPSFactory = This;
  1855. if ( pProxyFileInfo->TableVersion < 2 )
  1856. pStubBuffer->pRMBVtbl = NULL;
  1857. else
  1858. pStubBuffer->pRMBVtbl = &CStdStubBuffer_ReleaseMarshalBuffersVtbl;
  1859. if ( (pProxyFileInfo->TableVersion & NDR_PROXY_FILE_ASYNC_UUID) &&
  1860. pProxyFileInfo->pAsyncIIDLookup[j] != 0 )
  1861. {
  1862. pStubBuffer->pCallFactoryVtbl = &CStdStubBuffer_CallFactoryVtbl;
  1863. pStubBuffer->pAsyncIID = pProxyFileInfo->pAsyncIIDLookup[j];
  1864. pStubBuffer->pRMBVtbl = &CStdAsyncStubBuffer_ReleaseMarshalBuffersVtbl;
  1865. }
  1866. if(0 == punkServer)
  1867. hr = S_OK;
  1868. else
  1869. {
  1870. hr = punkServer->lpVtbl->QueryInterface(
  1871. punkServer,
  1872. riid,
  1873. (void**)&pStubBuffer->pvServerObject);
  1874. }
  1875. if(SUCCEEDED(hr))
  1876. {
  1877. //Increment the DLL reference count for DllCanUnloadNow.
  1878. This->lpVtbl->AddRef(This);
  1879. *ppStub = (IRpcStubBuffer *) pStubBuffer;
  1880. }
  1881. else
  1882. {
  1883. (*pfnCoTaskMemFree)(pStubBuffer);
  1884. }
  1885. }
  1886. }
  1887. }
  1888. if(FAILED(hr))
  1889. *ppStub = 0;
  1890. return hr;
  1891. }
  1892. HRESULT STDMETHODCALLTYPE
  1893. CStdPSFactoryBuffer_HkGetProxyFileInfo
  1894. (
  1895. IN IPSFactoryBuffer *This,
  1896. IN REFIID riid,
  1897. OUT PINT pOffset,
  1898. OUT PVOID *ppProxyFileInfo
  1899. )
  1900. /*++
  1901. Routine Description:
  1902. This function returns the proxy information for a particular
  1903. interface. HookOle requires information such as the number
  1904. of methods in the vtable and a pointer to the
  1905. StublessProxyInfo structure.
  1906. Arguments:
  1907. This - This pointer for the proxy object.
  1908. riid - IID of the interface we are asking about.
  1909. pOffset - Offset into the ProxyFileInfo lists for this
  1910. particular interface.
  1911. ppProxyFileInfo - Pointer to location where a pointer to the
  1912. ProxyFileInfo structure can be stored.
  1913. Return Value:
  1914. --*/
  1915. {
  1916. HRESULT hr=E_NOINTERFACE;
  1917. ProxyFileInfo *pProxyFileInfo=NULL;
  1918. //
  1919. // Find the index into the FileList for this iid.
  1920. //
  1921. if (NdrpFindInterface(
  1922. ((CStdPSFactoryBuffer *)This)->pProxyFileList,
  1923. riid,
  1924. (const ProxyFileInfo**)&pProxyFileInfo,
  1925. (long*)pOffset)) {
  1926. *ppProxyFileInfo = (PVOID)pProxyFileInfo;
  1927. hr = S_OK;
  1928. }
  1929. return(hr);
  1930. }
  1931. // initialize mutex, and return error instead of throwing. In OLE world, people
  1932. // expect error code instead of exception.
  1933. HRESULT
  1934. NdrpInitializeMutex( I_RPC_MUTEX * pMutex )
  1935. {
  1936. RPC_STATUS rc = RPC_S_OK;
  1937. NDR_ASSERT( *pMutex == NULL, "pMutex should be NULL to be initialized" );
  1938. //
  1939. __try
  1940. {
  1941. I_RpcRequestMutex( pMutex );
  1942. I_RpcClearMutex( *pMutex );
  1943. }
  1944. __except( EXCEPTION_EXECUTE_HANDLER )
  1945. {
  1946. // we want to catch all the exception here in OLE land
  1947. rc = RpcExceptionCode();
  1948. }
  1949. return HRESULT_FROM_WIN32( rc );
  1950. }