ctapi32: Added wrapper dll for ctapi (CardTerminal API).
diff --git a/Makefile.in b/Makefile.in
index 71c51eb..8f5e507 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -190,6 +190,7 @@
 	dlls/cryptdll/Makefile \
 	dlls/cryptnet/Makefile \
 	dlls/cryptnet/tests/Makefile \
+	dlls/ctapi32/Makefile \
 	dlls/ctl3d32/Makefile \
 	dlls/d3d10/Makefile \
 	dlls/d3d8/Makefile \
@@ -567,6 +568,7 @@
 dlls/cryptdll/Makefile: dlls/cryptdll/Makefile.in dlls/Makedll.rules
 dlls/cryptnet/Makefile: dlls/cryptnet/Makefile.in dlls/Makedll.rules
 dlls/cryptnet/tests/Makefile: dlls/cryptnet/tests/Makefile.in dlls/Maketest.rules
+dlls/ctapi32/Makefile: dlls/ctapi32/Makefile.in dlls/Makedll.rules
 dlls/ctl3d32/Makefile: dlls/ctl3d32/Makefile.in dlls/Makedll.rules
 dlls/d3d10/Makefile: dlls/d3d10/Makefile.in dlls/Makedll.rules
 dlls/d3d8/Makefile: dlls/d3d8/Makefile.in dlls/Makedll.rules
diff --git a/configure b/configure
index e2d6bac..3f56379 100755
--- a/configure
+++ b/configure
@@ -20578,6 +20578,8 @@
 
 ac_config_files="$ac_config_files dlls/cryptnet/tests/Makefile"
 
+ac_config_files="$ac_config_files dlls/ctapi32/Makefile"
+
 ac_config_files="$ac_config_files dlls/ctl3d32/Makefile"
 
 ac_config_files="$ac_config_files dlls/d3d10/Makefile"
@@ -21836,6 +21838,7 @@
     "dlls/cryptdll/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/cryptdll/Makefile" ;;
     "dlls/cryptnet/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/cryptnet/Makefile" ;;
     "dlls/cryptnet/tests/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/cryptnet/tests/Makefile" ;;
+    "dlls/ctapi32/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/ctapi32/Makefile" ;;
     "dlls/ctl3d32/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/ctl3d32/Makefile" ;;
     "dlls/d3d10/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/d3d10/Makefile" ;;
     "dlls/d3d8/Makefile") CONFIG_FILES="$CONFIG_FILES dlls/d3d8/Makefile" ;;
diff --git a/configure.ac b/configure.ac
index a84a434..305cf13 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1606,6 +1606,7 @@
 AC_CONFIG_FILES([dlls/cryptdll/Makefile])
 AC_CONFIG_FILES([dlls/cryptnet/Makefile])
 AC_CONFIG_FILES([dlls/cryptnet/tests/Makefile])
+AC_CONFIG_FILES([dlls/ctapi32/Makefile])
 AC_CONFIG_FILES([dlls/ctl3d32/Makefile])
 AC_CONFIG_FILES([dlls/d3d10/Makefile])
 AC_CONFIG_FILES([dlls/d3d8/Makefile])
diff --git a/dlls/Makefile.in b/dlls/Makefile.in
index c79037e..f9f36eb 100644
--- a/dlls/Makefile.in
+++ b/dlls/Makefile.in
@@ -39,6 +39,7 @@
 	crypt32 \
 	cryptdll \
 	cryptnet \
+	ctapi32 \
 	ctl3d32 \
 	d3d10 \
 	d3d8 \
