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.

217 lines
5.5 KiB

  1. /*
  2. *
  3. * ABImport.c - Code for calling WABIMP.dll to import
  4. * Netscape and Eudora files into WAB
  5. *
  6. * Assumes this will be compiled with wab32.lib, else need to
  7. * loadlibrary("wab32.dll") and call GetProcAddress("WABOpen");
  8. *
  9. * Exported functions:
  10. * HrImportNetscapeAB() - Imports Netscape AB into WAB
  11. * HrImportEudoraAB() - Imports Eudora AB into WAB
  12. *
  13. * Rough cut - vikramm 4/3/97
  14. *
  15. */
  16. #include "pch.hxx"
  17. #include <wab.h>
  18. #include <wabmig.h>
  19. #include "abimport.h"
  20. #include <impapi.h>
  21. #include <newimp.h>
  22. #include "import.h"
  23. #include "strconst.h"
  24. HRESULT HrImportAB(HWND hWndParent, LPTSTR lpszfnImport);
  25. static CImpProgress *g_pProgress = NULL;
  26. static TCHAR g_szABFmt[CCHMAX_STRINGRES];
  27. /*
  28. *
  29. * ProgressCallback
  30. *
  31. * This is the call back function that updates the progress bar
  32. *
  33. * In the function below, IDC_Progress is the ID of the progress
  34. * bar that will be updated and IDC_MEssage is the ID of the
  35. * static that will display text returned from the WABImp.Dll
  36. * Replace these 2 ids with your own ids...
  37. *
  38. */
  39. HRESULT ProgressCallback(HWND hwnd, LPWAB_PROGRESS lpProgress)
  40. {
  41. TCHAR sz[CCHMAX_STRINGRES];
  42. Assert(g_pProgress != NULL);
  43. if (lpProgress->denominator)
  44. {
  45. if (lpProgress->numerator == 0)
  46. {
  47. g_pProgress->Reset();
  48. g_pProgress->AdjustMax(lpProgress->denominator);
  49. }
  50. wnsprintf(sz, ARRAYSIZE(sz), g_szABFmt, lpProgress->numerator + 1, lpProgress->denominator);
  51. g_pProgress->SetMsg(sz, IDC_MESSAGE_STATIC);
  52. g_pProgress->HrUpdate(1);
  53. }
  54. return(S_OK);
  55. }
  56. // ===========================================================================
  57. // HrLoadLibraryWabDLL -
  58. // ===========================================================================
  59. HINSTANCE LoadLibraryWabDLL (VOID)
  60. {
  61. TCHAR szDll[MAX_PATH];
  62. TCHAR szExpand[MAX_PATH];
  63. LPTSTR psz;
  64. DWORD dwType = 0;
  65. HKEY hKey;
  66. ULONG cbData = sizeof(szDll);
  67. *szDll = '\0';
  68. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpszWABDLLRegPathKey, 0, KEY_READ, &hKey))
  69. {
  70. if (ERROR_SUCCESS == RegQueryValueEx( hKey, "", NULL, &dwType, (LPBYTE) szDll, &cbData))
  71. if (REG_EXPAND_SZ == dwType)
  72. {
  73. ExpandEnvironmentStrings(szDll, szExpand, ARRAYSIZE(szExpand));
  74. psz = szExpand;
  75. }
  76. else
  77. psz = szDll;
  78. RegCloseKey(hKey);
  79. }
  80. if(!lstrlen(psz))
  81. StrCpyN(psz, WAB_DLL_NAME, MAX_PATH);
  82. return(LoadLibrary(psz));
  83. }
  84. /*
  85. *
  86. *
  87. * HrImportAB
  88. *
  89. * Calls the relevant DLL proc and imports corresponding AB
  90. *
  91. */
  92. HRESULT HrImportAB(HWND hWndParent, LPTSTR lpszfnImport)
  93. {
  94. TCHAR sz[CCHMAX_STRINGRES];
  95. HINSTANCE hinstWabDll;
  96. LPWABOPEN lpfnWABOpen;
  97. LPWABOBJECT lpWABObject = NULL;
  98. LPADRBOOK lpAdrBookWAB = NULL;
  99. HRESULT hResult;
  100. BOOL fFinished = FALSE;
  101. LPWAB_IMPORT lpfnWABImport = NULL;
  102. HINSTANCE hinstImportDll = NULL;
  103. WAB_IMPORT_OPTIONS ImportOptions;
  104. ZeroMemory(&ImportOptions, sizeof(WAB_IMPORT_OPTIONS));
  105. hinstWabDll = LoadLibraryWabDLL();
  106. if (hinstWabDll == NULL)
  107. return(MAPI_E_NOT_INITIALIZED);
  108. lpfnWABOpen = (LPWABOPEN)GetProcAddress(hinstWabDll, szWabOpen);
  109. if (lpfnWABOpen == NULL)
  110. {
  111. hResult = MAPI_E_NOT_INITIALIZED;
  112. goto out;
  113. }
  114. hinstImportDll = LoadLibrary(szImportDll);
  115. if(!hinstImportDll)
  116. {
  117. hResult = MAPI_E_NOT_INITIALIZED;
  118. goto out;
  119. }
  120. if (! (lpfnWABImport = (LPWAB_IMPORT) GetProcAddress(hinstImportDll,lpszfnImport)))
  121. {
  122. hResult = MAPI_E_NOT_INITIALIZED;
  123. goto out;
  124. }
  125. // Flags that can be passed to the WABImp DLL
  126. //
  127. ImportOptions.fNoErrors = FALSE; // Display Pop up errors
  128. ImportOptions.ReplaceOption = WAB_REPLACE_PROMPT; //Prompt user before replacing contacts
  129. if(hResult = lpfnWABOpen(&lpAdrBookWAB, &lpWABObject, NULL, 0))
  130. goto out;
  131. g_pProgress = new CImpProgress;
  132. if (g_pProgress == NULL)
  133. {
  134. hResult = E_OUTOFMEMORY;
  135. goto out;
  136. }
  137. g_pProgress->Init(hWndParent, FALSE);
  138. LoadString(g_hInstImp, idsImportingABFmt, g_szABFmt, ARRAYSIZE(g_szABFmt));
  139. LoadString(g_hInstImp, idsImportABTitle, sz, ARRAYSIZE(sz));
  140. g_pProgress->SetTitle(sz);
  141. LoadString(g_hInstImp, idsImportAB, sz, ARRAYSIZE(sz));
  142. g_pProgress->SetMsg(sz, IDC_FOLDER_STATIC);
  143. g_pProgress->Show(0);
  144. hResult = lpfnWABImport(hWndParent,
  145. lpAdrBookWAB,
  146. lpWABObject,
  147. (LPWAB_PROGRESS_CALLBACK)&ProgressCallback,
  148. &ImportOptions);
  149. if (hResult == MAPI_E_USER_CANCEL)
  150. {
  151. hResult = hrUserCancel;
  152. }
  153. else if (FAILED(hResult))
  154. {
  155. ImpMessageBox( hWndParent,
  156. MAKEINTRESOURCE(idsImportTitle),
  157. MAKEINTRESOURCE(idsABImportError),
  158. NULL,
  159. MB_OK | MB_ICONEXCLAMATION );
  160. }
  161. out:
  162. if (g_pProgress != NULL)
  163. {
  164. g_pProgress->Release();
  165. g_pProgress = NULL;
  166. }
  167. if (lpAdrBookWAB)
  168. lpAdrBookWAB->Release();
  169. if (lpWABObject)
  170. lpWABObject->Release();
  171. if(hinstImportDll)
  172. FreeLibrary(hinstImportDll);
  173. FreeLibrary(hinstImportDll);
  174. return hResult;
  175. }