// Context Functions /// <summary> /// Establish a resource manager context for the query. /// </summary> /// <param name="nScope"></param> /// <returns></returns> /// <remarks> /// The context used by the resource manager when accessing the smart /// card database. The resource manager context is primarily used by the /// query and management functions when accessing the database. The scope /// of the resource manager context can be the current user or the system. /// </remarks> public bool EstablishContext(SCardContextScope nScope) { uint nErrCode; if (this.m_fDisposed) { throw new ObjectDisposedException(base.GetType().FullName); } if (this.m_hContext != IntPtr.Zero) { // Just release it so can get new one. nErrCode = WinSCard.SCardReleaseContext(this.m_hContext); } // Establish the resource manager context on the card. nErrCode = WinSCard.SCardEstablishContext((uint)nScope, IntPtr.Zero, IntPtr.Zero, out this.m_hContext); // If Service not running if (nErrCode == 0x8010001d) { //MessageBox.Show("The ensure that SCardSvr Service is running. PC/SC routines won't be available."); // Sometimes this is ok, like installing the omnikey ethernet driver the first time, besides, this is // a rude practice and the text is gibberish. return(false); } // else there is some other problem if (nErrCode != 0) { //MessageBox.Show(string.Format("SCardEstablishContext failed: 0x{0:X8}", nErrCode)); //SCardException.RaiseWin32ResponseCode(nErrCode); } return(true); }
private static extern uint SCardEstablishContext(SCardContextScope dwScope, IntPtr pvReserved1, IntPtr pvReserved2, out IntPtr phContext);