Implement some function of winscard.dll (dynamic translate from libpcsclite.so ver.1.7.2) SCardConnect SCardDisconnect SCardEstablishContext SCardGetStatusChange SCardListReaders SCardReleaseContext SCardTransmit

Charles Davis cdavis at mymail.mines.edu
Mon Apr 25 18:47:28 CDT 2011


On 4/25/11 11:36 AM, serg_admin at rambler.ru wrote:
> +LONG (*_SCardConnect)(SCARDCONTEXT,LPSTR,DWORD,DWORD,LPSCARDHANDLE,LPDWORD);
> +LONG (*_SCardDisconnect)(SCARDHANDLE, DWORD);
> +LONG (*_SCardEstablishContext)(DWORD,LPCVOID,LPCVOID,LPSCARDCONTEXT);
> +LONG (*_SCardGetStatusChange)(SCARDCONTEXT,DWORD,LPSCARD_READERSTATEA,DWORD);
> +LONG (*_SCardListReaders)(SCARDHANDLE, LPCSTR,LPSTR,LPDWORD);
> +LONG (*_SCardReleaseContext)(SCARDCONTEXT);
> +LONG (*_SCardTransmit)(SCARDHANDLE,LPCSCARD_IO_REQUEST,LPCBYTE,DWORD,LPSCARD_IO_REQUEST,LPBYTE,LPDWORD);
You should split this patch up, one patch per function. Also, a common
convention in Wine is to prefix function pointer globals with 'p'
instead of an underscore.
>  
>  BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
>  {
> @@ -46,11 +55,61 @@ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
>              WINSCARD_hModule = hinstDLL;
>              /* FIXME: for now, we act as if the pcsc daemon is always started */
>              g_startedEvent = CreateEventA(NULL,TRUE,TRUE,NULL);
> +            /* check exist libpcsclite.so */
> +            h_libpcsc = dlopen("libpcsclite.so",RTLD_LAZY);
You must detect the existence of this library in configure.ac, with
WINE_CHECK_SONAME. Then, you use the special macro SONAME_LIBPCSCLITE
that WINE_CHECK_SONAME defines for you if the library is present.

Also, wine has its own wrapper around dlopen(3), wine_dlopen(), that you
should use instead of straight dlopen(3).
> +            if (h_libpcsc == 0)  {
> +              FIXME("Can't load library libpcsclite.so: %s\n", dlerror());
wine_dlopen() has parameters for a bounded buffer to receive the error
string. You should use that instead of calling dlerror(3).
> +              SetLastError(ERROR_DLL_MIGHT_BE_INCOMPATIBLE);
> +            }
> +            else  {
> +        	_SCardConnect = dlsym(h_libpcsc,"SCardConnect");
Use wine_dlsym() instead.
> +        	if (!(_SCardConnect))  {
> +        	  FIXME("Can't find method SCardConnec: %s\n", dlerror());
> +                  SetLastError(ERROR_DLL_MIGHT_BE_INCOMPATIBLE);
> +        	}
> +		_SCardDisconnect = dlsym(h_libpcsc,"SCardDisconnect");
> +        	if (!(_SCardDisconnect))  {
> +        	  FIXME("Can't find method SCardDisconnect: %s\n", dlerror());
> +                  SetLastError(ERROR_DLL_MIGHT_BE_INCOMPATIBLE);
> +        	}
> +        	_SCardEstablishContext = dlsym(h_libpcsc,"SCardEstablishContext");
> +        	if (!(_SCardEstablishContext))  {
> +        	  FIXME("Can't find method SCardEstablishContext: %s\n", dlerror());
> +                  SetLastError(ERROR_DLL_MIGHT_BE_INCOMPATIBLE);
> +        	}
> +        	_SCardGetStatusChange = dlsym(h_libpcsc,"SCardGetStatusChange");
> +        	if (!(_SCardGetStatusChange))  {
> +        	  FIXME("Can't find method SCardGetStatusChange: %s\n", dlerror());
> +                  SetLastError(ERROR_DLL_MIGHT_BE_INCOMPATIBLE);
> +        	}
> +        	_SCardListReaders = dlsym(h_libpcsc,"SCardListReaders");
> +        	if (!(_SCardListReaders))  {
> +        	  FIXME("Can't find method SCardListReaders: %s\n", dlerror());
> +                  SetLastError(ERROR_DLL_MIGHT_BE_INCOMPATIBLE);
> +        	}
> +        	_SCardReleaseContext = dlsym(h_libpcsc,"SCardReleaseContext");
> +        	if (!(_SCardReleaseContext))  {
> +        	  FIXME("Can't find method SCardReleaseContext: %s\n", dlerror());
> +                  SetLastError(ERROR_DLL_MIGHT_BE_INCOMPATIBLE);
> +        	}
> +        	_SCardTransmit = dlsym(h_libpcsc,"SCardTransmit");
> +        	if (!(_SCardReleaseContext))  {
> +        	  FIXME("Can't find method SCardTransmit: %s\n", dlerror());
> +                  SetLastError(ERROR_DLL_MIGHT_BE_INCOMPATIBLE);
> +        	}
You could avoid a lot of redundancy here by using a macro (most parts of
Wine that load dynamic function pointers use a macro to do so).
> +            }
>              break;
>          }
>          case DLL_PROCESS_DETACH:
>          {
>              CloseHandle(g_startedEvent);
> +            if (h_libpcsc != 0)
> +            {
> +              if (dlclose(h_libpcsc))
Use wine_dlclose() instead.

Chip



More information about the wine-patches mailing list