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.

194 lines
3.5 KiB

  1. #include "faxmapip.h"
  2. #pragma hdrstop
  3. typedef struct _STRING_TABLE {
  4. DWORD ResourceId;
  5. DWORD InternalId;
  6. LPTSTR String;
  7. } STRING_TABLE, *PSTRING_TABLE;
  8. static STRING_TABLE StringTable[] =
  9. {
  10. { IDS_NO_MAPI_LOGON, IDS_NO_MAPI_LOGON, NULL },
  11. { IDS_DEFAULT, IDS_DEFAULT, NULL }
  12. };
  13. #define CountStringTable (sizeof(StringTable)/sizeof(STRING_TABLE))
  14. LPTSTR
  15. GetLastErrorText(
  16. DWORD ErrorCode
  17. )
  18. /*++
  19. Routine Description:
  20. Gets a string for a given WIN32 error code.
  21. Arguments:
  22. ErrorCode - WIN32 error code.
  23. Return Value:
  24. Pointer to a string representing the ErrorCode.
  25. --*/
  26. {
  27. static TCHAR ErrorBuf[256];
  28. DWORD Count;
  29. Count = FormatMessage(
  30. FORMAT_MESSAGE_FROM_SYSTEM |FORMAT_MESSAGE_ARGUMENT_ARRAY,
  31. NULL,
  32. ErrorCode,
  33. LANG_NEUTRAL,
  34. ErrorBuf,
  35. sizeof(ErrorBuf),
  36. NULL
  37. );
  38. if (Count) {
  39. if (ErrorBuf[Count-1] == TEXT('\n')) {
  40. ErrorBuf[Count-1] = 0;
  41. }
  42. if ((Count>1) && (ErrorBuf[Count-2] == TEXT('\r'))) {
  43. ErrorBuf[Count-2] = 0;
  44. }
  45. }
  46. return ErrorBuf;
  47. }
  48. VOID
  49. InitializeStringTable(
  50. VOID
  51. )
  52. {
  53. DWORD i;
  54. TCHAR Buffer[256];
  55. for (i=0; i<CountStringTable; i++) {
  56. if (LoadString(
  57. MyhInstance,
  58. StringTable[i].ResourceId,
  59. Buffer,
  60. sizeof(Buffer)/sizeof(TCHAR)
  61. )) {
  62. StringTable[i].String = (LPTSTR) MemAlloc( StringSize( Buffer ) );
  63. if (!StringTable[i].String) {
  64. StringTable[i].String = TEXT("");
  65. } else {
  66. _tcscpy( StringTable[i].String, Buffer );
  67. }
  68. } else {
  69. StringTable[i].String = TEXT("");
  70. }
  71. }
  72. }
  73. LPTSTR
  74. GetString(
  75. DWORD InternalId
  76. )
  77. /*++
  78. Routine Description:
  79. Loads a resource string and returns a pointer to the string.
  80. The caller must free the memory.
  81. Arguments:
  82. ResourceId - resource string id
  83. Return Value:
  84. pointer to the string
  85. --*/
  86. {
  87. DWORD i;
  88. for (i=0; i<CountStringTable; i++) {
  89. if (StringTable[i].InternalId == InternalId) {
  90. return StringTable[i].String;
  91. }
  92. }
  93. return NULL;
  94. }
  95. BOOL
  96. MyInitializeMapi(
  97. )
  98. {
  99. HKEY hKey = NULL;
  100. LPTSTR szNoMailClient = NULL;
  101. LPTSTR szPreFirstRun = NULL;
  102. BOOL bRslt = FALSE;
  103. hKey = OpenRegistryKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Clients\\Mail"), FALSE, KEY_ALL_ACCESS);
  104. if (hKey != NULL) {
  105. szNoMailClient = GetRegistryString(hKey, TEXT("NoMailClient"), TEXT(""));
  106. if (_tcscmp(szNoMailClient, TEXT("")) == 0) {
  107. MemFree(szNoMailClient);
  108. szNoMailClient = NULL;
  109. }
  110. else {
  111. RegDeleteValue(hKey, TEXT("NoMailClient"));
  112. }
  113. szPreFirstRun = GetRegistryString(hKey, TEXT("PreFirstRun"), TEXT(""));
  114. if (_tcscmp(szPreFirstRun, TEXT("")) == 0) {
  115. MemFree(szPreFirstRun);
  116. szPreFirstRun = NULL;
  117. }
  118. else {
  119. RegDeleteValue(hKey, TEXT("PreFirstRun"));
  120. }
  121. }
  122. bRslt = InitializeMapi();
  123. if (szNoMailClient != NULL) {
  124. SetRegistryString(hKey, TEXT("NoMailClient"), szNoMailClient);
  125. MemFree(szNoMailClient);
  126. }
  127. if (szPreFirstRun != NULL) {
  128. SetRegistryString(hKey, TEXT("PreFirstRun"), szPreFirstRun);
  129. MemFree(szPreFirstRun);
  130. }
  131. if (hKey != NULL) {
  132. RegCloseKey(hKey);
  133. }
  134. return bRslt;
  135. }