diff --git a/dlls/ctapi32/Makefile.in b/dlls/ctapi32/Makefile.in
new file mode 100644
index 0000000..a22f27b
--- /dev/null
+++ b/dlls/ctapi32/Makefile.in
@@ -0,0 +1,12 @@
+TOPSRCDIR = @top_srcdir@
+TOPOBJDIR = ../..
+SRCDIR    = @srcdir@
+VPATH     = @srcdir@
+MODULE    = ctapi32.dll
+IMPORTS   = advapi32 kernel32
+
+C_SRCS = ctapi32.c
+
+@MAKE_DLL_RULES@
+
+@DEPENDENCIES@  # everything below this line is overwritten by make depend
diff --git a/dlls/ctapi32/ctapi.h b/dlls/ctapi32/ctapi.h
new file mode 100644
index 0000000..89edb47
--- /dev/null
+++ b/dlls/ctapi32/ctapi.h
@@ -0,0 +1,107 @@
+/*
+ * CT-API library for the REINER SCT cyberJack pinpad/e-com USB.
+ * Copyright (C) 2001  REINER SCT
+ * Author: Matthias Bruestle
+ * Support: support@reiner-sct.com
+ *
+ * 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
+ */
+#ifndef H_CTAPI
+#define H_CTAPI
+
+/* More uniqe defines */
+
+#define CT_API_AD_HOST		2
+#define CT_API_AD_REMOTE	5
+
+#define CT_API_AD_CT		1
+#define CT_API_AD_ICC1		0
+#define CT_API_AD_ICC2		2
+#define CT_API_AD_ICC3		3
+#define CT_API_AD_ICC4		4
+#define CT_API_AD_ICC5		5
+#define CT_API_AD_ICC6		6
+#define CT_API_AD_ICC7		7
+#define CT_API_AD_ICC8		8
+#define CT_API_AD_ICC9		9
+#define CT_API_AD_ICC10		10
+#define CT_API_AD_ICC11		11
+#define CT_API_AD_ICC12		12
+#define CT_API_AD_ICC13		13
+#define CT_API_AD_ICC14		14
+
+#define CT_API_RV_OK		0
+#define CT_API_RV_ERR_INVALID	-1
+#define CT_API_RV_ERR_CT	-8
+#define CT_API_RV_ERR_TRANS	-10
+#define CT_API_RV_ERR_MEMORY	-11
+#define CT_API_RV_ERR_HOST	-127
+#define CT_API_RV_ERR_HTSI	-128
+
+/* MUSCLE style defines */
+
+#define OK			 0	/* Success */
+#define ERR_INVALID		-1	/* Invalid Data */
+#define ERR_CT			-8	/* CT Error */
+#define ERR_TRANS		-10	/* Transmission Error */
+#define ERR_MEMORY		-11	/* Memory Allocate Error */
+#define ERR_HOST		-127	/* Host Error */
+#define ERR_HTSI		-128	/* HTSI Error */
+
+#define PORT_COM1		0	/* COM 1 */
+#define PORT_COM2		1	/* COM 2 */
+#define PORT_COM3		2	/* COM 3 */
+#define PORT_COM4		3	/* COM 4 */
+#define PORT_Printer		4	/* Printer Port (MAC) */
+#define PORT_Modem		5	/* Modem Port (MAC)   */
+#define PORT_LPT1		6	/* LPT 1 */
+#define PORT_LPT2		7	/* LPT 2 */
+
+#define CT			1
+#define HOST			2
+
+/* Short */
+#define CJ_CTAPI_MAX_LENC	4+1+255+1
+#define CJ_CTAPI_MAX_LENR	256+2
+/* Extended */
+/* #define CJ_CTAPI_MAX_LENC	5+2+65535+2 */
+/* #define CJ_CTAPI_MAX_LENR	65536+2 */
+/* Maximum for CTAPI */
+/* #define CJ_CTAPI_MAX_LENC	65535 */
+/* #define CJ_CTAPI_MAX_LENR	65535 */
+
+
+typedef unsigned char IU8;
+typedef unsigned short IU16;
+
+typedef signed char IS8;
+typedef signed short IS16;
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+IS8 CT_init( IU16 ctn, IU16 pn );
+IS8 CT_data( IU16 ctn, IU8 *dad, IU8 *sad, IU16 lenc, IU8 *command, IU16 *lenr,
+	IU8 *response );
+IS8 CT_close( IU16 ctn );
+
+/* Proprietary extension */
+IS8 CT_keycb( IU16 ctn, void (* cb)(IU16 ctn, IU8 status) );
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+#endif /* H_CTAPI */
diff --git a/dlls/ctapi32/ctapi32.c b/dlls/ctapi32/ctapi32.c
new file mode 100644
index 0000000..39fea9c
--- /dev/null
+++ b/dlls/ctapi32/ctapi32.c
@@ -0,0 +1,155 @@
+/*
+ * 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 <config.h>
+#include <wine/port.h>
+#include <string.h>
+#include <wine/library.h>
+#include <wine/debug.h>
+#include <windef.h>
+#include <winreg.h>
+#include <winnls.h>
+#include "ctapi.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(ctapi32);
+
+#define FALLBACK_LIBCTAPI "libctapi.so"
+static const WCHAR value_name[] = {'l','i','b','r','a','r','y',0};
+
+
+static IS8 (*pCT_init)(IU16 ctn, IU16 pn) = NULL;
+static IS8 (*pCT_data)(IU16 ctn, IU8 *dad, IU8 *sad, IU16 lenc, IU8 *command,
+	IU16 *lenr, IU8 *response) = NULL;
+static IS8 (*pCT_close)(IU16 ctn) = NULL;
+
+static void *ctapi_handle = NULL;
+
+
+static int load_functions(void) {
+	char soname[MAX_PATH] = FALLBACK_LIBCTAPI, buffer[MAX_PATH];
+	LONG result;
+	HKEY key_handle;
+
+	if (pCT_init) /* loaded already */
+		return 0;
+
+	/* Try to get name of low level library from registry */
+        /* @@ Wine registry key: HKCU\Software\Wine\ctapi32 */
+	result = RegOpenKeyExA(HKEY_CURRENT_USER, "Software\\Wine\\ctapi32", 0, KEY_READ, &key_handle);
+	if (result == ERROR_SUCCESS) {
+		DWORD type, size;
+		WCHAR buffer_w[MAX_PATH];
+
+		size = sizeof(buffer_w) - sizeof(WCHAR);  /* Leave space for null termination */
+		result = RegQueryValueExW(key_handle, value_name, NULL, &type, (LPBYTE)buffer_w, &size);
+		if ((result == ERROR_SUCCESS) && (type == REG_SZ)) {
+			int len;
+
+			/* Null termination */
+			buffer_w[size / sizeof(WCHAR)] = '\0';
+			len = WideCharToMultiByte(CP_UNIXCP, 0, buffer_w, -1, buffer, sizeof(buffer), NULL, NULL);
+			if (len)
+				memcpy(soname, buffer, len - 1);
+		}
+		RegCloseKey(key_handle);
+	}
+
+	TRACE("Loading library '%s'\n", soname);
+	ctapi_handle = wine_dlopen(soname, RTLD_NOW, NULL, 0);
+	if (ctapi_handle) {
+		TRACE("Successfully loaded '%s'\n", soname);
+	}
+	else {
+		MESSAGE("Wine cannot find any useable 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 1;
+	}
+
+#define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(ctapi_handle, #f, NULL, 0)) == NULL){WARN("Can't find symbol %s\n", #f); return 1;}
+LOAD_FUNCPTR(CT_init);
+LOAD_FUNCPTR(CT_data);
+LOAD_FUNCPTR(CT_close);
+#undef LOAD_FUNCPTR
+
+	return 0;
+}
+
+static void unload_functions(void)
+{
+	pCT_close = NULL;
+	pCT_data = NULL;
+	pCT_init = NULL;
+	if (ctapi_handle)
+		wine_dlclose(ctapi_handle, NULL, 0);
+}
+
+
+/*
+ *  ct-API specific functions
+ */
+
+IS8 WINAPI WIN_CT_init(IU16 ctn, IU16 pn)
+{
+	if (!pCT_init)
+		return ERR_HOST;
+	return pCT_init(ctn, pn);
+}
+
+IS8 WINAPI WIN_CT_data(IU16 ctn, IU8 *dad, IU8 *sad, IU16 lenc, IU8 *command, IU16 *lenr, IU8 *response)
+{
+	if (!pCT_data)
+		return ERR_HOST;
+	return pCT_data(ctn, dad, sad, lenc, command, lenr, response);
+}
+
+IS8 WINAPI WIN_CT_close(IU16 ctn)
+{
+	if (!pCT_close)
+		return ERR_HOST;
+	return pCT_close(ctn);
+}
+
+/*
+ *  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);
+            /* Try to load low-level library */
+            if (load_functions() != 0)
+		return FALSE;  /* error */
+            break;
+        }
+        case DLL_PROCESS_DETACH:
+        {
+            unload_functions();
+            break;
+        }
+    }
+
+    return TRUE;
+}
diff --git a/dlls/ctapi32/ctapi32.spec b/dlls/ctapi32/ctapi32.spec
new file mode 100644
index 0000000..a874e7c
--- /dev/null
+++ b/dlls/ctapi32/ctapi32.spec
@@ -0,0 +1,3 @@
+@ stdcall CT_close (long) WIN_CT_close
+@ stdcall CT_data (long  ptr ptr long ptr ptr ptr) WIN_CT_data
+@ stdcall CT_init (long long) WIN_CT_init