[Pcsclite-cvs-commit] r6407 - /trunk/contrib/libPCSCv2part10/sample.c

rousseau at users.alioth.debian.org rousseau at users.alioth.debian.org
Wed Aug 8 08:34:37 UTC 2012


Author: rousseau
Date: Wed Aug  8 08:34:36 2012
New Revision: 6407

URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=6407
Log:
Make the sample code a real and working example

Modified:
    trunk/contrib/libPCSCv2part10/sample.c   (contents, props changed)

Modified: trunk/contrib/libPCSCv2part10/sample.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/contrib/libPCSCv2part10/sample.c?rev=6407&op=diff
==============================================================================
--- trunk/contrib/libPCSCv2part10/sample.c (original)
+++ trunk/contrib/libPCSCv2part10/sample.c Wed Aug  8 08:34:36 2012
@@ -1,3 +1,26 @@
+/*
+    sample.c: example of use of libPCSCv2part10 helper functions
+    Copyright (C) 2012   Ludovic Rousseau
+
+    This library is free software; you can redistribute it and/or
+    modify it under the terms of the GNU Lesser General Public
+    License as published by the Free Software Foundation; either
+    version 2.1 of the License, or (at your option) any later version.
+
+    This library is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+    Lesser General Public License for more details.
+
+    You should have received a copy of the GNU Lesser General Public
+    License along with this library; if not, write to the Free Software
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+/*
+ * $Id$
+ */
+
 #include <stdio.h>
 
 #ifdef __APPLE__
@@ -11,15 +34,52 @@
 
 #include "PCSCv2part10.h"
 
+/* PCSC error */
+#define PCSC_ERROR_EXIT(rv) \
+if (rv != SCARD_S_SUCCESS) \
+{ \
+	printf("Failed at line %d with %s (0x%lX)\n", __LINE__, pcsc_stringify_error(rv), rv); \
+	goto end; \
+}
+
 int main(void)
 {
-	SCARDHANDLE hCard = 0;
-	int value, ret;
+	LONG rv;
+	SCARDCONTEXT hContext;
+	SCARDHANDLE hCard;
+	int value, ret = -1;
+	DWORD dwReaders, dwPref;
+	char *mszReaders;
 
-	ret = PCSCv2Part10_find_TLV_property_by_tag_from_hcard(hCard, PCSCv2_PART10_PROPERTY_wIdVendor, &value);
+	rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
+	PCSC_ERROR_EXIT(rv)
 
-	printf("This sample does nothing.\n");
-	printf("It is just used to check compilation and link\n");
+	dwReaders = SCARD_AUTOALLOCATE;
+	rv = SCardListReaders(hContext, NULL, (LPSTR)&mszReaders, &dwReaders);
+	PCSC_ERROR_EXIT(rv)
 
+	/* use first reader */
+	printf("Using reaer: %s\n", mszReaders);
+
+	rv = SCardConnect(hContext, mszReaders,
+		SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
+		&hCard, &dwPref);
+
+	ret = PCSCv2Part10_find_TLV_property_by_tag_from_hcard(hCard,
+		PCSCv2_PART10_PROPERTY_wIdVendor, &value);
+
+	printf("ret: %d\n", ret);
+	printf("value for PCSCv2_PART10_PROPERTY_wIdVendor: 0x%04X\n", value),
+
+	rv = SCardDisconnect(hCard, SCARD_LEAVE_CARD);
+	PCSC_ERROR_EXIT(rv)
+
+	rv = SCardFreeMemory(hContext, mszReaders);
+	PCSC_ERROR_EXIT(rv)
+
+	rv = SCardReleaseContext(hContext);
+	PCSC_ERROR_EXIT(rv)
+
+end:
 	return ret;
 }

Propchange: trunk/contrib/libPCSCv2part10/sample.c
------------------------------------------------------------------------------
    svn:keywords = Id




More information about the Pcsclite-cvs-commit mailing list