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.

141 lines
3.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: SCard.h
  8. //
  9. //--------------------------------------------------------------------------
  10. // SCard.h : Declaration of the CSCard
  11. #ifndef __SCARD_H_
  12. #define __SCARD_H_
  13. #include "resource.h" // main symbols
  14. #include <winscard.h>
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CSCard
  17. class ATL_NO_VTABLE CSCard :
  18. public CComObjectRootEx<CComMultiThreadModel>,
  19. public CComCoClass<CSCard, &CLSID_CSCard>,
  20. public IDispatchImpl<ISCard, &IID_ISCard, &LIBID_SCARDSSPLib>
  21. {
  22. public:
  23. CSCard()
  24. {
  25. m_pUnkMarshaler = NULL;
  26. m_hContext = NULL;
  27. m_hMyContext = NULL;
  28. m_hCard = NULL;
  29. m_hMyCard = NULL;
  30. m_dwProtocol = 0;
  31. }
  32. DECLARE_REGISTRY_RESOURCEID(IDR_SCARD)
  33. DECLARE_GET_CONTROLLING_UNKNOWN()
  34. DECLARE_PROTECT_FINAL_CONSTRUCT()
  35. BEGIN_COM_MAP(CSCard)
  36. COM_INTERFACE_ENTRY(ISCard)
  37. COM_INTERFACE_ENTRY(IDispatch)
  38. COM_INTERFACE_ENTRY_AGGREGATE(IID_IMarshal, m_pUnkMarshaler.p)
  39. END_COM_MAP()
  40. HRESULT FinalConstruct()
  41. {
  42. return CoCreateFreeThreadedMarshaler(
  43. GetControllingUnknown(), &m_pUnkMarshaler.p);
  44. }
  45. void FinalRelease()
  46. {
  47. if (NULL != m_hMyCard)
  48. SCardDisconnect(m_hMyCard, SCARD_RESET_CARD);
  49. if (NULL != m_hMyContext)
  50. SCardReleaseContext(m_hMyContext);
  51. m_pUnkMarshaler.Release();
  52. }
  53. CComPtr<IUnknown> m_pUnkMarshaler;
  54. protected:
  55. SCARDCONTEXT m_hContext;
  56. SCARDCONTEXT m_hMyContext;
  57. SCARDHANDLE m_hCard;
  58. SCARDHANDLE m_hMyCard;
  59. DWORD m_dwProtocol;
  60. SCARDCONTEXT Context(void)
  61. {
  62. LONG lSts;
  63. if (NULL == m_hContext)
  64. {
  65. ASSERT(NULL == m_hMyContext);
  66. lSts = SCardEstablishContext(
  67. SCARD_SCOPE_USER,
  68. NULL,
  69. NULL,
  70. &m_hMyContext);
  71. if (SCARD_S_SUCCESS != lSts)
  72. throw (HRESULT)HRESULT_FROM_WIN32(lSts);
  73. m_hContext = m_hMyContext;
  74. }
  75. return m_hContext;
  76. }
  77. // ISCard
  78. public:
  79. STDMETHOD(get_Atr)(
  80. /* [retval][out] */ LPBYTEBUFFER __RPC_FAR *ppAtr);
  81. STDMETHOD(get_CardHandle)(
  82. /* [retval][out] */ HSCARD __RPC_FAR *pHandle);
  83. STDMETHOD(get_Context)(
  84. /* [retval][out] */ HSCARDCONTEXT __RPC_FAR *pContext);
  85. STDMETHOD(get_Protocol)(
  86. /* [retval][out] */ SCARD_PROTOCOLS __RPC_FAR *pProtocol);
  87. STDMETHOD(get_Status)(
  88. /* [retval][out] */ SCARD_STATES __RPC_FAR *pStatus);
  89. STDMETHOD(AttachByHandle)(
  90. /* [in] */ HSCARD hCard);
  91. STDMETHOD(AttachByReader)(
  92. /* [in] */ BSTR bstrReaderName,
  93. /* [defaultvalue][in] */ SCARD_SHARE_MODES ShareMode = EXCLUSIVE,
  94. /* [defaultvalue][in] */ SCARD_PROTOCOLS PrefProtocol = T0);
  95. STDMETHOD(Detach)(
  96. /* [defaultvalue][in] */ SCARD_DISPOSITIONS Disposition = LEAVE);
  97. STDMETHOD(LockSCard)(
  98. void);
  99. STDMETHOD(ReAttach)(
  100. /* [defaultvalue][in] */ SCARD_SHARE_MODES ShareMode = EXCLUSIVE,
  101. /* [defaultvalue][in] */ SCARD_DISPOSITIONS InitState = LEAVE);
  102. STDMETHOD(Transaction)(
  103. /* [out][in] */ LPSCARDCMD __RPC_FAR *ppCmd);
  104. STDMETHOD(UnlockSCard)(
  105. /* [defaultvalue][in] */ SCARD_DISPOSITIONS Disposition = LEAVE);
  106. };
  107. inline CSCard *
  108. NewSCard(
  109. void)
  110. {
  111. return (CSCard *)NewObject(CLSID_CSCard, IID_ISCard);
  112. }
  113. #endif //__SCARD_H_