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.

165 lines
4.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: scardssp.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // scardssp.cpp : Implementation of DLL Exports.
  11. // Note: Proxy/Stub Information
  12. // To merge the proxy/stub code into the object DLL, add the file
  13. // dlldatax.c to the project. Make sure precompiled headers
  14. // are turned off for this file, and add _MERGE_PROXYSTUB to the
  15. // defines for the project.
  16. //
  17. // If you are not running WinNT4.0 or Win95 with DCOM, then you
  18. // need to remove the following define from dlldatax.c
  19. // #define _WIN32_WINNT 0x0400
  20. //
  21. // Further, if you are running MIDL without /Oicf switch, you also
  22. // need to remove the following define from dlldatax.c.
  23. // #define USE_STUBLESS_PROXY
  24. //
  25. // Modify the custom build rule for scardssp.idl by adding the following
  26. // files to the Outputs.
  27. // scardssp_p.c
  28. // dlldata.c
  29. // To build a separate proxy/stub DLL,
  30. // run nmake -f scardsspps.mk in the project directory.
  31. #include "stdafx.h"
  32. #include "resource.h"
  33. #include <initguid.h>
  34. #include <sspguid.h>
  35. #include "dlldatax.h"
  36. #include "ByteBuffer.h"
  37. #include "TypeConv.h"
  38. #include "SCardCmd.h"
  39. #include "ISO7816.h"
  40. #include "SCard.h"
  41. #include "Database.h"
  42. #include "Locate.h"
  43. #ifdef _MERGE_PROXYSTUB
  44. extern "C" HINSTANCE hProxyDll;
  45. #endif
  46. CComModule _Module;
  47. BEGIN_OBJECT_MAP(ObjectMap)
  48. OBJECT_ENTRY(CLSID_CByteBuffer, CByteBuffer)
  49. OBJECT_ENTRY(CLSID_CSCardTypeConv, CSCardTypeConv)
  50. OBJECT_ENTRY(CLSID_CSCardCmd, CSCardCmd)
  51. OBJECT_ENTRY(CLSID_CSCardISO7816, CSCardISO7816)
  52. OBJECT_ENTRY(CLSID_CSCard, CSCard)
  53. OBJECT_ENTRY(CLSID_CSCardDatabase, CSCardDatabase)
  54. OBJECT_ENTRY(CLSID_CSCardLocate, CSCardLocate)
  55. END_OBJECT_MAP()
  56. /////////////////////////////////////////////////////////////////////////////
  57. // DLL Entry Point
  58. extern "C"
  59. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  60. {
  61. lpReserved;
  62. #ifdef _MERGE_PROXYSTUB
  63. if (!PrxDllMain(hInstance, dwReason, lpReserved))
  64. return FALSE;
  65. #endif
  66. if (dwReason == DLL_PROCESS_ATTACH)
  67. {
  68. _Module.Init(ObjectMap, hInstance/* , &LIBID_SCARDSSPLib */);
  69. DisableThreadLibraryCalls(hInstance);
  70. }
  71. else if (dwReason == DLL_PROCESS_DETACH)
  72. _Module.Term();
  73. return TRUE; // ok
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. // Used to determine whether the DLL can be unloaded by OLE
  77. STDAPI DllCanUnloadNow(void)
  78. {
  79. #ifdef _MERGE_PROXYSTUB
  80. if (PrxDllCanUnloadNow() != S_OK)
  81. return S_FALSE;
  82. #endif
  83. return (_Module.GetLockCount()==0) ? S_OK : S_FALSE;
  84. }
  85. /////////////////////////////////////////////////////////////////////////////
  86. // Returns a class factory to create an object of the requested type
  87. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  88. {
  89. #ifdef _MERGE_PROXYSTUB
  90. if (PrxDllGetClassObject(rclsid, riid, ppv) == S_OK)
  91. return S_OK;
  92. #endif
  93. return _Module.GetClassObject(rclsid, riid, ppv);
  94. }
  95. /////////////////////////////////////////////////////////////////////////////
  96. // DllRegisterServer - Adds entries to the system registry
  97. STDAPI DllRegisterServer(void)
  98. {
  99. #ifdef _MERGE_PROXYSTUB
  100. HRESULT hRes = PrxDllRegisterServer();
  101. if (FAILED(hRes))
  102. return hRes;
  103. #endif
  104. // registers object, typelib and all interfaces in typelib
  105. return _Module.RegisterServer(TRUE);
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. // DllUnregisterServer - Removes entries from the system registry
  109. STDAPI DllUnregisterServer(void)
  110. {
  111. #ifdef _MERGE_PROXYSTUB
  112. PrxDllUnregisterServer();
  113. #endif
  114. return _Module.UnregisterServer(/* TRUE */);
  115. }
  116. /////////////////////////////////////////////////////////////////////////////
  117. // Quick Generation of our own objects.
  118. LPUNKNOWN
  119. NewObject(
  120. REFCLSID rclsid,
  121. REFIID riid)
  122. {
  123. HRESULT hr;
  124. IClassFactory *pCF = NULL;
  125. LPUNKNOWN pUnk = NULL;
  126. try
  127. {
  128. hr = DllGetClassObject(rclsid, IID_IClassFactory, (LPVOID *)&pCF);
  129. if (FAILED(hr))
  130. throw hr;
  131. hr = pCF->CreateInstance(NULL, riid, (LPVOID *)&pUnk);
  132. if (FAILED(hr))
  133. throw hr;
  134. pCF->Release();
  135. }
  136. catch (...)
  137. {
  138. if (NULL != pCF)
  139. pCF->Release();
  140. throw;
  141. }
  142. return pUnk;
  143. }