diff --git a/plugins/wintab/src/main/native/WinTabUtils.c b/plugins/wintab/src/main/native/WinTabUtils.c new file mode 100644 index 0000000..3c9d709 --- /dev/null +++ b/plugins/wintab/src/main/native/WinTabUtils.c @@ -0,0 +1,167 @@ +/*---------------------------------------------------------------------------- + + NAME + Utils.c + + PURPOSE + Some general-purpose functions for the WinTab demos. + + COPYRIGHT + Copyright (c) Wacom Company, Ltd. 2014 All Rights Reserved + All rights reserved. + + The text and information contained in this file may be freely used, + copied, or distributed without compensation or licensing restrictions. + +---------------------------------------------------------------------------- */ + +#include "WinTabUtils.h" + +#ifdef WACOM_DEBUG + +void WacomTrace( char *lpszFormat, ...); + +#define WACOM_ASSERT( x ) assert( x ) +#define WACOM_TRACE(...) WacomTrace(__VA_ARGS__) +#else +#define WACOM_TRACE(...) +#define WACOM_ASSERT( x ) + +#endif // WACOM_DEBUG + +////////////////////////////////////////////////////////////////////////////// +HINSTANCE ghWintab = NULL; + +WTINFOA gpWTInfoA = NULL; +WTOPENA gpWTOpenA = NULL; +WTGETA gpWTGetA = NULL; +WTSETA gpWTSetA = NULL; +WTCLOSE gpWTClose = NULL; +WTPACKET gpWTPacket = NULL; +WTENABLE gpWTEnable = NULL; +WTOVERLAP gpWTOverlap = NULL; +WTSAVE gpWTSave = NULL; +WTCONFIG gpWTConfig = NULL; +WTRESTORE gpWTRestore = NULL; +WTEXTSET gpWTExtSet = NULL; +WTEXTGET gpWTExtGet = NULL; +WTQUEUESIZESET gpWTQueueSizeSet = NULL; +WTDATAPEEK gpWTDataPeek = NULL; +WTPACKETSGET gpWTPacketsGet = NULL; + +// TODO - add more wintab32 function pointers as needed + +#define GETPROCADDRESS(type, func) \ + gp##func = (type)GetProcAddress(ghWintab, #func); \ + if (!gp##func){ WACOM_ASSERT(FALSE); UnloadWintab(); return FALSE; } + +////////////////////////////////////////////////////////////////////////////// +// Purpose +// Find wintab32.dll and load it. +// Find the exported functions we need from it. +// +// Returns +// TRUE on success. +// FALSE on failure. +// +BOOL LoadWintab( void ) +{ + ghWintab = LoadLibraryA( "Wintab32.dll" ); + if ( !ghWintab ) + { + DWORD err = GetLastError(); + WACOM_TRACE("LoadLibrary error: %i\n", err); + return FALSE; + } + + // Explicitly find the exported Wintab functions in which we are interested. + // We are using the ASCII, not unicode versions (where applicable). + GETPROCADDRESS( WTOPENA, WTOpenA ); + GETPROCADDRESS( WTINFOA, WTInfoA ); + GETPROCADDRESS( WTGETA, WTGetA ); + GETPROCADDRESS( WTSETA, WTSetA ); + GETPROCADDRESS( WTPACKET, WTPacket ); + GETPROCADDRESS( WTCLOSE, WTClose ); + GETPROCADDRESS( WTENABLE, WTEnable ); + GETPROCADDRESS( WTOVERLAP, WTOverlap ); + GETPROCADDRESS( WTSAVE, WTSave ); + GETPROCADDRESS( WTCONFIG, WTConfig ); + GETPROCADDRESS( WTRESTORE, WTRestore ); + GETPROCADDRESS( WTEXTSET, WTExtSet ); + GETPROCADDRESS( WTEXTGET, WTExtGet ); + GETPROCADDRESS( WTQUEUESIZESET, WTQueueSizeSet ); + GETPROCADDRESS( WTDATAPEEK, WTDataPeek ); + GETPROCADDRESS( WTPACKETSGET, WTPacketsGet ); + + + // TODO - don't forget to NULL out pointers in UnloadWintab(). + return TRUE; +} + + + +////////////////////////////////////////////////////////////////////////////// +// Purpose +// Uninitializes use of wintab32.dll +// +// Returns +// Nothing. +// +void UnloadWintab( void ) +{ + WACOM_TRACE( "UnloadWintab()\n" ); + + if ( ghWintab ) + { + FreeLibrary( ghWintab ); + ghWintab = NULL; + } + + gpWTOpenA = NULL; + gpWTClose = NULL; + gpWTInfoA = NULL; + gpWTPacket = NULL; + gpWTEnable = NULL; + gpWTOverlap = NULL; + gpWTSave = NULL; + gpWTConfig = NULL; + gpWTGetA = NULL; + gpWTSetA = NULL; + gpWTRestore = NULL; + gpWTExtSet = NULL; + gpWTExtGet = NULL; + gpWTQueueSizeSet = NULL; + gpWTDataPeek = NULL; + gpWTPacketsGet = NULL; +} + + + +#ifdef WACOM_DEBUG + +////////////////////////////////////////////////////////////////////////////// + +void WacomTrace( char *lpszFormat, ...) +{ + char szTraceMessage[ 128 ]; + + int nBytesWritten; + + va_list args; + + WACOM_ASSERT( lpszFormat ); + + va_start( args, lpszFormat ); + + nBytesWritten = _vsnprintf( szTraceMessage, sizeof( szTraceMessage ) - 1, + lpszFormat, args ); + + if ( nBytesWritten > 0 ) + { + OutputDebugStringA( szTraceMessage ); + } + + va_end( args ); +} + +#endif // WACOM_DEBUG diff --git a/plugins/wintab/src/main/native/WinTabUtils.h b/plugins/wintab/src/main/native/WinTabUtils.h new file mode 100644 index 0000000..89b31a3 --- /dev/null +++ b/plugins/wintab/src/main/native/WinTabUtils.h @@ -0,0 +1,92 @@ +/*---------------------------------------------------------------------------- + + NAME + Utils.h + + PURPOSE + Defines for the general-purpose functions for the WinTab demos. + + COPYRIGHT + Copyright (c) Wacom Company, Ltd. 2014 All Rights Reserved + All rights reserved. + + The text and information contained in this file may be freely used, + copied, or distributed without compensation or licensing restrictions. + +---------------------------------------------------------------------------- */ +#pragma once + +#include +#include +#include +#include + +#include "wintab.h" // NOTE: get from wactab header package + + +////////////////////////////////////////////////////////////////////////////// +#define WACOM_DEBUG + +// Ignore warnings about using unsafe string functions. +#pragma warning( disable : 4996 ) + +////////////////////////////////////////////////////////////////////////////// +// Function pointers to Wintab functions exported from wintab32.dll. +typedef UINT ( API * WTINFOA ) ( UINT, UINT, LPVOID ); +typedef HCTX ( API * WTOPENA )( HWND, LPLOGCONTEXTA, BOOL ); +typedef BOOL ( API * WTGETA ) ( HCTX, LPLOGCONTEXT ); +typedef BOOL ( API * WTSETA ) ( HCTX, LPLOGCONTEXT ); +typedef BOOL ( API * WTCLOSE ) ( HCTX ); +typedef BOOL ( API * WTENABLE ) ( HCTX, BOOL ); +typedef BOOL ( API * WTPACKET ) ( HCTX, UINT, LPVOID ); +typedef BOOL ( API * WTOVERLAP ) ( HCTX, BOOL ); +typedef BOOL ( API * WTSAVE ) ( HCTX, LPVOID ); +typedef BOOL ( API * WTCONFIG ) ( HCTX, HWND ); +typedef HCTX ( API * WTRESTORE ) ( HWND, LPVOID, BOOL ); +typedef BOOL ( API * WTEXTSET ) ( HCTX, UINT, LPVOID ); +typedef BOOL ( API * WTEXTGET ) ( HCTX, UINT, LPVOID ); +typedef BOOL ( API * WTQUEUESIZESET ) ( HCTX, int ); +typedef int ( API * WTDATAPEEK ) ( HCTX, UINT, UINT, int, LPVOID, LPINT); +typedef int ( API * WTPACKETSGET ) (HCTX, int, LPVOID); + +// TODO - add more wintab32 function defs as needed + +// Loaded Wintab32 API functions. +extern HINSTANCE ghWintab; + +extern WTINFOA gpWTInfoA; +extern WTOPENA gpWTOpenA; +extern WTGETA gpWTGetA; +extern WTSETA gpWTSetA; +extern WTCLOSE gpWTClose; +extern WTPACKET gpWTPacket; +extern WTENABLE gpWTEnable; +extern WTOVERLAP gpWTOverlap; +extern WTSAVE gpWTSave; +extern WTCONFIG gpWTConfig; +extern WTRESTORE gpWTRestore; +extern WTEXTSET gpWTExtSet; +extern WTEXTGET gpWTExtGet; +extern WTQUEUESIZESET gpWTQueueSizeSet; +extern WTDATAPEEK gpWTDataPeek; +extern WTPACKETSGET gpWTPacketsGet; + +// TODO - add more wintab32 function pointers as needed + +////////////////////////////////////////////////////////////////////////////// +BOOL LoadWintab( void ); +void UnloadWintab( void ); + +////////////////////////////////////////////////////////////////////////////// +#ifdef WACOM_DEBUG + +void WacomTrace( char *lpszFormat, ...); + +#define WACOM_ASSERT( x ) assert( x ) +#define WACOM_TRACE(...) WacomTrace(__VA_ARGS__) +#else +#define WACOM_TRACE(...) +#define WACOM_ASSERT( x ) + +#endif // WACOM_DEBUG + diff --git a/plugins/wintab/src/main/native/net_java_games_input_WinTabContext.c b/plugins/wintab/src/main/native/net_java_games_input_WinTabContext.c index 99d6fe5..c00d848 100644 --- a/plugins/wintab/src/main/native/net_java_games_input_WinTabContext.c +++ b/plugins/wintab/src/main/native/net_java_games_input_WinTabContext.c @@ -3,6 +3,7 @@ #include #include "net_java_games_input_WinTabContext.h" +#include "wintabutils.h" #include //#define PACKETDATA ( PK_X | PK_Y | PK_Z | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ROTATION | PK_ORIENTATION | PK_CURSOR ) #define PACKETDATA ( PK_TIME | PK_X | PK_Y | PK_Z | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_TANGENT_PRESSURE | PK_ORIENTATION | PK_CURSOR ) @@ -22,7 +23,9 @@ JNIEXPORT jlong JNICALL Java_net_java_games_input_WinTabContext_nOpen(JNIEnv *en jmethodID getBooleanMethod = (*env)->GetStaticMethodID(env, booleanClass, "getBoolean", "(Ljava/lang/String;)Z"); jboolean detachCursor = (*env)->CallStaticBooleanMethod(env, booleanClass, getBooleanMethod, propertyName); - WTInfo(WTI_DEFCONTEXT, 0, &context); + LoadWintab(); + + gpWTInfoA(WTI_DEFCONTEXT, 0, &context); wsprintf(context.lcName, "JInput Digitizing"); context.lcPktData = PACKETDATA; @@ -34,18 +37,19 @@ JNIEXPORT jlong JNICALL Java_net_java_games_input_WinTabContext_nOpen(JNIEnv *en } /* open the region */ - hCtx = WTOpen(hWnd, &context, TRUE); + hCtx = gpWTOpenA(hWnd, &context, TRUE); return (jlong)(intptr_t)hCtx; } JNIEXPORT void JNICALL Java_net_java_games_input_WinTabContext_nClose(JNIEnv *env, jclass unused, jlong hCtx_long) { - WTClose((HCTX)(INT_PTR)hCtx_long); + gpWTClose((HCTX)(INT_PTR)hCtx_long); + UnloadWintab(); } JNIEXPORT jint JNICALL Java_net_java_games_input_WinTabContext_nGetNumberOfSupportedDevices(JNIEnv *env, jclass unused) { int numDevices; - WTInfo(WTI_INTERFACE, IFC_NDEVICES, &numDevices); + gpWTInfoA(WTI_INTERFACE, IFC_NDEVICES, &numDevices); return numDevices; } @@ -54,7 +58,7 @@ JNIEXPORT jobjectArray JNICALL Java_net_java_games_input_WinTabContext_nGetPacke jobjectArray retval; int i=0; PACKET packets[MAX_PACKETS]; - int numberRead = WTPacketsGet((HCTX)(INT_PTR)hCtx_long, MAX_PACKETS, packets); + int numberRead = gpWTPacketsGet((HCTX)(INT_PTR)hCtx_long, MAX_PACKETS, packets); jclass winTabPacketClass = (*env)->FindClass(env, "net/java/games/input/WinTabPacket"); jfieldID packetTimeField = (*env)->GetFieldID(env, winTabPacketClass, "PK_TIME", "J"); jfieldID packetXAxisField = (*env)->GetFieldID(env, winTabPacketClass, "PK_X", "I"); diff --git a/plugins/wintab/src/main/native/net_java_games_input_WinTabDevice.c b/plugins/wintab/src/main/native/net_java_games_input_WinTabDevice.c index 9aeef0a..45af0c1 100644 --- a/plugins/wintab/src/main/native/net_java_games_input_WinTabDevice.c +++ b/plugins/wintab/src/main/native/net_java_games_input_WinTabDevice.c @@ -4,6 +4,7 @@ #include #include "net_java_games_input_WinTabDevice.h" #include "util.h" +#include "wintabutils.h" #include #include #define PACKETDATA ( PK_X | PK_Y | PK_Z | PK_BUTTONS | PK_NORMAL_PRESSURE | PK_ORIENTATION | PK_CURSOR ) @@ -12,7 +13,7 @@ JNIEXPORT jstring JNICALL Java_net_java_games_input_WinTabDevice_nGetName(JNIEnv *env, jclass unused, jint deviceIndex) { char name[50]; - WTInfo(WTI_DEVICES + deviceIndex, DVC_NAME, name); + gpWTInfoA(WTI_DEVICES + deviceIndex, DVC_NAME, name); return (*env)->NewStringUTF(env, name); } @@ -34,7 +35,7 @@ JNIEXPORT jintArray JNICALL Java_net_java_games_input_WinTabDevice_nGetAxisDetai else if(axisId==net_java_games_input_WinTabDevice_RotationAxis) type = DVC_ROTATION; if(axisId==net_java_games_input_WinTabDevice_RotationAxis || axisId==net_java_games_input_WinTabDevice_OrientationAxis) { - res = WTInfo(WTI_DEVICES + deviceIndex, type, &threeAxisArray); + res = gpWTInfoA(WTI_DEVICES + deviceIndex, type, &threeAxisArray); if(res!=0) { threeAxisData[0] = threeAxisArray[0].axMin; threeAxisData[1] = threeAxisArray[0].axMax; @@ -46,7 +47,7 @@ JNIEXPORT jintArray JNICALL Java_net_java_games_input_WinTabDevice_nGetAxisDetai (*env)->SetIntArrayRegion(env, retVal, 0, 6, threeAxisData); } } else { - res = WTInfo(WTI_DEVICES + deviceIndex, type, &axis); + res = gpWTInfoA(WTI_DEVICES + deviceIndex, type, &axis); if(res!=0) { axisData[0] = axis.axMin; axisData[1] = axis.axMax; @@ -71,13 +72,13 @@ JNIEXPORT jobjectArray JNICALL Java_net_java_games_input_WinTabDevice_nGetCursor jstring nameString; jobjectArray retval; - WTInfo(WTI_DEVICES + deviceId, DVC_NCSRTYPES, &numberCursorTypes); - WTInfo(WTI_DEVICES + deviceId, DVC_FIRSTCSR, &firstCursorType); + gpWTInfoA(WTI_DEVICES + deviceId, DVC_NCSRTYPES, &numberCursorTypes); + gpWTInfoA(WTI_DEVICES + deviceId, DVC_FIRSTCSR, &firstCursorType); retval = (*env)->NewObjectArray(env, numberCursorTypes, stringClass, NULL); for(i=0;iNewStringUTF(env, name); (*env)->SetObjectArrayElement(env, retval, i-firstCursorType, nameString); } @@ -92,11 +93,11 @@ JNIEXPORT jint JNICALL Java_net_java_games_input_WinTabDevice_nGetMaxButtonCount int i; byte retval=0; - WTInfo(WTI_DEVICES + deviceId, DVC_NCSRTYPES, &numberCursorTypes); - WTInfo(WTI_DEVICES + deviceId, DVC_FIRSTCSR, &firstCursorType); + gpWTInfoA(WTI_DEVICES + deviceId, DVC_NCSRTYPES, &numberCursorTypes); + gpWTInfoA(WTI_DEVICES + deviceId, DVC_FIRSTCSR, &firstCursorType); for(i=0;iretval) { retval = buttonCount; }