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.

1123 lines
36 KiB

  1. /***************************************************************************
  2. *
  3. * Copyright (C) 1996 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: stipriv.h
  6. * Content: Internal include file
  7. *@@BEGIN_MSINTERNAL
  8. * History:
  9. *
  10. * 10/28/96 vlads Starting code for STI
  11. *
  12. *@@END_MSINTERNAL
  13. *
  14. ***************************************************************************/
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #ifndef FINAL
  19. #define EXPIRE_YEAR 2001
  20. #define EXPIRE_MONTH 01
  21. #define EXPIRE_DAY 24
  22. #endif
  23. typedef LPUNKNOWN PUNK;
  24. typedef LPVOID PV, *PPV;
  25. typedef CONST VOID *PCV;
  26. typedef REFIID RIID;
  27. typedef CONST GUID *PCGUID;
  28. #define MAX_REG_CHAR 128
  29. //
  30. // We need to use free-threading model, definitions for which are guarded
  31. // with the following define ( in VC 5.0).
  32. //
  33. #ifndef _WIN32_DCOM
  34. //#define _WIN32_DCOM
  35. #endif
  36. /***************************************************************************
  37. *
  38. * Global variables
  39. *
  40. ***************************************************************************/
  41. extern HINSTANCE g_hInst;
  42. extern BOOL g_NoUnicodePlatform;
  43. extern BOOL g_COMInitialized;
  44. extern HANDLE g_hStiFileLog;
  45. /*****************************************************************************
  46. *
  47. * stiobj.c - ISti objectimplementation
  48. *
  49. *****************************************************************************/
  50. STDMETHODIMP CStiObj_New(PUNK punkOuter, RIID riid, PPV ppvOut);
  51. STDMETHODIMP StiCreateHelper(
  52. HINSTANCE hinst,
  53. DWORD dwVer,
  54. PPV ppvObj,
  55. PUNK punkOuter,
  56. RIID riid
  57. );
  58. STDMETHODIMP StiPrivateGetDeviceInfoHelperW(
  59. LPWSTR pwszDeviceName,
  60. LPVOID *ppBuffer
  61. );
  62. /*****************************************************************************
  63. *
  64. *
  65. *****************************************************************************/
  66. #define INTERNAL NTAPI /* Called only within a translation unit */
  67. #define EXTERNAL NTAPI /* Called from other translation units */
  68. #define INLINE static __inline
  69. #define BEGIN_CONST_DATA data_seg(".text", "CODE")
  70. #define END_CONST_DATA data_seg(".data", "DATA")
  71. /*
  72. * Arithmetic on pointers.
  73. */
  74. #define pvSubPvCb(pv, cb) ((PV)((PBYTE)pv - (cb)))
  75. #define pvAddPvCb(pv, cb) ((PV)((PBYTE)pv + (cb)))
  76. #define cbSubPvPv(p1, p2) ((PBYTE)(p1) - (PBYTE)(p2))
  77. /*
  78. * Convert an object (X) to a count of bytes (cb).
  79. */
  80. #define cbX(X) sizeof(X)
  81. /*
  82. * Convert an array name (A) to a generic count (c).
  83. */
  84. #define cA(a) (cbX(a)/cbX(a[0]))
  85. /*
  86. * Convert a count of X's (cx) into a count of bytes.
  87. */
  88. #define cbCxX(cx, X) ((cx) * cbX(X))
  89. /*
  90. * Convert a count of chars (cch), tchars (ctch), wchars (cwch),
  91. * or dwords (cdw) into a count of bytes.
  92. */
  93. #define cbCch(cch) cbCxX( cch, CHAR)
  94. #define cbCwch(cwch) cbCxX(cwch, WCHAR)
  95. #define cbCtch(ctch) cbCxX(ctch, TCHAR)
  96. #define cbCdw(cdw) cbCxX( cdw, DWORD)
  97. /*
  98. * Zero an arbitrary buffer. It is a common error to get the second
  99. * and third parameters to memset backwards.
  100. */
  101. #define ZeroBuf(pv, cb) memset(pv, 0, cb)
  102. /*
  103. * Zero an arbitrary object.
  104. */
  105. #define ZeroX(x) ZeroBuf(&(x), cbX(x))
  106. /*
  107. * land -- Logical and. Evaluate the first. If the first is zero,
  108. * then return zero. Otherwise, return the second.
  109. */
  110. #define fLandFF(f1, f2) ((f1) ? (f2) : 0)
  111. /*
  112. * limp - logical implication. True unless the first is nonzero and
  113. * the second is zero.
  114. */
  115. #define fLimpFF(f1, f2) (!(f1) || (f2))
  116. /*
  117. * leqv - logical equivalence. True if both are zero or both are nonzero.
  118. */
  119. #define fLeqvFF(f1, f2) (!(f1) == !(f2))
  120. /*
  121. * fInOrder - checks that i1 <= i2 < i3.
  122. */
  123. #define fInOrder(i1, i2, i3) ((unsigned)((i2)-(i1)) < (unsigned)((i3)-(i1)))
  124. /*
  125. * Words to keep preprocessor happy.
  126. */
  127. #define comma ,
  128. #define empty
  129. /*
  130. * Atomically exchange one value for another.
  131. */
  132. #define pvExchangePpvPv(ppv, pv) \
  133. (PV)InterlockedExchangePointer((PPV)(ppv), (PV)(pv))
  134. /*
  135. * Creating HRESULTs from a USHORT or from a LASTERROR.
  136. */
  137. #define hresUs(us) MAKE_HRESULT(SEVERITY_SUCCESS, 0, (USHORT)(us))
  138. #define hresLe(le) MAKE_HRESULT(SEVERITY_ERROR, FACILITY_WIN32, (USHORT)(le))
  139. /***************************************************************************
  140. *
  141. * Debug / RDebug / Retail
  142. *
  143. * If either DEBUG or RDEBUG, set MAXDEBUG.
  144. *
  145. * Retail defines nothing.
  146. *
  147. ***************************************************************************/
  148. #if defined(DEBUG) || defined(RDEBUG)
  149. //#define MAXDEBUG
  150. #endif
  151. /***************************************************************************
  152. *
  153. * Validation Code....
  154. *
  155. * "If it crashes in retail, it must crash in debug."
  156. *
  157. * What we don't want is an app that works fine under debug, but crashes
  158. * under retail.
  159. *
  160. * So if we find an invalid parameter in debug that would not have been
  161. * detected by retail, let it pass through after a warning. That way,
  162. * the invalid parameter continues onward through the system and creates
  163. * as much (or more) havoc in debug as it would under retail.
  164. *
  165. * The _fFastValidXxx functions perform cursory validation.
  166. * The _fFullValidXxx functions perform full validation.
  167. *
  168. * In retail, fFastValidXxx maps to _fFastValidXxx.
  169. *
  170. * In debug, fFastValidXxx performs a full validation and throws away
  171. * the error value, then returns the value of _fFastValidXxx.
  172. *
  173. * The hresFullValidXxx functions return HRESULTs instead of BOOLs.
  174. *
  175. * Values for Xxx:
  176. *
  177. * Hwnd - hwnd = window handle
  178. * Pdw - pdw = pointer to a dword
  179. * PdwOut - pdw = pointer to a dword that will be set initially to 0
  180. * Pfn - pfn = function pointer
  181. * riid - riid = pointer to IID
  182. * guid - pguid = pointer to GUID
  183. *
  184. * ReadPx - p -> structure for reading, X = structure name
  185. * WritePx - p -> structure for writing, X = structure name
  186. *
  187. * ReadPxCb - p -> structure for reading, X = structure name
  188. * first field of structure is dwSize which must be
  189. * equal to cbX(X).
  190. *
  191. * WritePxCb - p -> structure for writing, X = structure name
  192. * first field of structure is dwSize which must be
  193. * equal to cbX(X).
  194. *
  195. * ReadPvCb - p -> buffer, cb = size of buffer
  196. * WritePvCb - p -> buffer, cb = size of buffer
  197. *
  198. * Pobj - p -> internal interface
  199. *
  200. * fl - fl = incoming flags, flV = valid flags
  201. *
  202. ***************************************************************************/
  203. #ifndef MAXDEBUG
  204. /*
  205. * Wrappers that throw away the szProc and iarg info.
  206. */
  207. #define hresFullValidHwnd_(hwnd, z, i) \
  208. _hresFullValidHwnd_(hwnd) \
  209. #define hresFullValidPdwOut_(pdw, z, i) \
  210. _hresFullValidPdwOut_(pdw) \
  211. #define hresFullValidReadPxCb_(pv, cb, pszProc, iarg) \
  212. _hresFullValidReadPxCb_(pv, cb) \
  213. #define hresFullValidReadPvCb_(pv, cb, pszProc, iarg) \
  214. _hresFullValidReadPvCb_(pv, cb) \
  215. #define hresFullValidWritePxCb_(pv, cb, pszProc, iarg) \
  216. _hresFullValidWritePxCb_(pv, cb) \
  217. #define hresFullValidWritePvCb_(pv, cb, pszProc, iarg) \
  218. _hresFullValidWritePvCb_(pv, cb) \
  219. #define hresFullValidFl_(fl, flV, pszProc, iarg) \
  220. _hresFullValidFl_(fl, flV) \
  221. #define hresFullValidPfn_(pfn, pszProc, iarg) \
  222. _hresFullValidPfn_(pfn) \
  223. #define hresFullValidPitf_(punk, pszProc, iarg) \
  224. _hresFullValidPitf_(punk) \
  225. #define hresFullValidHwnd0_(hwnd, pszProc, iarg) \
  226. _hresFullValidHwnd0_(hwnd) \
  227. #define hresFullValidPitf0_(punk, pszProc, iarg) \
  228. _hresFullValidPitf0_(punk) \
  229. #endif
  230. /*
  231. * The actual functions.
  232. */
  233. STDMETHODIMP hresFullValidHwnd_(HWND hwnd, LPCSTR pszProc, int iarg);
  234. STDMETHODIMP hresFullValidPdwOut_(PV pdw, LPCSTR pszProc, int iarg);
  235. STDMETHODIMP hresFullValidReadPxCb_(PCV pv, UINT cb, LPCSTR pszProc, int iarg);
  236. STDMETHODIMP hresFullValidReadPvCb_(PCV pv, UINT cb, LPCSTR pszProc, int iarg);
  237. STDMETHODIMP hresFullValidWritePxCb_(PV pv, UINT cb, LPCSTR pszProc, int iarg);
  238. STDMETHODIMP hresFullValidWritePvCb_(PV pv, UINT cb, LPCSTR pszProc, int iarg);
  239. STDMETHODIMP hresFullValidFl_(DWORD fl, DWORD flV, LPCSTR pszProc, int iarg);
  240. STDMETHODIMP hresFullValidPfn_(FARPROC pfn, LPCSTR pszProc, int iarg);
  241. STDMETHODIMP hresFullValidPitf_(PUNK punk, LPCSTR pszProc, int iarg);
  242. HRESULT INLINE
  243. hresFullValidHwnd0_(HWND hwnd, LPCSTR pszProc, int iarg)
  244. {
  245. HRESULT hres;
  246. if (hwnd) {
  247. hres = hresFullValidHwnd_(hwnd, pszProc, iarg);
  248. } else {
  249. hres = S_OK;
  250. }
  251. return hres;
  252. }
  253. HRESULT INLINE
  254. hresFullValidPitf0_(PUNK punk, LPCSTR pszProc, int iarg)
  255. {
  256. HRESULT hres;
  257. if (punk) {
  258. hres = hresFullValidPitf_(punk, pszProc, iarg);
  259. } else {
  260. hres = S_OK;
  261. }
  262. return hres;
  263. }
  264. /*
  265. * Wrappers for derived types.
  266. */
  267. #define hresFullValidRiid_(riid, s_szProc, iarg) \
  268. hresFullValidReadPvCb_(riid, cbX(IID), s_szProc, iarg) \
  269. /*
  270. * Wrapers that add the szProc and iarg info.
  271. */
  272. #define hresFullValidHwnd(hwnd, iarg) \
  273. hresFullValidHwnd_(hwnd, s_szProc, iarg) \
  274. #define hresFullValidPdwOut(pdw, i) \
  275. hresFullValidPdwOut_(pdw, s_szProc, i) \
  276. #define hresFullValidReadPdw_(pdw, z, i) \
  277. hresFullValidReadPvCb_(pdw, cbX(DWORD), z, i) \
  278. #define hresFullValidRiid(riid, iarg) \
  279. hresFullValidRiid_(riid, s_szProc, iarg) \
  280. #define hresFullValidGuid(pguid, iarg) \
  281. hresFullValidReadPvCb_(pguid, cbX(GUID), s_szProc, iarg) \
  282. #define hresFullValidReadPxCb(pv, X, iarg) \
  283. hresFullValidReadPxCb_(pv, cbX(X), s_szProc, iarg) \
  284. #define hresFullValidReadPvCb(pv, cb, iarg) \
  285. hresFullValidReadPvCb_(pv, cb, s_szProc, iarg) \
  286. #define hresFullValidReadPx(pv, X, iarg) \
  287. hresFullValidReadPvCb_(pv, cbX(X), s_szProc, iarg) \
  288. #define hresFullValidWritePxCb(pv, X, iarg) \
  289. hresFullValidWritePxCb_(pv, cbX(X), s_szProc, iarg) \
  290. #define hresFullValidWritePvCb(pv, cb, iarg) \
  291. hresFullValidWritePvCb_(pv, cb, s_szProc, iarg) \
  292. #define hresFullValidWritePx(pv, X, iarg) \
  293. hresFullValidWritePvCb_(pv, cbX(X), s_szProc, iarg) \
  294. #define hresFullValidReadPdw(pdw, iarg) \
  295. hresFullValidReadPdw_(pdw, s_szProc, iarg) \
  296. #define hresFullValidFl(fl, flV, iarg) \
  297. hresFullValidFl_(fl, flV, s_szProc, iarg) \
  298. #define hresFullValidPfn(pfn, iarg) \
  299. hresFullValidPfn_((FARPROC)(pfn), s_szProc, iarg) \
  300. #define hresFullValidPitf(pitf, iarg) \
  301. hresFullValidPitf_((PUNK)(pitf), s_szProc, iarg) \
  302. #define hresFullValidHwnd0(hwnd, iarg) \
  303. hresFullValidHwnd0_(hwnd, s_szProc, iarg) \
  304. #define hresFullValidPitf0(pitf, iarg) \
  305. hresFullValidPitf0_((PUNK)(pitf), s_szProc, iarg) \
  306. /*****************************************************************************
  307. *
  308. * @doc INTERNAL
  309. *
  310. * @func void | ValidationException |
  311. *
  312. * Raises a parameter validation exception in MAXDEBUG.
  313. *
  314. *****************************************************************************/
  315. #define ecValidation (ERROR_SEVERITY_ERROR | hresLe(ERROR_INVALID_PARAMETER))
  316. #ifdef MAXDEBUG
  317. #define ValidationException() RaiseException(ecValidation, 0, 0, 0)
  318. #else
  319. #define ValidationException()
  320. #endif
  321. /*
  322. * TFORM(x) expands to x##A if ANSI or x##W if UNICODE.
  323. * This T-izes a symbol, in the sense of TCHAR or PTSTR.
  324. *
  325. * SFORM(x) expands to x##W if ANSI or x##A if UNICODE.
  326. * This anti-T-izes a symbol.
  327. */
  328. #ifdef UNICODE
  329. #define _TFORM(x) x##W
  330. #define _SFORM(x) x##A
  331. #else
  332. #define _TFORM(x) x##A
  333. #define _SFORM(x) x##W
  334. #endif
  335. #define TFORM(x) _TFORM(x)
  336. #define SFORM(x) _SFORM(x)
  337. /*
  338. * SToT(dst, cchDst, src) - convert S to T
  339. * TToS(dst, cchDst, src) - convert T to S
  340. *
  341. * Remember, "T" means "ANSI if ANSI, or UNICODE if UNICODE",
  342. * and "S" is the anti-T.
  343. *
  344. * So SToT converts to the preferred character set, and TToS converts
  345. * to the alternate character set.
  346. *
  347. */
  348. #define AToU(dst, cchDst, src) \
  349. MultiByteToWideChar(CP_ACP, 0, src, -1, dst, cchDst)
  350. #define UToA(dst, cchDst, src) \
  351. WideCharToMultiByte(CP_ACP, 0, src, -1, dst, cchDst, 0, 0)
  352. #ifdef UNICODE
  353. #define SToT AToU
  354. #define TToS UToA
  355. #define AToT AToU
  356. #define TToU(dst, cchDst, src) lstrcpyn(dst, src, cchDst)
  357. #else
  358. #define SToT UToA
  359. #define TToS AToU
  360. #define AToT(dst, cchDst, src) lstrcpyn(dst, src, cchDst)
  361. #define TToU AToU
  362. #endif
  363. /*****************************************************************************
  364. *
  365. * Unicode wrappers for Win95
  366. *
  367. *****************************************************************************/
  368. #ifndef UNICODE
  369. #define LoadStringW _LoadStringW
  370. int EXTERNAL LoadStringW(HINSTANCE hinst, UINT ids, LPWSTR pwsz, int cwch);
  371. #endif
  372. //
  373. // Migration function
  374. //
  375. BOOL
  376. RegisterSTIAppForWIAEvents(
  377. WCHAR *pszName,
  378. WCHAR *pszWide,
  379. BOOL fSetAsDefault
  380. );
  381. HRESULT RunRegisterProcess(
  382. CHAR *szAppName,
  383. CHAR *szCmdLine);
  384. //
  385. // C specific macros, not needed in C++ code
  386. //
  387. #ifndef __cplusplus
  388. /*****************************************************************************
  389. *
  390. * Common Object Managers for the Component Object Model
  391. *
  392. * OLE wrapper macros and structures. For more information, see
  393. * the beginning of common.c
  394. *
  395. *****************************************************************************/
  396. /*****************************************************************************
  397. *
  398. * Pre-vtbl structures
  399. *
  400. * Careful! If you change these structures, you must also adjust
  401. * common.c accordingly.
  402. *
  403. *****************************************************************************/
  404. typedef struct PREVTBL { /* Shared vtbl prefix */
  405. RIID riid; /* Type of this object */
  406. ULONG lib; /* offset from start of object */
  407. } PREVTBL, *PPREVTBL;
  408. typedef struct PREVTBLP { /* Prefix for primary vtbl */
  409. PPV rgvtbl; /* Array of standard vtbls */
  410. UINT cbvtbl; /* Size of vtbl array in bytes */
  411. STDMETHOD(QIHelper)(PV pv, RIID riid, PPV ppvOut); /* QI helper */
  412. STDMETHOD_(void,FinalizeProc)(PV pv);/* Finalization procedure */
  413. PREVTBL prevtbl; /* lib must be zero */
  414. } PREVTBLP, *PPREVTBLP;
  415. /*
  416. * A fuller implementation is in common.c. Out here, we need only
  417. * concern ourselves with getting to the primary interface.
  418. */
  419. #define _thisPv(pitf) \
  420. pvSubPvCb(pitf, (*(PPREVTBL*)(pitf))[-1].lib)
  421. #define _thisPvNm(pitf, nm) \
  422. pvSubPvCb(pitf, FIELD_OFFSET(ThisClass, nm)) \
  423. #ifndef MAXDEBUG
  424. #define hresPvVtbl_(pv, vtbl, pszProc) \
  425. _hresPvVtbl_(pv, vtbl) \
  426. #endif
  427. HRESULT EXTERNAL
  428. hresPvVtbl_(PV pv, PV vtbl, LPCSTR pszProc);
  429. #define hresPvVtbl(pv, vtbl) \
  430. hresPvVtbl_(pv, vtbl, s_szProc) \
  431. #define hresPvI(pv, I) \
  432. hresPvVtbl(pv, Class_Vtbl(ThisClass, I)) \
  433. #define hresPv(pv) \
  434. hresPvI(pv, ThisInterface) \
  435. #ifdef MAXDEBUG
  436. #define hresPvT(pv) \
  437. hresPvVtbl(pv, vtblExpected) \
  438. #else
  439. #define hresPvT(pv) \
  440. hresPv(pv) \
  441. #endif
  442. /*****************************************************************************
  443. *
  444. * Declaring interfaces
  445. *
  446. * The extra level of indirection on _Primary_Interface et al
  447. * allow the interface name to be a macro which expands to the
  448. * *real* name of the interface.
  449. *
  450. *****************************************************************************/
  451. #define __Class_Vtbl(C, I) &c_##I##_##C##VI.vtbl
  452. #define _Class_Vtbl(C, I) __Class_Vtbl(C, I)
  453. #define Class_Vtbl(C, I) _Class_Vtbl(C, I)
  454. #define Num_Interfaces(C) cA(c_rgpv##C##Vtbl)
  455. #ifdef DEBUG
  456. #define Simple_Interface(C) Primary_Interface(C, IUnknown); \
  457. Default_QueryInterface(C) \
  458. Default_AddRef(C) \
  459. Default_Release(C)
  460. #define Simple_Vtbl(C) Class_Vtbl(C)
  461. #define Simple_Interface_Begin(C) Primary_Interface_Begin(C, IUnknown)
  462. #define Simple_Interface_End(C) Primary_Interface_End(C, IUnknown)
  463. #else
  464. #define Simple_Interface(C) Primary_Interface(C, IUnknown)
  465. #define Simple_Vtbl(C) Class_Vtbl(C)
  466. #define Simple_Interface_Begin(C) \
  467. struct S_##C##Vtbl c_##I##_##C##VI = { { \
  468. c_rgpv##C##Vtbl, \
  469. cbX(c_rgpv##C##Vtbl), \
  470. C##_QIHelper, \
  471. C##_Finalize, \
  472. { &IID_##IUnknown, 0 }, \
  473. }, { \
  474. Common##_QueryInterface, \
  475. Common##_AddRef, \
  476. Common##_Release, \
  477. #define Simple_Interface_End(C) \
  478. } }; \
  479. #endif
  480. #define _Primary_Interface(C, I) \
  481. extern struct S_##C##Vtbl { \
  482. PREVTBLP prevtbl; \
  483. I##Vtbl vtbl; \
  484. } c_##I##_##C##VI \
  485. #define Primary_Interface(C, I) \
  486. _Primary_Interface(C, I) \
  487. #define _Primary_Interface_Begin(C, I) \
  488. struct S_##C##Vtbl c_##I##_##C##VI = { { \
  489. c_rgpv##C##Vtbl, \
  490. cbX(c_rgpv##C##Vtbl), \
  491. C##_QIHelper, \
  492. C##_Finalize, \
  493. { &IID_##I, 0, }, \
  494. }, { \
  495. C##_QueryInterface, \
  496. C##_AddRef, \
  497. C##_Release, \
  498. #define Primary_Interface_Begin(C, I) \
  499. _Primary_Interface_Begin(C, I) \
  500. #define Primary_Interface_End(C, I) \
  501. } }; \
  502. #define _Secondary_Interface(C, I) \
  503. extern struct S_##I##_##C##Vtbl { \
  504. PREVTBL prevtbl; \
  505. I##Vtbl vtbl; \
  506. } c_##I##_##C##VI \
  507. #define Secondary_Interface(C, I) \
  508. _Secondary_Interface(C, I) \
  509. /*
  510. * Secret backdoor for the "private" IUnknown in common.c
  511. */
  512. #define _Secondary_Interface_Begin(C, I, ofs, Pfx) \
  513. struct S_##I##_##C##Vtbl c_##I##_##C##VI = { { \
  514. &IID_##I, \
  515. ofs, \
  516. }, { \
  517. Pfx##QueryInterface, \
  518. Pfx##AddRef, \
  519. Pfx##Release, \
  520. #define Secondary_Interface_Begin(C, I, nm) \
  521. _Secondary_Interface_Begin(C, I, FIELD_OFFSET(C, nm), Common_) \
  522. #define _Secondary_Interface_End(C, I) \
  523. } }; \
  524. #define Secondary_Interface_End(C, I, nm) \
  525. _Secondary_Interface_End(C, I) \
  526. #define Interface_Template_Begin(C) \
  527. PV c_rgpv##C##Vtbl[] = { \
  528. #define Primary_Interface_Template(C, I) \
  529. Class_Vtbl(C, I), \
  530. #define Secondary_Interface_Template(C, I) \
  531. Class_Vtbl(C, I), \
  532. #define Interface_Template_End(C) \
  533. }; \
  534. STDMETHODIMP Common_QueryInterface(PV, RIID, PPV);
  535. STDMETHODIMP_(ULONG) Common_AddRef(PV pv);
  536. STDMETHODIMP_(ULONG) Common_Release(PV pv);
  537. STDMETHODIMP Common_QIHelper(PV, RIID, PPV);
  538. void EXTERNAL Common_Finalize(PV);
  539. #ifndef MAXDEBUG
  540. #define _Common_New_(cb, punkOuter, vtbl, pvpObj, z) \
  541. __Common_New_(cb, punkOuter, vtbl, pvpObj) \
  542. #define _Common_NewRiid_(cb, vtbl, punkOuter, riid, pvpObj, z) \
  543. __Common_NewRiid_(cb, vtbl, punkOuter, riid, pvpObj) \
  544. #endif
  545. STDMETHODIMP
  546. _Common_New_(ULONG cb, PUNK punkOuter, PV vtbl, PPV ppvObj, LPCSTR s_szProc);
  547. STDMETHODIMP
  548. _Common_NewRiid_(ULONG cb, PV vtbl, PUNK punkOuter, RIID riid, PPV pvpObj,
  549. LPCSTR s_szProc);
  550. #define Common_NewCb(cb, C, punkOuter, ppvObj) \
  551. _Common_New_(cb, punkOuter, Class_Vtbl(C, ThisInterface), ppvObj, s_szProc)
  552. #define Common_New(C, punkOuter, ppvObj) \
  553. Common_NewCb(cbX(C), C, punkOuter, ppvObj) \
  554. #define Common_NewCbRiid(cb, C, punkOuter, riid, ppvObj) \
  555. _Common_NewRiid_(cb, Class_Vtbl(C, ThisInterface), punkOuter, riid, ppvObj, s_szProc)
  556. #define Common_NewRiid(C, punkOuter, riid, ppvObj) \
  557. _Common_NewRiid_(cbX(C), Class_Vtbl(C, ThisInterface), punkOuter, riid, ppvObj, s_szProc)
  558. #ifdef DEBUG
  559. PV EXTERNAL Common_IsType(PV pv);
  560. #else
  561. #define Common_IsType
  562. #endif
  563. #define Assert_CommonType Common_IsType
  564. STDMETHODIMP Forward_QueryInterface(PV pv, RIID riid, PPV ppvObj);
  565. STDMETHODIMP_(ULONG) Forward_AddRef(PV pv);
  566. STDMETHODIMP_(ULONG) Forward_Release(PV pv);
  567. void EXTERNAL Invoke_Release(PPV pv);
  568. #define Common_DumpObjects()
  569. /*****************************************************************************
  570. *
  571. * OLE wrappers
  572. *
  573. * These basically do the same as IUnknown_Mumble, except that they
  574. * avoid side-effects in evaluation by being inline functions.
  575. *
  576. *****************************************************************************/
  577. HRESULT INLINE
  578. OLE_QueryInterface(PV pv, RIID riid, PPV ppvObj)
  579. {
  580. PUNK punk = pv;
  581. return punk->lpVtbl->QueryInterface(punk, riid, ppvObj);
  582. }
  583. ULONG INLINE
  584. OLE_AddRef(PV pv)
  585. {
  586. PUNK punk = pv;
  587. return punk->lpVtbl->AddRef(punk);
  588. }
  589. ULONG INLINE
  590. OLE_Release(PV pv)
  591. {
  592. PUNK punk = pv;
  593. return punk->lpVtbl->Release(punk);
  594. }
  595. /*****************************************************************************
  596. *
  597. * Macros that forward to the common handlers after DebugOuting.
  598. * Use these only in DEBUG.
  599. *
  600. * It is assumed that DbgFl has been #define'd to the appropriate DbgFl.
  601. *
  602. *****************************************************************************/
  603. #ifdef DEBUG
  604. #define Default_QueryInterface(Class) \
  605. STDMETHODIMP \
  606. Class##_QueryInterface(PV pv, RIID riid, PPV ppvObj) \
  607. { \
  608. DebugOutPtszV(DbgFl, TEXT(#Class) TEXT("_QueryInterface()")); \
  609. return Common_QueryInterface(pv, riid, ppvObj); \
  610. } \
  611. #define Default_AddRef(Class) \
  612. STDMETHODIMP_(ULONG) \
  613. Class##_AddRef(PV pv) \
  614. { \
  615. ULONG ulRc = Common_AddRef(pv); \
  616. DebugOutPtszV(DbgFl, TEXT(#Class) \
  617. TEXT("_AddRef(%08x) -> %d"), pv, ulRc); \
  618. return ulRc; \
  619. } \
  620. #define Default_Release(Class) \
  621. STDMETHODIMP_(ULONG) \
  622. Class##_Release(PV pv) \
  623. { \
  624. ULONG ulRc = Common_Release(pv); \
  625. DebugOutPtszV(DbgFl, TEXT(#Class) \
  626. TEXT("_Release(%08x) -> %d"), pv, ulRc); \
  627. return ulRc; \
  628. } \
  629. #endif
  630. /*****************************************************************************
  631. *
  632. * Paranoid callbacks
  633. *
  634. * Callback() performs a callback. The callback must accept exactly
  635. * two parameters, both pointers. (All our callbacks are like this.)
  636. * And it must return a BOOL.
  637. *
  638. *****************************************************************************/
  639. typedef BOOL (FAR PASCAL * STICALLBACKPROC)(LPVOID, LPVOID);
  640. #ifdef MAXDEBUG
  641. BOOL EXTERNAL Callback(STICALLBACKPROC, PVOID, PVOID);
  642. #else
  643. #define Callback(pec, pv1, pv2) pec(pv1, pv2)
  644. #endif
  645. /*
  646. * Describes the CLSIDs we provide to OLE.
  647. */
  648. typedef STDMETHOD(CREATEFUNC)(PUNK punkOuter, RIID riid, PPV ppvOut);
  649. typedef struct CLSIDMAP {
  650. REFCLSID rclsid; /* The clsid */
  651. CREATEFUNC pfnCreate; /* How to create it */
  652. UINT ids; /* String that describes it */
  653. } CLSIDMAP, *PCLSIDMAP;
  654. #define cclsidmap 1 /* CLSID_Sti */
  655. extern CLSIDMAP c_rgclsidmap[cclsidmap];
  656. /*****************************************************************************
  657. *
  658. * sti.c - Basic DLL stuff
  659. *
  660. *****************************************************************************/
  661. void EXTERNAL DllEnterCrit(void);
  662. void EXTERNAL DllLeaveCrit(void);
  663. void EXTERNAL DllAddRef(void);
  664. void EXTERNAL DllRelease(void);
  665. BOOL EXTERNAL DllInitializeCOM(void);
  666. BOOL EXTERNAL DllUnInitializeCOM(void);
  667. extern CHAR szProcessCommandLine[];
  668. #ifdef DEBUG
  669. extern UINT g_thidCrit;
  670. #define InCrit() (g_thidCrit == GetCurrentThreadId())
  671. #endif
  672. /*****************************************************************************
  673. *
  674. * sticf.c - IClassFactory implementation
  675. *
  676. *****************************************************************************/
  677. STDMETHODIMP CSti_Factory_New(CREATEFUNC pfnCreate, RIID riid, PPV ppvObj);
  678. /*****************************************************************************
  679. *
  680. * device.c - IStiDevice implementation
  681. *
  682. *****************************************************************************/
  683. #define STI_MUTEXNAME_PREFIX L"STIDeviceMutex_"
  684. STDMETHODIMP CStiDevice_New(PUNK punkOuter, RIID riid, PPV ppvObj);
  685. STDMETHODIMP OpenDeviceRegistryKey(LPCWSTR pwszDeviceName,LPCWSTR pwszSubKeyName,HKEY *phkeyDeviceParameters);
  686. /*****************************************************************************
  687. *
  688. * passusd.c - Pass through USD
  689. *
  690. *****************************************************************************/
  691. #define StiReadControlInfo STI_RAW_RESERVED+1
  692. #define StiWriteControlInfo STI_RAW_RESERVED+2
  693. #define StiTransact STI_RAW_RESERVED+3
  694. STDMETHODIMP CStiEmptyUSD_New(PUNK punkOuter, RIID riid, PPV ppvObj);
  695. /*****************************************************************************
  696. *
  697. * hel.c - Hardware emulation layer
  698. *
  699. *****************************************************************************/
  700. //
  701. // Device types
  702. //
  703. #define HEL_DEVICE_TYPE_WDM 1
  704. #define HEL_DEVICE_TYPE_PARALLEL 2
  705. #define HEL_DEVICE_TYPE_SERIAL 3
  706. //
  707. // Device open flags
  708. //
  709. #define STI_HEL_OPEN_CONTROL 0x00000001
  710. #define STI_HEL_OPEN_DATA 0x00000002
  711. STDMETHODIMP NewDeviceControl(DWORD dwDeviceType,DWORD dwMode,LPCWSTR pwszPortName,DWORD dwFlags,PSTIDEVICECONTROL *ppDevCtl);
  712. STDMETHODIMP CWDMDeviceControl_New(PUNK punkOuter, RIID riid, PPV ppvObj);
  713. STDMETHODIMP CCommDeviceControl_New(PUNK punkOuter, RIID riid, PPV ppvObj);
  714. /*****************************************************************************
  715. *
  716. * util.c - Misc utilities
  717. *
  718. *****************************************************************************/
  719. #define ctchGuid (1 + 8 + 1 + 4 + 1 + 4 + 1 + 4 + 1 + 12 + 1 + 1)
  720. #ifndef MAXDEBUG
  721. #define hresValidInstanceVer_(hinst, dwVer, z) \
  722. _hresValidInstanceVer_(hinst, dwVer) \
  723. #endif
  724. HRESULT EXTERNAL
  725. hresValidInstanceVer_(HINSTANCE hinst, DWORD dwVersion, LPCSTR s_szProc);
  726. #define hresValidInstanceVer(hinst, dwVer) \
  727. hresValidInstanceVer_(hinst, dwVer, s_szProc) \
  728. HRESULT
  729. EXTERNAL
  730. DupEventHandle(HANDLE h, LPHANDLE phOut);
  731. PV EXTERNAL
  732. pvFindResource(HINSTANCE hinst, DWORD id, LPCTSTR rt);
  733. HRESULT
  734. ParseCommandLine(LPSTR lpszCmdLine,UINT *pargc,LPTSTR *argv);
  735. void WINAPI
  736. StiLogTrace(
  737. DWORD dwType,
  738. DWORD idMessage,
  739. ...
  740. );
  741. #endif // __cplusplus
  742. /*****************************************************************************
  743. *
  744. * olesupp.c - Misc utilities
  745. *
  746. *****************************************************************************/
  747. STDMETHODIMP
  748. MyCoCreateInstanceW(
  749. LPWSTR pwszClsid,
  750. LPUNKNOWN punkOuter,
  751. RIID riid,
  752. PPV ppvOut,
  753. HINSTANCE *phinst
  754. );
  755. STDMETHODIMP
  756. MyCoCreateInstanceA(
  757. LPSTR ptszClsid,
  758. LPUNKNOWN punkOuter,
  759. RIID riid,
  760. PPV ppvOut,
  761. HINSTANCE *phinst
  762. );
  763. /*****************************************************************************
  764. *
  765. * osutil.c - Misc utilities , specific for platform
  766. *
  767. *****************************************************************************/
  768. BOOL EXTERNAL OSUtil_IsPlatformUnicode(VOID);
  769. HRESULT WINAPI EXTERNAL OSUtil_GetWideString(LPWSTR *ppszWide,LPCSTR pszAnsi);
  770. HRESULT WINAPI EXTERNAL OSUtil_GetAnsiString(LPSTR * ppszAnsi,LPCWSTR lpszWide);
  771. HRESULT WINAPI
  772. OSUtil_RegOpenKeyExW(HKEY hKey,LPCWSTR lpszKeyStrW,DWORD dwReserved,REGSAM samDesired,PHKEY phkResult);
  773. LONG WINAPI
  774. OSUtil_RegCreateKeyExW(
  775. HKEY hKey, LPWSTR lpszSubKeyW, DWORD dwReserved, LPWSTR lpszClassW, DWORD dwOptions,
  776. REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition);
  777. LONG WINAPI
  778. OSUtil_RegQueryValueExW(HKEY hKey,LPCWSTR lpszValueNameW,DWORD *pdwType,BYTE* lpData,DWORD *pcbData,BOOL fUnicodeCaller);
  779. LONG WINAPI
  780. OSUtil_RegSetValueExW(HKEY hKey,LPCWSTR lpszValueNameW,DWORD dwType,BYTE* lpData,DWORD cbData,BOOL fUnicodeCaller);
  781. HRESULT
  782. ReadRegistryStringA(HKEY hkey,LPCWSTR pszValueNameW,LPCWSTR pszDefaultValueW,BOOL fExpand,LPWSTR * ppwszResult);
  783. HRESULT
  784. ReadRegistryStringW(HKEY hkey,LPCWSTR pszValueNameW,LPCWSTR pszDefaultValueW,BOOL fExpand,LPWSTR * ppwszResult);
  785. #ifdef UNICODE
  786. #define ReadRegistryString ReadRegistryStringW
  787. #else
  788. #define ReadRegistryString ReadRegistryStringA
  789. #endif
  790. DWORD
  791. ReadRegistryDwordW( HKEY hkey,LPCWSTR pszValueNameW,DWORD dwDefaultValue );
  792. DWORD
  793. WriteRegistryStringA(
  794. IN HKEY hkey,
  795. IN LPCSTR pszValueName,
  796. IN LPCSTR pszValue,
  797. IN DWORD cbValue,
  798. IN DWORD fdwType);
  799. DWORD
  800. WriteRegistryStringW(IN HKEY hkey,
  801. IN LPCWSTR pszValueNameW,IN LPCWSTR pszValueW,IN DWORD cbValue,IN DWORD fdwType);
  802. LONG WINAPI
  803. OSUtil_RegDeleteValueW(HKEY hKey,LPWSTR lpszValueNameW);
  804. HANDLE WINAPI
  805. OSUtil_CreateFileW(
  806. LPCWSTR lpszFileNameW,DWORD dwDesiredAccess,DWORD dwShareMode,LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  807. DWORD dwCreationDisposition,DWORD dwFlagsAndAttributes,HANDLE hTemplateFile);
  808. HRESULT
  809. WINAPI
  810. ExtractCommandLineArgumentW(
  811. LPCSTR lpszSwitchName,
  812. LPWSTR pwszSwitchValue
  813. );
  814. HRESULT
  815. WINAPI
  816. ExtractCommandLineArgumentA(
  817. LPCSTR lpszSwitchName,
  818. LPSTR pszSwitchValue
  819. );
  820. /*****************************************************************************
  821. *
  822. * string.c - Misc utilities , specific for platform
  823. * Nb: Prorotypes for Cruntime string functions are in string.h
  824. *
  825. *****************************************************************************/
  826. #pragma intrinsic(memcmp,memset,memcpy)
  827. #define OSUtil_StrLenW wcslen
  828. #define OSUtil_StrCmpW wcscmp
  829. #define OSUtil_lstrcpyW wcscpy
  830. #define OSUtil_lstrcatW wcscat
  831. #define OSUtil_lstrcpynW wcsncpy
  832. // Security.c
  833. DWORD
  834. CreateWellKnownSids(
  835. VOID
  836. );
  837. VOID
  838. FreeWellKnownSids(
  839. VOID
  840. );
  841. DWORD
  842. CreateGlobalSyncObjectSD(
  843. OUT PSECURITY_DESCRIPTOR *NewDescriptor
  844. );
  845. /*****************************************************************************
  846. *
  847. * mem.c - Memory management
  848. *
  849. * Be extremely careful with FreePv, because it doesn't work if
  850. * the pointer is null.
  851. *
  852. *****************************************************************************/
  853. HRESULT INLINE
  854. AllocCbPpv(UINT cb, PPV ppv)
  855. {
  856. HRESULT hres;
  857. *ppv = LocalAlloc(LPTR, cb);
  858. hres = *ppv ? NOERROR : E_OUTOFMEMORY;
  859. return hres;
  860. }
  861. #define FreePv(pv) LocalFree((HLOCAL)(pv))
  862. void INLINE
  863. FreePpv(PPV ppv)
  864. {
  865. PV pv = (PV)InterlockedExchangePointer(ppv,(PV) 0);
  866. if (pv) {
  867. FreePv(pv);
  868. }
  869. }
  870. #if 0
  871. #define NEED_REALLOC
  872. STDMETHODIMP EXTERNAL ReallocCbPpv(UINT cb, PV ppvObj);
  873. STDMETHODIMP EXTERNAL AllocCbPpv(UINT cb, PV ppvObj);
  874. #ifdef NEED_REALLOC
  875. #define FreePpv(ppv) (void)ReallocCbPpv(0, ppv)
  876. #else
  877. void EXTERNAL FreePpv(PV ppv);
  878. #define FreePpv(ppv) FreePpv(ppv)
  879. #endif
  880. #endif
  881. #ifdef __cplusplus
  882. };
  883. #endif