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.

117 lines
3.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: xenroll.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #if _MSC_VER < 1200
  11. #pragma comment(linker,"/merge:.CRT=.data")
  12. #endif
  13. // xenroll.cpp : Implementation of DLL Exports.
  14. // Note: Proxy/Stub Information
  15. // To build a separate proxy/stub DLL,
  16. // run nmake -f xenrollps.mk in the project directory.
  17. #include "stdafx.h"
  18. #include "resource.h"
  19. #include "initguid.h"
  20. #include "xenroll.h"
  21. #include "CEnroll.h"
  22. #include <pvk.h>
  23. extern BOOL MSAsnInit(HMODULE hInst);
  24. extern void MSAsnTerm();
  25. extern BOOL AsnInit(HMODULE hInst);
  26. extern void AsnTerm();
  27. extern BOOL WINAPI I_CryptOIDInfoDllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved);
  28. CComModule _Module;
  29. HINSTANCE hInstanceXEnroll = NULL;
  30. BEGIN_OBJECT_MAP(ObjectMap)
  31. OBJECT_ENTRY(CLSID_CEnroll2, CCEnroll)
  32. END_OBJECT_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // DLL Entry Point
  35. extern BOOL WINAPI UnicodeDllMain(HMODULE hInstDLL, DWORD fdwReason, LPVOID lpvReserved);
  36. extern "C"
  37. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  38. {
  39. if (dwReason == DLL_PROCESS_ATTACH)
  40. {
  41. _Module.Init(ObjectMap, hInstance);
  42. DisableThreadLibraryCalls(hInstance);
  43. if (!MSAsnInit(hInstance))
  44. AsnInit(hInstance);
  45. hInstanceXEnroll = hInstance;
  46. }
  47. else if (dwReason == DLL_PROCESS_DETACH)
  48. {
  49. MSAsnTerm();
  50. AsnTerm();
  51. _Module.Term();
  52. }
  53. return(
  54. I_CryptOIDInfoDllMain(hInstance, dwReason, lpReserved) &&
  55. PvkDllMain(hInstance, dwReason, lpReserved) &&
  56. UnicodeDllMain(hInstance, dwReason, lpReserved) &&
  57. InitIE302UpdThunks(hInstance, dwReason, lpReserved)); // ok
  58. }
  59. /////////////////////////////////////////////////////////////////////////////
  60. // Used to determine whether the DLL can be unloaded by OLE
  61. STDAPI DllCanUnloadNow(void)
  62. {
  63. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  64. }
  65. /////////////////////////////////////////////////////////////////////////////
  66. // Returns a class factory to create an object of the requested type
  67. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  68. {
  69. return _Module.GetClassObject(rclsid, riid, ppv);
  70. }
  71. /////////////////////////////////////////////////////////////////////////////
  72. // DllRegisterServer - Adds entries to the system registry
  73. STDAPI DllRegisterServer(void)
  74. {
  75. HRESULT hRes;
  76. // registers object, typelib and all interfaces in typelib
  77. hRes = _Module.RegisterServer(TRUE);
  78. if (SUCCEEDED(hRes)) {
  79. // set up emulation for the old xenroll interface (allows legacy callers to call us)
  80. hRes = CoTreatAsClass(CLSID_CEnroll, CLSID_CEnroll2);
  81. }
  82. return hRes;
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // DllUnregisterServer - Removes entries from the system registry
  86. STDAPI DllUnregisterServer(void)
  87. {
  88. HRESULT hr = S_OK;
  89. CoTreatAsClass(CLSID_CEnroll, CLSID_NULL); // remove emulation
  90. _Module.UnregisterServer();
  91. return hr;
  92. }