2007-11-02 13:46:18 +01:00
|
|
|
/*
|
|
|
|
* WINE ct-api wrapper
|
|
|
|
*
|
|
|
|
* Copyright 2007 Christian Eggers
|
|
|
|
*
|
|
|
|
* 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 St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2021-10-29 09:37:35 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2007-11-13 09:32:20 +01:00
|
|
|
#include "windef.h"
|
2021-10-29 09:37:35 +02:00
|
|
|
#include "winbase.h"
|
2007-11-13 09:32:20 +01:00
|
|
|
#include "winreg.h"
|
|
|
|
#include "winnls.h"
|
2021-10-29 09:37:35 +02:00
|
|
|
#include "unixlib.h"
|
|
|
|
#include "wine/debug.h"
|
2007-11-02 13:46:18 +01:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ctapi32);
|
|
|
|
|
|
|
|
#define FALLBACK_LIBCTAPI "libctapi.so"
|
|
|
|
|
2021-10-29 09:37:35 +02:00
|
|
|
static unixlib_handle_t ctapi_handle;
|
2007-11-02 13:46:18 +01:00
|
|
|
|
2021-10-29 09:37:35 +02:00
|
|
|
#define CTAPI_CALL( func, params ) __wine_unix_call( ctapi_handle, unix_ ## func, params )
|
2007-11-02 13:46:18 +01:00
|
|
|
|
|
|
|
|
2013-11-06 21:21:06 +01:00
|
|
|
static BOOL load_functions(void) {
|
2021-10-29 09:37:35 +02:00
|
|
|
char soname[MAX_PATH] = FALLBACK_LIBCTAPI;
|
2007-11-02 13:46:18 +01:00
|
|
|
LONG result;
|
|
|
|
HKEY key_handle;
|
|
|
|
|
|
|
|
/* Try to get name of low level library from registry */
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\ctapi32 */
|
2021-10-29 09:37:35 +02:00
|
|
|
result = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Wine\\ctapi32", 0, KEY_READ, &key_handle);
|
2007-11-02 13:46:18 +01:00
|
|
|
if (result == ERROR_SUCCESS) {
|
|
|
|
DWORD type, size;
|
|
|
|
WCHAR buffer_w[MAX_PATH];
|
|
|
|
|
|
|
|
size = sizeof(buffer_w) - sizeof(WCHAR); /* Leave space for null termination */
|
2021-10-29 09:37:35 +02:00
|
|
|
result = RegQueryValueExW(key_handle, L"library", NULL, &type, (LPBYTE)buffer_w, &size);
|
2007-11-02 13:46:18 +01:00
|
|
|
if ((result == ERROR_SUCCESS) && (type == REG_SZ)) {
|
|
|
|
/* Null termination */
|
|
|
|
buffer_w[size / sizeof(WCHAR)] = '\0';
|
2021-10-29 09:37:35 +02:00
|
|
|
WideCharToMultiByte(CP_UNIXCP, 0, buffer_w, -1, soname, sizeof(soname), NULL, NULL);
|
2007-11-02 13:46:18 +01:00
|
|
|
}
|
|
|
|
RegCloseKey(key_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Loading library '%s'\n", soname);
|
2021-11-08 20:53:51 +01:00
|
|
|
if (!CTAPI_CALL( attach, soname )) return TRUE;
|
2007-11-02 13:46:18 +01:00
|
|
|
|
2021-10-29 09:37:35 +02:00
|
|
|
MESSAGE("Wine cannot find any usable hardware library, ctapi32.dll not working.\n");
|
|
|
|
MESSAGE("Please create the key \"HKEY_CURRENT_USER\\Software\\Wine\\ctapi32\" in your registry\n");
|
|
|
|
MESSAGE("and set the value \"library\" to your library name (e.g. \"libctapi-cyberjack.so.1\" or \"/usr/lib/readers/libctapi.so\").\n");
|
|
|
|
return FALSE;
|
2007-11-02 13:46:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ct-API specific functions
|
|
|
|
*/
|
|
|
|
|
2021-10-29 09:37:35 +02:00
|
|
|
IS8 WINAPI CT_init(IU16 ctn, IU16 pn)
|
2007-11-02 13:46:18 +01:00
|
|
|
{
|
2021-10-29 09:37:35 +02:00
|
|
|
struct ct_init_params params = { ctn, pn };
|
|
|
|
|
|
|
|
return CTAPI_CALL( ct_init, ¶ms );
|
2007-11-02 13:46:18 +01:00
|
|
|
}
|
|
|
|
|
2021-10-29 09:37:35 +02:00
|
|
|
IS8 WINAPI CT_data(IU16 ctn, IU8 *dad, IU8 *sad, IU16 lenc, IU8 *command, IU16 *lenr, IU8 *response)
|
2007-11-02 13:46:18 +01:00
|
|
|
{
|
2021-10-29 09:37:35 +02:00
|
|
|
struct ct_data_params params = { ctn, dad, sad, lenc, command, lenr, response };
|
|
|
|
|
|
|
|
return CTAPI_CALL( ct_data, ¶ms );
|
2007-11-02 13:46:18 +01:00
|
|
|
}
|
|
|
|
|
2021-10-29 09:37:35 +02:00
|
|
|
IS8 WINAPI CT_close(IU16 ctn)
|
2007-11-02 13:46:18 +01:00
|
|
|
{
|
2021-10-29 09:37:35 +02:00
|
|
|
struct ct_close_params params = { ctn };
|
|
|
|
|
|
|
|
return CTAPI_CALL( ct_close, ¶ms );
|
2007-11-02 13:46:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dll Main function
|
|
|
|
*/
|
|
|
|
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
|
|
|
{
|
|
|
|
TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
|
|
|
|
|
|
|
|
switch (fdwReason)
|
|
|
|
{
|
|
|
|
case DLL_PROCESS_ATTACH:
|
|
|
|
DisableThreadLibraryCalls(hinstDLL);
|
2021-10-29 09:37:35 +02:00
|
|
|
if (NtQueryVirtualMemory( GetCurrentProcess(), hinstDLL, MemoryWineUnixFuncs,
|
|
|
|
&ctapi_handle, sizeof(ctapi_handle), NULL ))
|
|
|
|
return FALSE;
|
2013-11-06 21:21:06 +01:00
|
|
|
if (!load_functions())
|
2021-10-29 09:37:35 +02:00
|
|
|
return FALSE;
|
2007-11-02 13:46:18 +01:00
|
|
|
break;
|
|
|
|
case DLL_PROCESS_DETACH:
|
2013-04-30 17:25:29 +02:00
|
|
|
if (lpvReserved) break;
|
2021-10-29 09:37:35 +02:00
|
|
|
CTAPI_CALL( detach, NULL );
|
2007-11-02 13:46:18 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|