diff --git a/doc/examples/pcsc-demo.cpp b/doc/examples/pcsc-demo.cpp index e37c33c..845dee6 100644 --- a/doc/examples/pcsc-demo.cpp +++ b/doc/examples/pcsc-demo.cpp @@ -1,6 +1,6 @@ //g++ -I ../svn -I /usr/include/PCSC test.cpp -lpcsclite -ggdb3 #include "pcscpp/pcsc.hxx" -#include "pcscpp/cardos.hxx" +//#include "pcscpp/cardos.hxx" #include int main(int, char const*const*const argv) try { diff --git a/src/pcsc.hxx b/src/pcsc.hxx index e21743b..b8e3037 100644 --- a/src/pcsc.hxx +++ b/src/pcsc.hxx @@ -10,8 +10,10 @@ #ifndef PCSC_HXX #define PCSC_HXX +#include + #ifdef WIN32 - #include "WinSCard.h" + #include #ifndef MAX_ATR_SIZE #define MAX_ATR_SIZE 33 #endif @@ -41,7 +43,6 @@ namespace pcsc { #endif #include -#include #include #include #include @@ -69,8 +70,8 @@ namespace pcsc { std::string hex(const std::string& data) { std::stringstream res; for (std::string::const_iterator it(data.begin()); it!=data.end(); ++it) - res<<"(0x"<dwProtocol; + rPci.cbPciLength = sizeof(rPci); + check(SCardTransmit(_id, &rPci, (unsigned char*)in.c_str(), in.size(), - &rPci, buff, &len), + 0, buff, &len), "smartcard transmit message "+hex(in)); return std::string((char*)buff, len); } @@ -232,8 +235,8 @@ namespace pcsc { // 11 - Error // So everything with Sev=00 is successful // theoretically even with Sev=01, but that's still rejected - return (_state>>30&3)==0; - //RETURN _STATE==SCARD_S_SUCCESS; + //return (_state>>30&3)==0; + return _state==SCARD_S_SUCCESS; } //...........................................................variables @@ -282,11 +285,12 @@ namespace pcsc { friend class Connection; //! Establishes a connection to the given named cardreader - Reader(const std::string& nm, Connection& c): + Reader(const std::string& nm, Connection& c, + DWORD mode=SCARD_SHARE_SHARED, + DWORD protocol=SCARD_PROTOCOL_T1): name(nm), _connection(c) { check(SCardConnect(_connection._id, strconv(name).c_str(), - SCARD_SHARE_SHARED, - SCARD_PROTOCOL_T0|SCARD_PROTOCOL_T1, + mode, protocol, &_id, &_protocol), "connect smartcard \""+name+"\""); } @@ -347,7 +351,7 @@ namespace pcsc { - @c true: class throws exceptions in case of an error - @c false: no exceptions, check your instance after each operation */ - Connection(Scope s=SYSTEM, bool exceptions=true): + Connection(Scope s=USER, bool exceptions=true): _exc(exceptions), _id(0), _state(SCardEstablishContext(s, 0, 0, &_id)) { check("establish smartcard context"); @@ -395,8 +399,8 @@ namespace pcsc { //! @c false if last operation was not successful operator bool() const { - return (_state>>30&3)==0; - //return _state==SCARD_S_SUCCESS; + //return (_state>>30&3)==0; + return _state==SCARD_S_SUCCESS; } //! Get the describing text of the last error