4 * Copyright 2007 Christian Eggers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(ctapi32
);
33 #define FALLBACK_LIBCTAPI "libctapi.so"
35 static unixlib_handle_t ctapi_handle
;
37 #define CTAPI_CALL( func, params ) __wine_unix_call( ctapi_handle, unix_ ## func, params )
40 static BOOL
load_functions(void) {
41 char soname
[MAX_PATH
] = FALLBACK_LIBCTAPI
;
45 /* Try to get name of low level library from registry */
46 /* @@ Wine registry key: HKCU\Software\Wine\ctapi32 */
47 result
= RegOpenKeyExW(HKEY_CURRENT_USER
, L
"Software\\Wine\\ctapi32", 0, KEY_READ
, &key_handle
);
48 if (result
== ERROR_SUCCESS
) {
50 WCHAR buffer_w
[MAX_PATH
];
52 size
= sizeof(buffer_w
) - sizeof(WCHAR
); /* Leave space for null termination */
53 result
= RegQueryValueExW(key_handle
, L
"library", NULL
, &type
, (LPBYTE
)buffer_w
, &size
);
54 if ((result
== ERROR_SUCCESS
) && (type
== REG_SZ
)) {
55 /* Null termination */
56 buffer_w
[size
/ sizeof(WCHAR
)] = '\0';
57 WideCharToMultiByte(CP_UNIXCP
, 0, buffer_w
, -1, soname
, sizeof(soname
), NULL
, NULL
);
59 RegCloseKey(key_handle
);
62 TRACE("Loading library '%s'\n", soname
);
63 if (!CTAPI_CALL( attach
, soname
)) return TRUE
;
65 MESSAGE("Wine cannot find any usable hardware library, ctapi32.dll not working.\n");
66 MESSAGE("Please create the key \"HKEY_CURRENT_USER\\Software\\Wine\\ctapi32\" in your registry\n");
67 MESSAGE("and set the value \"library\" to your library name (e.g. \"libctapi-cyberjack.so.1\" or \"/usr/lib/readers/libctapi.so\").\n");
72 * ct-API specific functions
75 IS8 WINAPI
CT_init(IU16 ctn
, IU16 pn
)
77 struct ct_init_params params
= { ctn
, pn
};
79 return CTAPI_CALL( ct_init
, ¶ms
);
82 IS8 WINAPI
CT_data(IU16 ctn
, IU8
*dad
, IU8
*sad
, IU16 lenc
, IU8
*command
, IU16
*lenr
, IU8
*response
)
84 struct ct_data_params params
= { ctn
, dad
, sad
, lenc
, command
, lenr
, response
};
86 return CTAPI_CALL( ct_data
, ¶ms
);
89 IS8 WINAPI
CT_close(IU16 ctn
)
91 struct ct_close_params params
= { ctn
};
93 return CTAPI_CALL( ct_close
, ¶ms
);
99 BOOL WINAPI
DllMain (HINSTANCE hinstDLL
, DWORD fdwReason
, LPVOID lpvReserved
)
101 TRACE("%p,%lx,%p\n", hinstDLL
, fdwReason
, lpvReserved
);
105 case DLL_PROCESS_ATTACH
:
106 DisableThreadLibraryCalls(hinstDLL
);
107 if (NtQueryVirtualMemory( GetCurrentProcess(), hinstDLL
, MemoryWineUnixFuncs
,
108 &ctapi_handle
, sizeof(ctapi_handle
), NULL
))
110 if (!load_functions())
113 case DLL_PROCESS_DETACH
:
114 if (lpvReserved
) break;
115 CTAPI_CALL( detach
, NULL
);