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.

111 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 1990-1998 Microsoft Corporation, All Rights Reserved
  3. Module Name:
  4. DEBUG.C
  5. ++*/
  6. #include <windows.h>
  7. #include "immdev.h"
  8. #include "fakeime.h"
  9. #ifdef DEBUG
  10. #ifdef FAKEIMEM
  11. const LPTSTR g_szRegInfoPath = TEXT("software\\microsoft\\fakeime\\m");
  12. #elif UNICODE
  13. const LPTSTR g_szRegInfoPath = TEXT("software\\microsoft\\fakeime\\u");
  14. #else
  15. const LPTSTR g_szRegInfoPath = TEXT("software\\microsoft\\fakeime\\a");
  16. #endif
  17. int DebugPrint(LPCTSTR lpszFormat, ...)
  18. {
  19. int nCount;
  20. TCHAR szMsg[1024];
  21. va_list marker;
  22. va_start(marker, lpszFormat);
  23. nCount = wvsprintf(szMsg, lpszFormat, marker);
  24. va_end(marker);
  25. OutputDebugString(szMsg);
  26. return nCount;
  27. }
  28. DWORD PASCAL GetDwordFromSetting(LPTSTR lpszFlag)
  29. {
  30. HKEY hkey;
  31. DWORD dwRegType, dwData, dwDataSize, dwRet;
  32. dwData = 0;
  33. dwDataSize=sizeof(DWORD);
  34. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, g_szRegInfoPath, 0, KEY_READ, &hkey)) {
  35. dwRet = RegQueryValueEx(hkey, lpszFlag, NULL, &dwRegType, (LPBYTE)&dwData, &dwDataSize);
  36. RegCloseKey(hkey);
  37. }
  38. MyDebugPrint((TEXT("Getting: %s=%#8.8x: dwRet=%#8.8x\n"), lpszFlag, dwData, dwRet));
  39. return dwData;
  40. }
  41. void SetDwordToSetting(LPCTSTR lpszFlag, DWORD dwFlag)
  42. {
  43. HKEY hkey;
  44. DWORD dwDataSize, dwRet;
  45. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, g_szRegInfoPath, 0, KEY_WRITE, &hkey)) {
  46. dwRet = RegSetValueEx(hkey, lpszFlag, 0, REG_DWORD, (CONST BYTE *) &dwFlag, sizeof(DWORD));
  47. RegCloseKey(hkey);
  48. }
  49. MyDebugPrint((TEXT("Setting: %s=%#8.8x: dwRet=%#8.8x\n"), lpszFlag, dwFlag, dwRet));
  50. }
  51. void PASCAL SetGlobalFlags()
  52. {
  53. dwLogFlag = GetDwordFromSetting(TEXT("LogFlag"));
  54. dwDebugFlag = GetDwordFromSetting(TEXT("DebugFlag"));
  55. }
  56. void PASCAL ImeLog(DWORD dwFlag, LPTSTR lpStr)
  57. {
  58. TCHAR szBuf[80];
  59. if (dwFlag & dwLogFlag)
  60. {
  61. if (dwDebugFlag & DEBF_THREADID)
  62. {
  63. DWORD dwThreadId = GetCurrentThreadId();
  64. wsprintf(szBuf, TEXT("ThreadID = %X "), dwThreadId);
  65. OutputDebugString(szBuf);
  66. }
  67. OutputDebugString(lpStr);
  68. OutputDebugString(TEXT("\r\n"));
  69. }
  70. }
  71. #ifdef FAKEIMEM
  72. void PASCAL MyOutputDebugStringW(LPWSTR lpw)
  73. {
  74. DWORD dwSize = (lstrlenW(lpw) + 1) * 2;
  75. LPSTR lpStr;
  76. int n;
  77. lpStr = GlobalAlloc(GPTR, dwSize);
  78. if (!lpStr)
  79. return;
  80. n = WideCharToMultiByte(CP_ACP, 0, lpw, lstrlenW(lpw), lpStr, dwSize, NULL, NULL);
  81. *(lpStr + n) = '\0';
  82. OutputDebugString(lpStr);
  83. GlobalFree((HANDLE)lpStr);
  84. }
  85. #endif
  86. #endif //DEBUG