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.

142 lines
3.8 KiB

  1. /*
  2. * WAB stuff for S/Mime Test
  3. */
  4. #include <windows.h>
  5. #include <wab.h>
  6. #include "smimetst.h"
  7. #include "instring.h"
  8. #include "wabstuff.h"
  9. #include "dbgutil.h"
  10. LPWABOPEN lpfnWABOpen = NULL;
  11. const static TCHAR szWABOpen[] = TEXT("WABOpen");
  12. LPWABOBJECT lpWABObject = NULL;
  13. LPADRBOOK lpAdrBook = NULL;
  14. HINSTANCE hInstWABDll = NULL;
  15. //$$//////////////////////////////////////////////////////////////////////
  16. //
  17. // GetWABDllPath
  18. //
  19. //
  20. //////////////////////////////////////////////////////////////////////////
  21. void GetWABDllPath(LPTSTR szPath, ULONG cb)
  22. {
  23. DWORD dwType = 0;
  24. ULONG cbData;
  25. HKEY hKey = NULL;
  26. TCHAR szPathT[MAX_PATH + 1];
  27. if(szPath) {
  28. *szPath = '\0';
  29. // open the szWABDllPath key under
  30. if (ERROR_SUCCESS == RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  31. WAB_DLL_PATH_KEY,
  32. 0, //reserved
  33. KEY_READ,
  34. &hKey))
  35. {
  36. cbData = sizeof(szPathT);
  37. if (ERROR_SUCCESS == RegQueryValueEx( hKey,
  38. "",
  39. NULL,
  40. &dwType,
  41. (LPBYTE) szPathT,
  42. &cbData))
  43. {
  44. if (dwType == REG_EXPAND_SZ)
  45. cbData = ExpandEnvironmentStrings(szPathT, szPath, cb / sizeof(TCHAR));
  46. else
  47. {
  48. if(GetFileAttributes(szPathT) != 0xFFFFFFFF)
  49. lstrcpy(szPath, szPathT);
  50. }
  51. }
  52. }
  53. }
  54. if(hKey)
  55. RegCloseKey(hKey);
  56. }
  57. /***************************************************************************
  58. Name : WABFreePadrlist
  59. Purpose : Free an adrlist and it's property arrays
  60. Parameters: lpBuffer = buffer to free
  61. Returns : SCODE
  62. Comment :
  63. ***************************************************************************/
  64. void WABFreePadrlist(LPADRLIST lpAdrList) {
  65. ULONG iEntry;
  66. if (lpAdrList) {
  67. for (iEntry = 0; iEntry < lpAdrList->cEntries; ++iEntry) {
  68. if (lpAdrList->aEntries[iEntry].rgPropVals) {
  69. WABFreeBuffer(lpAdrList->aEntries[iEntry].rgPropVals);
  70. }
  71. }
  72. WABFreeBuffer(lpAdrList);
  73. }
  74. }
  75. //$$//////////////////////////////////////////////////////////////////////
  76. //
  77. // LoadLibrary_WABDll()
  78. //
  79. // Since we are moving the WAB directory out of Windows\SYstem, we cant be
  80. // sure it will be on the path. Hence we need to make sure that WABOpen will
  81. // work - by loading the wab32.dll upfront
  82. //
  83. ///////////////////////////////////////////////////////////////////////////
  84. HINSTANCE LoadLibrary_WABDll(void)
  85. {
  86. IF_WIN32(LPTSTR lpszWABDll = TEXT("Wab32.dll");)
  87. TCHAR szWABDllPath[MAX_PATH + 1];
  88. HINSTANCE hinst = NULL;
  89. GetWABDllPath(szWABDllPath, sizeof(szWABDllPath));
  90. hinst = LoadLibrary((lstrlen(szWABDllPath)) ? szWABDllPath : lpszWABDll);
  91. return hinst;
  92. }
  93. void LoadWAB(void) {
  94. LPWABOPEN lpfnWABOpen = NULL;
  95. if (! hInstWABDll) {
  96. hInstWABDll = LoadLibrary_WABDll();
  97. if (hInstWABDll)
  98. lpfnWABOpen = (LPWABOPEN) GetProcAddress(hInstWABDll, szWABOpen);
  99. if (lpfnWABOpen)
  100. lpfnWABOpen(&lpAdrBook, &lpWABObject, NULL, 0);
  101. }
  102. }
  103. void UnloadWAB(void) {
  104. if (lpAdrBook) {
  105. lpAdrBook->Release();
  106. lpAdrBook = NULL;
  107. lpWABObject->Release();
  108. lpWABObject = NULL;
  109. }
  110. if (hInstWABDll) {
  111. FreeLibrary(hInstWABDll);
  112. hInstWABDll = NULL;
  113. }
  114. }