winscard: Implement some functions of winscard.dll

Sergey Stepanov serg_admin at rambler.ru
Sun May 15 07:45:16 CDT 2011


---
 dlls/winscard/winscard.c |   41 +++++++++++++++++++++++++++++++++++------
 1 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/dlls/winscard/winscard.c b/dlls/winscard/winscard.c
index 412299c..5d1d7d3 100644
--- a/dlls/winscard/winscard.c
+++ b/dlls/winscard/winscard.c
@@ -17,10 +17,12 @@
  */
 
 #include "config.h"
+#include <dlfcn.h>
 #include <stdarg.h>
 #include "windef.h"
 #include "winbase.h"
 #include "wine/debug.h"
+#include "wine/library.h"
 #include "winscard.h"
 #include "winternl.h"
 
@@ -33,6 +35,23 @@ const SCARD_IO_REQUEST g_rgSCardT0Pci = { SCARD_PROTOCOL_T0, 8 };
 const SCARD_IO_REQUEST g_rgSCardT1Pci = { SCARD_PROTOCOL_T1, 8 };
 const SCARD_IO_REQUEST g_rgSCardRawPci = { SCARD_PROTOCOL_RAW, 8 };
 
+#define MAKE_FUNCPTR(f) static typeof(f) * p##f = NULL
+MAKE_FUNCPTR(SCardEstablishContext);
+MAKE_FUNCPTR(SCardReleaseContext);
+
+static void load_pcsclite(void)
+{
+    void *pcsc_handle = NULL;
+    pcsc_handle = wine_dlopen("libpcsclite.so", RTLD_LAZY | RTLD_GLOBAL, NULL, 0);
+    if (!pcsc_handle){
+	TRACE("Wine cannot find the pcsclite library\n");
+	return;
+    }
+#define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(pcsc_handle, #f, NULL, 0)) == NULL){WARN("Can't find symbol %s\n", #f);}
+    LOAD_FUNCPTR(SCardEstablishContext);
+    LOAD_FUNCPTR(SCardReleaseContext);
+#undef LOAD_FUNCPTR
+}
 
 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 {
@@ -44,6 +63,7 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
         {
             DisableThreadLibraryCalls(hinstDLL);
             WINSCARD_hModule = hinstDLL;
+            load_pcsclite();
             /* FIXME: for now, we act as if the pcsc daemon is always started */
             g_startedEvent = CreateEventA(NULL,TRUE,TRUE,NULL);
             break;
@@ -90,9 +110,15 @@ LONG WINAPI SCardAddReaderToGroupW(SCARDCONTEXT context, LPCWSTR reader, LPCWSTR
 LONG WINAPI SCardEstablishContext(DWORD dwScope, LPCVOID pvReserved1,
     LPCVOID pvReserved2, LPSCARDCONTEXT phContext)
 {
-    FIXME("(%x,%p,%p,%p) stub\n", dwScope, pvReserved1, pvReserved2, phContext);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return SCARD_F_INTERNAL_ERROR;
+    if (pSCardEstablishContext == NULL) {
+	TRACE("SCardEstablishContext not loaded\n");
+	SetLastError(ERROR_DLL_MIGHT_BE_INCOMPATIBLE);
+	return SCARD_F_INTERNAL_ERROR;
+    }
+    else {
+        return pSCardEstablishContext(dwScope, pvReserved1, pvReserved2, phContext);
+    }
+
 }
 
 LONG WINAPI SCardIsValidContext(SCARDCONTEXT context)
@@ -111,9 +137,12 @@ LONG WINAPI SCardListCardsA(SCARDCONTEXT hContext, LPCBYTE pbAtr, LPCGUID rgguid
 
 LONG WINAPI SCardReleaseContext(SCARDCONTEXT context)
 {
-    FIXME("(%lx) stub\n", context);
-    SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
-    return SCARD_F_INTERNAL_ERROR;
+    if (pSCardReleaseContext == NULL) {
+	TRACE("SCardReleaseContext not loaded\n");
+	SetLastError(ERROR_DLL_MIGHT_BE_INCOMPATIBLE);
+	return SCARD_F_INTERNAL_ERROR;
+    }
+    return pSCardReleaseContext(context);
 }
 
 void WINAPI SCardReleaseStartedEvent(void)
-- 
1.7.4.4




More information about the wine-patches mailing list