wined3d: Pass a wined3d_device_context to wined3d_cs_emit_blt_sub_resource().
[wine/zf.git] / dlls / ctapi32 / ctapi32.c
blob10adacb65dcfdb70a252eba6d98e708d222f71cc
1 /*
2 * WINE ct-api wrapper
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
21 #include "config.h"
22 #include "wine/port.h"
23 #include <string.h>
24 #include "wine/debug.h"
25 #include "windef.h"
26 #include "winreg.h"
27 #include "winnls.h"
28 #include "ctapi.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(ctapi32);
32 #define FALLBACK_LIBCTAPI "libctapi.so"
33 static const WCHAR value_name[] = {'l','i','b','r','a','r','y',0};
36 static IS8 (*pCT_init)(IU16 ctn, IU16 pn) = NULL;
37 static IS8 (*pCT_data)(IU16 ctn, IU8 *dad, IU8 *sad, IU16 lenc, IU8 *command,
38 IU16 *lenr, IU8 *response) = NULL;
39 static IS8 (*pCT_close)(IU16 ctn) = NULL;
41 static void *ctapi_handle = NULL;
44 static BOOL load_functions(void) {
45 char soname[MAX_PATH] = FALLBACK_LIBCTAPI, buffer[MAX_PATH];
46 LONG result;
47 HKEY key_handle;
49 if (pCT_init) /* loaded already */
50 return TRUE;
52 /* Try to get name of low level library from registry */
53 /* @@ Wine registry key: HKCU\Software\Wine\ctapi32 */
54 result = RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Wine\\ctapi32", 0, KEY_READ, &key_handle);
55 if (result == ERROR_SUCCESS) {
56 DWORD type, size;
57 WCHAR buffer_w[MAX_PATH];
59 size = sizeof(buffer_w) - sizeof(WCHAR); /* Leave space for null termination */
60 result = RegQueryValueExW(key_handle, value_name, NULL, &type, (LPBYTE)buffer_w, &size);
61 if ((result == ERROR_SUCCESS) && (type == REG_SZ)) {
62 int len;
64 /* Null termination */
65 buffer_w[size / sizeof(WCHAR)] = '\0';
66 len = WideCharToMultiByte(CP_UNIXCP, 0, buffer_w, -1, buffer, sizeof(buffer), NULL, NULL);
67 if (len)
68 memcpy(soname, buffer, len);
70 RegCloseKey(key_handle);
73 TRACE("Loading library '%s'\n", soname);
74 ctapi_handle = dlopen(soname, RTLD_NOW);
75 if (ctapi_handle) {
76 TRACE("Successfully loaded '%s'\n", soname);
78 else {
79 MESSAGE("Wine cannot find any usable hardware library, ctapi32.dll not working.\n");
80 MESSAGE("Please create the key \"HKEY_CURRENT_USER\\Software\\Wine\\ctapi32\" in your registry\n");
81 MESSAGE("and set the value \"library\" to your library name (e.g. \"libctapi-cyberjack.so.1\" or \"/usr/lib/readers/libctapi.so\").\n");
82 return FALSE;
85 #define LOAD_FUNCPTR(f) if((p##f = dlsym(ctapi_handle, #f)) == NULL){WARN("Can't find symbol %s\n", #f); return FALSE;}
86 LOAD_FUNCPTR(CT_init);
87 LOAD_FUNCPTR(CT_data);
88 LOAD_FUNCPTR(CT_close);
89 #undef LOAD_FUNCPTR
91 return TRUE;
95 * ct-API specific functions
98 IS8 WINAPI WIN_CT_init(IU16 ctn, IU16 pn)
100 if (!pCT_init)
101 return ERR_HOST;
102 return pCT_init(ctn, pn);
105 IS8 WINAPI WIN_CT_data(IU16 ctn, IU8 *dad, IU8 *sad, IU16 lenc, IU8 *command, IU16 *lenr, IU8 *response)
107 if (!pCT_data)
108 return ERR_HOST;
109 return pCT_data(ctn, dad, sad, lenc, command, lenr, response);
112 IS8 WINAPI WIN_CT_close(IU16 ctn)
114 if (!pCT_close)
115 return ERR_HOST;
116 return pCT_close(ctn);
120 * Dll Main function
122 BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
124 TRACE("%p,%x,%p\n", hinstDLL, fdwReason, lpvReserved);
126 switch (fdwReason)
128 case DLL_PROCESS_ATTACH:
129 DisableThreadLibraryCalls(hinstDLL);
130 /* Try to load low-level library */
131 if (!load_functions())
132 return FALSE; /* error */
133 break;
134 case DLL_PROCESS_DETACH:
135 if (lpvReserved) break;
136 if (ctapi_handle) dlclose(ctapi_handle);
137 break;
140 return TRUE;