Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

951 lines
35 KiB

  1. /****************************************************************************/
  2. /* util.h */
  3. /* */
  4. /* Utility API header */
  5. /* */
  6. /* Copyright(C) Microsoft Corporation 1997-1999 */
  7. /****************************************************************************/
  8. #ifndef _H_UT
  9. #define _H_UT
  10. #define _H_AUTDATA
  11. #define _H_AUTAPI
  12. extern "C" {
  13. #include <autreg.h>
  14. #include <compress.h>
  15. #include <winsock.h>
  16. }
  17. #ifndef OS_WINCE
  18. #include "shlobj.h"
  19. #endif
  20. /****************************************************************************/
  21. /* */
  22. /* CONSTANTS */
  23. /* */
  24. /****************************************************************************/
  25. #define UT_MAX_DOMAIN_LENGTH 52
  26. #define UT_MAX_USERNAME_LENGTH 512
  27. #define UT_MAX_PASSWORD_LENGTH 32
  28. #define UT_FILENAME_MAX_LENGTH 15
  29. #define UT_MAX_WORKINGDIR_LENGTH 512
  30. #define UT_MAX_ALTERNATESHELL_LENGTH 512
  31. #define UT_MAX_ADDRESS_LENGTH 256
  32. #define UT_REGSESSION_MAX_LENGTH 32
  33. #define UT_MAX_SUBKEY 265
  34. #define UT_SALT_LENGTH 20
  35. #define UT_COMPUTERNAME_SECTION "Network"
  36. #define UT_COMPUTERNAME_KEY "ComputerName"
  37. #define UT_COMPUTERNAME_FILE "SYSTEM.INI"
  38. #ifdef DC_DEBUG
  39. /****************************************************************************/
  40. /* Random Failure iemIDs */
  41. /****************************************************************************/
  42. #define UT_FAILURE_BASE 0x3256
  43. #define UT_FAILURE_ITEM(n) ((DCUINT) UT_FAILURE_BASE + (n) )
  44. #define UT_FAILURE_MALLOC UT_FAILURE_ITEM(0)
  45. #define UT_FAILURE_MALLOC_HUGE UT_FAILURE_ITEM(1)
  46. #define UT_FAILURE_MAX_INDEX 1
  47. #endif /* DC_DEBUG */
  48. /****************************************************************************/
  49. /* */
  50. /* TYPEDEFS */
  51. /* */
  52. /****************************************************************************/
  53. /****************************************************************************/
  54. /* Structure passed into thread entry functions created by */
  55. /* UT_StartThread(). */
  56. /****************************************************************************/
  57. typedef DCVOID (DCAPI * UTTHREAD_PROC)(PDCVOID);
  58. /****************************************************************************/
  59. /* Structure: UT_THREAD_DATA */
  60. /* */
  61. /* Description: */
  62. /****************************************************************************/
  63. typedef struct tagUT_THREAD_DATA
  64. {
  65. DWORD threadID;
  66. ULONG_PTR threadHnd;
  67. } UT_THREAD_DATA, DCPTR PUT_THREAD_DATA;
  68. // forward declaration
  69. class CUT;
  70. /****************************************************************************/
  71. /* Structure: UT_THREAD_INFO */
  72. /* */
  73. /* Description: Passes params to UTThreadEntry */
  74. /****************************************************************************/
  75. typedef struct tagUT_THREAD_INFO
  76. {
  77. UTTHREAD_PROC pFunc;
  78. ULONG_PTR sync;
  79. PDCVOID threadParam;
  80. } UT_THREAD_INFO, DCPTR PUT_THREAD_INFO;
  81. /****************************************************************************/
  82. /* */
  83. /* INLINE FUNCTIONS */
  84. /* */
  85. /****************************************************************************/
  86. /****************************************************************************/
  87. /* */
  88. /* FUNCTION MACRO WRAPPERS */
  89. /* */
  90. /****************************************************************************/
  91. #ifdef DC_DEBUG
  92. /****************************************************************************/
  93. /* Use the comma operator because UT_... return values and so the entire */
  94. /* macro must also return a value. */
  95. /* Use different macros for non-DEBUG because TRC_NRM macros to nothing and */
  96. /* the comma operator cannot take 'nothing' as its first parameter. */
  97. /****************************************************************************/
  98. #define UT_Malloc(utinst, X) (utinst)->UT_MallocDbg(X, trc_fn)
  99. #define UT_MallocHuge(utinst, X) \
  100. (TRC_NRM((TB, _T("%s calling UT_MallocHuge for %#x bytes"), trc_fn, X)), \
  101. (utinst)->UT_MallocHugeReal(X))
  102. #define UT_Free(utinst, X) (TRC_NRM((TB, _T("%s freeing %p"), trc_fn, X)), \
  103. (utinst)->UT_FreeReal(X))
  104. #else
  105. #define UT_Malloc(utinst,X) LocalAlloc(LPTR, X)
  106. #define UT_MallocHuge(utinst, X) LocalAlloc(LPTR, X)
  107. #define UT_Free(utinst, X) LocalFree(X)
  108. #endif
  109. /****************************************************************************/
  110. /* */
  111. /* SIMPLE MACROS FOR BUFFER CHECKS */
  112. /* */
  113. /****************************************************************************/
  114. // Check for lenInner<lenOuter is purely to prevent overflow in pointer arithmetic
  115. #define IsContainedMemory(pOuter,lenOuter,pInner,lenInner) \
  116. (((LPBYTE)(pInner) >= (LPBYTE)(pOuter)) && \
  117. ((lenInner) <= (lenOuter)) && \
  118. (((LPBYTE)(pInner)) + (lenInner) >= ((LPBYTE)(pOuter))) && \
  119. (((LPBYTE)(pInner)) + (lenInner) <= ((LPBYTE)(pOuter)) + (lenOuter)))
  120. #define IsContainedPointer(pOuter,lenOuter,pInner) \
  121. (((LPBYTE)(pInner) >= (LPBYTE)(pOuter)) && \
  122. ((LPBYTE)(pInner) < ((LPBYTE)(pOuter)) + (lenOuter)))
  123. /****************************************************************************/
  124. /* Automatic Session Info */
  125. /****************************************************************************/
  126. #define MAX_SESSIONINFO_NAME 32
  127. #define MAX_SESSIONINFO_SECTIONNAME MAX_SESSIONINFO_NAME + sizeof(UTREG_SESSIONINFO_ROOT)
  128. #define MAKE_SESSIONINFO_SECTION(BUFF, SESSIONNAME) \
  129. DC_TSTRCPY(BUFF, UTREG_SESSIONINFO_ROOT); \
  130. DC_TSTRCAT(BUFF, SESSIONNAME)
  131. //
  132. // From autdata.h
  133. //
  134. /****************************************************************************/
  135. /* */
  136. /* External DLL */
  137. /* *
  138. /****************************************************************************/
  139. typedef union _FUNCTIONPORT {
  140. #ifndef OS_WINCE
  141. LPCSTR pszFunctionName;
  142. #else
  143. LPCTSTR pszFunctionName;
  144. #endif
  145. FARPROC lpfnFunction;
  146. } FUNCTIONPORT, *PFUNCTIONPORT;
  147. #if defined(OS_WIN32)
  148. /****************************************************************************/
  149. /* IMM32 DLL */
  150. /****************************************************************************/
  151. typedef union _IMM32_FUNCTION {
  152. #ifndef OS_WINCE
  153. FUNCTIONPORT rgFunctionPort[3];
  154. #else
  155. FUNCTIONPORT rgFunctionPort[2];
  156. #endif
  157. struct {
  158. HIMC (CALLBACK* _ImmAssociateContext)(
  159. IN HWND hWnd,
  160. IN HIMC hImc
  161. );
  162. BOOL (CALLBACK* _ImmGetIMEFileNameW)(
  163. IN HKL hkl,
  164. OUT LPWSTR lpwszFileName,
  165. OUT UINT uBufferLength
  166. );
  167. #ifndef OS_WINCE
  168. BOOL (CALLBACK* _ImmGetIMEFileNameA)(
  169. IN HKL hkl,
  170. OUT LPSTR lpszFileName,
  171. OUT UINT uBufferLength
  172. );
  173. #endif
  174. };
  175. } IMM32_FUNCTION, *PIMM32_FUNCTION;
  176. typedef struct _IMM32DLL {
  177. HINSTANCE hInst;
  178. IMM32_FUNCTION func;
  179. } IMM32DLL, *PIMM32DLL;
  180. #define lpfnImmAssociateContext _UT.Imm32Dll.func._ImmAssociateContext
  181. #endif // OS_WIN32
  182. #if !defined(OS_WINCE)
  183. /****************************************************************************/
  184. /* WINNLS DLL */
  185. /****************************************************************************/
  186. #if !defined(OS_WINCE)
  187. #include <winnls32.h>
  188. #endif
  189. typedef union _WINNLS_FUNCTION {
  190. FUNCTIONPORT rgFunctionPort[3];
  191. struct {
  192. BOOL (CALLBACK* _WINNLSEnableIME)(
  193. IN HANDLE hWnd,
  194. IN BOOL fEnable
  195. );
  196. BOOL (CALLBACK* _IMPGetIMEW)(
  197. IN HWND hWnd,
  198. OUT LPIMEPROW lpImePro
  199. );
  200. BOOL (CALLBACK* _IMPGetIMEA)(
  201. IN HWND hWnd,
  202. OUT LPIMEPROA lpImePro
  203. );
  204. };
  205. } WINNLS_FUNCTION, *PWINNLS_FUNCTION;
  206. typedef struct _WINNLSDLL {
  207. HINSTANCE hInst;
  208. WINNLS_FUNCTION func;
  209. } WINNLSDLL, *PWINNLSDLL;
  210. #define lpfnWINNLSEnableIME _UT.WinnlsDll.func._WINNLSEnableIME
  211. #endif // !defined(OS_WINCE)
  212. #if defined(OS_WINNT)
  213. /****************************************************************************/
  214. /* F3AHVOAS DLL */
  215. /****************************************************************************/
  216. typedef union _F3AHVOASYS_FUNCTION {
  217. FUNCTIONPORT rgFunctionPort[1];
  218. struct {
  219. VOID (CALLBACK* _FujitsuOyayubiControl)(
  220. IN DWORD dwImeOpen,
  221. IN DWORD dwImeConversionMode
  222. );
  223. };
  224. } F3AHVOASYS_FUNCTION, *PF3AHVOASYS_FUNCTION;
  225. typedef struct _F3AHVOASYSDLL {
  226. HINSTANCE hInst;
  227. F3AHVOASYS_FUNCTION func;
  228. } F3AHVOASYSDLL, *PF3AHVOASYSDLL;
  229. #define lpfnFujitsuOyayubiControl _UT.F3AHVOasysDll.func._FujitsuOyayubiControl
  230. #endif // OS_WINNT
  231. /****************************************************************************/
  232. /* Prototypes */
  233. /****************************************************************************/
  234. /****************************************************************************/
  235. /* Structure: UT_DATA */
  236. /* */
  237. /* Description: */
  238. /****************************************************************************/
  239. typedef struct tagUT_DATA
  240. {
  241. HKEY enumHKey;
  242. DCTCHAR sessionName[UT_REGSESSION_MAX_LENGTH];
  243. #if defined(OS_WIN32)
  244. IMM32DLL Imm32Dll;
  245. #endif // OS_WIN32
  246. #if !defined(OS_WINCE)
  247. WINNLSDLL WinnlsDll;
  248. #endif // !defined(OS_WINCE)
  249. #if defined(OS_WINNT)
  250. F3AHVOASYSDLL F3AHVOasysDll;
  251. #endif // OS_WINNT
  252. #ifdef DC_DEBUG
  253. DCINT failPercent[UT_FAILURE_MAX_INDEX + 1];
  254. #endif /* DC_DEBUG */
  255. DCINT osMinorType;
  256. HINSTANCE hInstance;
  257. #ifdef DC_DEBUG
  258. DWORD dwDebugThreadWaitTimeout;
  259. #endif
  260. } UT_DATA, DCPTR PUT_DATA;
  261. /****************************************************************************/
  262. /* */
  263. /* HOTKEY structure */
  264. /* *
  265. /* */
  266. /****************************************************************************/
  267. typedef struct tagDCHOTKEY
  268. {
  269. DCUINT fullScreen;
  270. DCUINT ctrlEsc;
  271. DCUINT altEsc;
  272. DCUINT altTab;
  273. DCUINT altShifttab;
  274. DCUINT altSpace;
  275. DCUINT ctlrAltdel;
  276. } DCHOTKEY;
  277. typedef DCHOTKEY DCPTR PDCHOTKEY;
  278. /*Hotkey structure*/
  279. VOID DisableIME(HWND hwnd);
  280. VOID UIGetIMEFileName(PDCTCHAR imeFileName, DCUINT Size);
  281. VOID UIGetIMEFileName16(PDCTCHAR imeFileName, DCUINT Size);
  282. class CUT
  283. {
  284. public:
  285. CUT();
  286. ~CUT();
  287. /****************************************************************************/
  288. /* */
  289. /* API FUNCTION PROTOTYPES */
  290. /* */
  291. /****************************************************************************/
  292. DCVOID DCAPI UT_Init(DCVOID);
  293. DCVOID DCAPI UT_Term(DCVOID);
  294. DCBOOL DCAPI UT_StartThread(UTTHREAD_PROC entryFunction,
  295. PUT_THREAD_DATA pThreadData,
  296. PDCVOID pThreadParam);
  297. DCBOOL DCAPI UT_DestroyThread(UT_THREAD_DATA threadData,
  298. BOOL fPumpMessages = FALSE);
  299. static DWORD UT_WaitWithMessageLoop(HANDLE hEvent, ULONG Timeout);
  300. DCUINT DCINTERNAL UT_GetANSICodePage(DCVOID);
  301. PDCVOID DCAPI UT_MallocReal(DCUINT length);
  302. DCVOID DCAPI UT_FreeReal(PDCVOID pMemory);
  303. HPDCVOID DCAPI UT_MallocHugeReal(DCUINT32 length);
  304. DCVOID DCAPI UT_ReadRegistryString( PDCTCHAR pSection,
  305. PDCTCHAR pEntry,
  306. PDCTCHAR pDefaultValue,
  307. PDCTCHAR pBuffer,
  308. DCINT bufferSize );
  309. DCBOOL DCAPI UT_ReadRegistryExpandSZ(PDCTCHAR pSection,
  310. PDCTCHAR pEntry,
  311. PDCTCHAR* ppBuffer,
  312. PDCINT pBufferSize );
  313. DCINT DCAPI UT_ReadRegistryInt( PDCTCHAR pSection,
  314. PDCTCHAR pEntry,
  315. DCINT defaultValue );
  316. DCVOID DCAPI UT_ReadRegistryBinary(PDCTCHAR pSection,
  317. PDCTCHAR pEntry,
  318. PDCTCHAR pBuffer,
  319. DCINT bufferSize);
  320. DCBOOL DCAPI UT_EnumRegistry( PDCTCHAR pSection,
  321. DCUINT32 index,
  322. PDCTCHAR pBuffer,
  323. PDCINT pBufferSize );
  324. DCUINT DCAPI UT_WriteRegistryString( PDCTCHAR pSection,
  325. PDCTCHAR pEntry,
  326. PDCTCHAR pDefaultValue,
  327. PDCTCHAR pBuffer );
  328. DCUINT DCAPI UT_WriteRegistryInt( PDCTCHAR pSection,
  329. PDCTCHAR pEntry,
  330. DCINT defaultValue,
  331. DCINT value );
  332. PRNS_UD_HEADER DCAPI UT_ParseUserData(PRNS_UD_HEADER pUserData,
  333. DCUINT userDataLen,
  334. DCUINT16 typeRequested);
  335. DCBOOL DCAPI UT_WriteRegistryBinary(PDCTCHAR pSection,
  336. PDCTCHAR pEntry,
  337. PDCTCHAR pBuffer,
  338. DCINT bufferSize);
  339. PDCVOID DCINTERNAL UT_GetCapsSet(DCUINT capsLength,
  340. PTS_COMBINED_CAPABILITIES pCaps,
  341. DCUINT capsSet);
  342. DCUINT DCAPI UT_SetScrollInfo(HWND hwnd,
  343. DCINT scrollBarFlag,
  344. LPSCROLLINFO pScrollInfo,
  345. DCBOOL redraw);
  346. DCBOOL DCINTERNAL UT_IsNEC98platform(DCVOID);
  347. DCBOOL DCINTERNAL UT_IsNX98Key(DCVOID);
  348. DCBOOL DCINTERNAL UT_IsNew106Layout(DCVOID);
  349. DCBOOL DCINTERNAL UT_IsFujitsuLayout(DCVOID);
  350. DCBOOL DCINTERNAL UT_IsKorean101LayoutForWin9x(DCVOID);
  351. DCBOOL DCINTERNAL UT_IsKorean101LayoutForNT351(DCVOID);
  352. DCBOOL DCAPI UT_GetComputerName(PDCTCHAR szBuff, DCUINT32 len);
  353. BOOL DCAPI UT_GetComputerAddressW(PDCUINT8 szBuff);
  354. BOOL DCAPI UT_GetComputerAddressA(PDCUINT8 szBuff);
  355. BOOL DCAPI UT_GetClientDirW(PDCUINT8 szBuff);
  356. DCBOOL DCINTERNAL UT_GetRealDriverNameNT(
  357. PDCTCHAR lpszRealDriverName,
  358. UINT cchDriverName);
  359. #ifdef OS_WINNT
  360. BOOL DCAPI UT_ValidateProductSuite(LPSTR SuiteName);
  361. BOOL DCAPI UT_IsTerminalServicesEnabled(VOID);
  362. #endif
  363. #if !defined(OS_WINCE)
  364. DCUINT DCINTERNAL UT_GetFullPathName(PDCTCHAR lpFileName,
  365. DCUINT nBufferLength,
  366. PDCTCHAR lpBuffer,
  367. PDCTCHAR *lpFilePart);
  368. #endif // !defined(OS_WINCE)
  369. #ifdef DC_DEBUG
  370. DCVOID DCAPI UT_SetRandomFailureItem(DCUINT itemID, DCINT percent);
  371. DCINT DCAPI UT_GetRandomFailureItem(DCUINT itemID);
  372. DCBOOL DCAPI UT_TestRandomFailure(DCUINT itemID);
  373. #endif /* DC_DEBUG */
  374. //
  375. // Time functions
  376. //
  377. HANDLE
  378. UTCreateTimer(
  379. HWND hWnd, // handle of window for timer messages
  380. DCUINT nIDEvent, // timer identifier
  381. DCUINT uElapse ); // time-out value
  382. DCBOOL
  383. UTStartTimer(
  384. HANDLE hTimer );
  385. DCBOOL
  386. UTStopTimer(
  387. HANDLE hTimer );
  388. DCBOOL
  389. UTDeleteTimer(
  390. HANDLE hTimer );
  391. HINSTANCE
  392. LoadExternalDll(
  393. LPCTSTR pszLibraryName,
  394. PFUNCTIONPORT rgFunction,
  395. DWORD dwItem
  396. );
  397. VOID
  398. InitExternalDll(
  399. VOID
  400. );
  401. public:
  402. //
  403. // Data members
  404. //
  405. UT_DATA _UT;
  406. public:
  407. #ifdef DC_DEBUG
  408. PDCVOID DCAPI UT_MallocDbg(DCUINT length, PDCTCHAR pCaller)
  409. {
  410. PDCVOID ptr;
  411. UNREFERENCED_PARAMETER( pCaller);
  412. DC_BEGIN_FN("UT_MallocDbg");
  413. ptr = UT_MallocReal(length);
  414. TRC_NRM((TB, _T("%s allocated %d bytes at %p"), pCaller, length, ptr));
  415. DC_END_FN();
  416. return(ptr);
  417. }
  418. #endif /* DC_DEBUG */
  419. /****************************************************************************/
  420. /* Name: UT_GetCurrentTimeMS */
  421. /* */
  422. /* Purpose: Returns the current system timer value in milliseconds. */
  423. /* */
  424. /* Returns: Millisecond timestamp. */
  425. /****************************************************************************/
  426. DCUINT32 DCAPI UT_GetCurrentTimeMS(DCVOID)
  427. {
  428. DCUINT32 rc;
  429. DC_BEGIN_FN("UT_GetCurrentTimeMS");
  430. rc = GetTickCount();
  431. DC_END_FN();
  432. return(rc);
  433. }
  434. /****************************************************************************/
  435. /* Name: UT_InterlockedExchange */
  436. /* */
  437. /* Purpose: Exchanges a given data value with the value in a given */
  438. /* location. */
  439. /* */
  440. /* Returns: Original data value from given location. */
  441. /* */
  442. /* Params: pData - pointer to data location */
  443. /* val - new data value */
  444. /****************************************************************************/
  445. DCUINT32 DCAPI UT_InterlockedExchange(PDCUINT32 pData, DCUINT32 val)
  446. {
  447. DCUINT32 rc;
  448. #ifdef OS_WIN32
  449. rc = (DCUINT32)InterlockedExchange((LPLONG)pData, (LONG)val);
  450. #else
  451. rc = *pData;
  452. *pData = val;
  453. #endif
  454. return(rc);
  455. }
  456. /****************************************************************************/
  457. /* Name: UT_InterlockedIncrement */
  458. /* */
  459. /* Purpose: Increments a 32-bit variable in a thread-safe manner. */
  460. /* */
  461. /* Params: Pointer to the DCINT32 to increment. */
  462. /****************************************************************************/
  463. DCVOID UT_InterlockedIncrement(PDCINT32 pData)
  464. {
  465. #ifdef OS_WIN32
  466. InterlockedIncrement((LPLONG)pData);
  467. #else
  468. *pData++;
  469. #endif
  470. } /* UT_InterlockedIncrement */
  471. /****************************************************************************/
  472. /* Name: UT_InterlockedDecrement */
  473. /* */
  474. /* Purpose: Decrements a 32-bit variable in a thread-safe manner. */
  475. /* */
  476. /* Params: Pointer to the DCINT32 to decrement. */
  477. /****************************************************************************/
  478. DCVOID UT_InterlockedDecrement(PDCINT32 pData)
  479. {
  480. #ifdef OS_WIN32
  481. InterlockedDecrement((LPLONG)pData);
  482. #else
  483. *pData--;
  484. #endif
  485. } /* UT_InterlockedDecrement */
  486. /****************************************************************************/
  487. /* Name: UT_GetSessionName */
  488. /* */
  489. /* Purpose: Return name of registry section for this session */
  490. /* */
  491. /* Params: pName (returned) - name of Session */
  492. /****************************************************************************/
  493. DCVOID UT_GetSessionName(LPTSTR szName, UINT cchName)
  494. {
  495. HRESULT hr;
  496. DC_BEGIN_FN("UT_GetSessionName");
  497. TRC_NRM((TB, _T("Name found >%s<"), _UT.sessionName));
  498. hr = StringCchCopy(szName, cchName, _UT.sessionName);
  499. if (FAILED(hr)) {
  500. TRC_ERR((TB,_T("StringCchCopy failed: 0x%x"),hr));
  501. }
  502. DC_END_FN();
  503. } /* UT_GetSessionName */
  504. /****************************************************************************/
  505. /* Name: UT_GetOsMinorType */
  506. /* */
  507. /* Purpose: Get the OS type */
  508. /* */
  509. /* Returns: OS type (one of the TS_OSMINORTYPE constants) */
  510. /****************************************************************************/
  511. DCUINT DCAPI UT_GetOsMinorType(DCVOID)
  512. {
  513. DCUINT rc;
  514. DC_BEGIN_FN("UI_GetOsMinorType");
  515. rc = _UT.osMinorType;
  516. DC_END_FN();
  517. return(rc);
  518. } /* UI_GetOsMinorType */
  519. /****************************************************************************/
  520. /* Name: UT_GetInstanceHandle */
  521. /* */
  522. /* Purpose: Return application hInstance */
  523. /* */
  524. /* Returns: hInstance */
  525. /****************************************************************************/
  526. HINSTANCE DCAPI UT_GetInstanceHandle(DCVOID)
  527. {
  528. HINSTANCE rc;
  529. DC_BEGIN_FN("UT_GetInstanceHandle");
  530. TRC_ASSERT((_UT.hInstance != 0), (TB, _T("Instance handle not set")));
  531. rc = _UT.hInstance;
  532. TRC_DBG((TB, _T("Return %p"), rc));
  533. DC_END_FN();
  534. return(rc);
  535. } /* UT_GetInstanceHandle */
  536. /****************************************************************************/
  537. /* Name: UT_SetInstanceHandle */
  538. /* */
  539. /* Purpose: Return application hInstance */
  540. /* */
  541. /* Returns: hInstance */
  542. /****************************************************************************/
  543. DCVOID DCAPI UT_SetInstanceHandle(HINSTANCE hInstance)
  544. {
  545. DC_BEGIN_FN("UT_SetInstanceHandle");
  546. TRC_ASSERT((_UT.hInstance == 0), (TB, _T("Set instance handle twice!")));
  547. TRC_ASSERT((hInstance != 0), (TB, _T("invalid (zero) instance handle")));
  548. _UT.hInstance = hInstance;
  549. DC_END_FN();
  550. } /* UT_SetInstanceHandle */
  551. static BOOL StringtoBinary(size_t cbInBuffer, PBYTE pbInBuffer,
  552. TCHAR *pszOutBuffer, DWORD *pcchOutBuffer);
  553. static BOOL BinarytoString(size_t cchInBuffer, TCHAR *pszInBuffer,
  554. PBYTE pbOutBuffer, DWORD *pcbOutBuffer);
  555. static BOOL ValidateServerName(LPCTSTR szServerName, BOOL fAllowPortSuffix);
  556. static INT GetPortNumberFromServerName(LPTSTR szServer);
  557. static VOID GetServerNameFromFullAddress(LPCTSTR szFullName,
  558. LPTSTR szServerOnly,
  559. ULONG len);
  560. static HRESULT
  561. GetCanonicalServerNameFromConnectString(
  562. IN LPCTSTR szConnectString,
  563. OUT LPTSTR szCanonicalServerName,
  564. ULONG cchLenOut
  565. );
  566. static BOOL IsSCardReaderInstalled();
  567. #ifndef OS_WINCE
  568. static BOOL NotifyShellOfFullScreen(HWND hwndMarkFullScreen,
  569. BOOL fNowFullScreen,
  570. ITaskbarList2** ppTsbl2,
  571. PBOOL pfQueriedForTaskbar);
  572. #endif
  573. //
  574. // Safe wrapper that validates a string length before doing the string copy
  575. //
  576. static HRESULT
  577. StringPropPut(
  578. LPTSTR szDestString,
  579. UINT cchDestLen,
  580. LPTSTR szSourceString
  581. );
  582. //
  583. // IME Wrapper functions
  584. //
  585. // These wrappers manage dynamically loading the IME dlls
  586. // and the appropriate unicode conversions on 9x where the
  587. // Unicode API's may not be available
  588. //
  589. UINT UT_ImmGetIMEFileName(IN HKL, OUT LPTSTR, IN UINT uBufLen);
  590. #if ! defined (OS_WINCE)
  591. BOOL UT_IMPGetIME( IN HWND, OUT LPIMEPRO);
  592. #endif
  593. static BOOL UT_IsScreen8bpp()
  594. {
  595. BOOL fUse8BitDepth = FALSE;
  596. HDC hdcScreen = GetDC(NULL);
  597. if (hdcScreen) {
  598. fUse8BitDepth = (GetDeviceCaps(hdcScreen, BITSPIXEL) <= 8);
  599. ReleaseDC(NULL, hdcScreen);
  600. }
  601. return fUse8BitDepth;
  602. }
  603. static HPALETTE UT_GetPaletteForBitmap(HDC hDCSrc, HBITMAP hBitmap);
  604. //
  605. // Internal functions
  606. //
  607. private:
  608. DCVOID DCINTERNAL UTGetCurrentTime(PDC_TIME pTime);
  609. DCBOOL DCINTERNAL UTReadEntry(HKEY topLevelKey,
  610. PDCTCHAR pSection,
  611. PDCTCHAR pEntry,
  612. PDCUINT8 pBuffer,
  613. DCINT bufferSize,
  614. DCINT32 expectedDataType);
  615. DCBOOL DCINTERNAL UTEnumRegistry( PDCTCHAR pSection,
  616. DCUINT32 index,
  617. PDCTCHAR pBuffer,
  618. PDCINT pBufferSize );
  619. DCBOOL DCINTERNAL UTWriteEntry(HKEY topLevelKey,
  620. PDCTCHAR pSection,
  621. PDCTCHAR pEntry,
  622. PDCUINT8 pData,
  623. DCINT dataSize,
  624. DCINT32 dataType);
  625. DCBOOL DCINTERNAL UTReadRegistryString(PDCTCHAR pSection,
  626. PDCTCHAR pEntry,
  627. PDCTCHAR pBuffer,
  628. DCINT bufferSize);
  629. DCBOOL DCINTERNAL UTReadRegistryExpandString(PDCTCHAR pSection,
  630. PDCTCHAR pEntry,
  631. PDCTCHAR* ppBuffer,
  632. PDCINT pBufferSize);
  633. DCBOOL DCINTERNAL UTReadRegistryInt(PDCTCHAR pSection,
  634. PDCTCHAR pEntry,
  635. PDCINT pValue);
  636. DCBOOL DCINTERNAL UTReadRegistryBinary(PDCTCHAR pSection,
  637. PDCTCHAR pEntry,
  638. PDCTCHAR pBuffer,
  639. DCINT bufferSize);
  640. DCBOOL DCINTERNAL UTWriteRegistryString(PDCTCHAR pSection,
  641. PDCTCHAR pEntry,
  642. PDCTCHAR pBuffer);
  643. DCBOOL DCINTERNAL UTWriteRegistryInt(PDCTCHAR pSection,
  644. PDCTCHAR pEntry,
  645. DCINT value);
  646. DCBOOL DCINTERNAL UTWriteRegistryBinary(PDCTCHAR pSection,
  647. PDCTCHAR pEntry,
  648. PDCTCHAR pBuffer,
  649. DCINT bufferSize);
  650. DCBOOL DCINTERNAL UTDeleteEntry(PDCTCHAR pSection,
  651. PDCTCHAR pEntry);
  652. DCUINT DCINTERNAL UTSetScrollInfo(HWND hwnd,
  653. DCINT scrollBarFlag,
  654. LPSCROLLINFO pScrollInfo,
  655. DCBOOL redraw);
  656. DCUINT32 DCAPI UTInterlockedExchange(PDCUINT32 pData, DCUINT32 val);
  657. #include "wutint.h"
  658. };
  659. //Old name
  660. #define SIZECHAR(x) sizeof(x)/sizeof(TCHAR)
  661. #define CHECK_READ_ONE_BYTE(pBuffer, pEnd, hr, trc ) \
  662. {\
  663. if (((BYTE*)(pBuffer)) >= (BYTE*)(pEnd)) { \
  664. TRC_ABORT( trc ); \
  665. hr = E_TSC_CORE_LENGTH; \
  666. DC_QUIT; \
  667. } \
  668. }
  669. #define CHECK_READ_ONE_BYTE_2ENDED(pBuffer, pStart, pEnd, hr, trc ) \
  670. {\
  671. if (((BYTE*)(pBuffer)) >= (BYTE*)(pEnd) || \
  672. (BYTE*)(pBuffer) < (BYTE*)(pStart)) { \
  673. TRC_ABORT( trc ); \
  674. hr = E_TSC_CORE_LENGTH; \
  675. DC_QUIT; \
  676. } \
  677. }
  678. #define CHECK_WRITE_ONE_BYTE(pBuffer, pEnd, hr, trc ) \
  679. {\
  680. if (((BYTE*)(pBuffer)) >= (BYTE*)(pEnd)) { \
  681. TRC_ABORT( trc ); \
  682. hr = E_TSC_CORE_LENGTH; \
  683. DC_QUIT; \
  684. } \
  685. }
  686. #define CHECK_WRITE_ONE_BYTE_NO_HR(pBuffer, pEnd, trc ) \
  687. {\
  688. if (((BYTE*)(pBuffer)) >= (BYTE*)(pEnd)) { \
  689. TRC_ABORT( trc ); \
  690. DC_QUIT; \
  691. } \
  692. }
  693. #define CHECK_READ_N_BYTES(pBuffer, pEnd, N, hr, trc ) \
  694. {\
  695. if ((BYTE*)(pBuffer) > (BYTE*)(pEnd) || \
  696. ((ULONG)((BYTE*)(pEnd) - (BYTE*)(pBuffer)) < (ULONG)(N))) { \
  697. TRC_ABORT( trc ); \
  698. hr = E_TSC_CORE_LENGTH; \
  699. DC_QUIT; \
  700. } \
  701. }
  702. #define CHECK_READ_N_BYTES_NO_HR(pBuffer, pEnd, N, trc ) \
  703. {\
  704. if ((BYTE*)(pBuffer) > (BYTE*)(pEnd) || \
  705. ((ULONG)((BYTE*)(pEnd) - (BYTE*)(pBuffer)) < (ULONG)(N))) { \
  706. TRC_ABORT( trc ); \
  707. DC_QUIT; \
  708. } \
  709. }
  710. #define CHECK_READ_N_BYTES_2ENDED(pBuffer, pStart, pEnd, N, hr, trc ) \
  711. {\
  712. if ((BYTE*)(pBuffer) > (BYTE*)(pEnd) || \
  713. ((ULONG)((BYTE*)(pEnd) - (BYTE*)(pBuffer)) < (ULONG)(N)) || \
  714. ((BYTE*)(pBuffer) < (BYTE*)(pStart)) ) { \
  715. TRC_ABORT( trc ); \
  716. hr = E_TSC_CORE_LENGTH; \
  717. DC_QUIT; \
  718. } \
  719. }
  720. #define CHECK_READ_N_BYTES_2ENDED_NO_HR(pBuffer, pStart, pEnd, N, trc ) \
  721. {\
  722. if ((BYTE*)(pBuffer) > (BYTE*)(pEnd) || \
  723. ((ULONG)((BYTE*)(pEnd) - (BYTE*)(pBuffer)) < (ULONG)(N)) || \
  724. ((BYTE*)(pBuffer) < (BYTE*)(pStart)) ) { \
  725. TRC_ABORT( trc ); \
  726. DC_QUIT; \
  727. } \
  728. }
  729. #define CHECK_WRITE_N_BYTES(pBuffer, pEnd, N, hr, trc ) \
  730. {\
  731. if ((BYTE*)(pBuffer) > (BYTE*)(pEnd) || \
  732. ((ULONG)((BYTE*)(pEnd) - (BYTE*)(pBuffer)) < (ULONG)(N))) { \
  733. TRC_ABORT( trc ); \
  734. hr = E_TSC_CORE_LENGTH; \
  735. DC_QUIT; \
  736. } \
  737. }
  738. #define CHECK_WRITE_N_BYTES_NO_HR(pBuffer, pEnd, N, trc ) \
  739. {\
  740. if ((BYTE*)(pBuffer) > (BYTE*)(pEnd) || \
  741. ((ULONG)((BYTE*)(pEnd) - (BYTE*)(pBuffer)) < (ULONG)(N))) { \
  742. TRC_ABORT( trc ); \
  743. DC_QUIT; \
  744. } \
  745. }
  746. #define CHECK_WRITE_N_BYTES_2ENDED_NO_HR(pBuffer, pStart, pEnd, N, trc ) \
  747. {\
  748. if ((BYTE*)(pBuffer) > (BYTE*)(pEnd) || \
  749. ((ULONG)((BYTE*)(pEnd) - (BYTE*)(pBuffer)) < (ULONG)(N)) || \
  750. ((BYTE*)(pBuffer) < (BYTE*)(pStart)) ) { \
  751. TRC_ABORT( trc ); \
  752. DC_QUIT; \
  753. } \
  754. }
  755. #endif /* _H_UTIL */