*/}}

wintab_utils.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*----------------------------------------------------------------------------
  2. NAME
  3. Utils.c
  4. PURPOSE
  5. Some general-purpose functions for the WinTab demos.
  6. COPYRIGHT
  7. Copyright (c) Wacom Company, Ltd. 2014 All Rights Reserved
  8. All rights reserved.
  9. The text and information contained in this file may be freely used,
  10. copied, or distributed without compensation or licensing restrictions.
  11. ---------------------------------------------------------------------------- */
  12. #include "wintab_utils.h"
  13. #ifdef WACOM_DEBUG
  14. void WacomTrace(char* lpszFormat, ...);
  15. #define WACOM_ASSERT( x ) assert( x )
  16. #define WACOM_TRACE(...) WacomTrace(__VA_ARGS__)
  17. #else
  18. #define WACOM_TRACE(...)
  19. #define WACOM_ASSERT( x )
  20. #endif // WACOM_DEBUG
  21. //////////////////////////////////////////////////////////////////////////////
  22. HINSTANCE ghWintab = NULL;
  23. WTINFOA gpWTInfoA = NULL;
  24. WTOPENA gpWTOpenA = NULL;
  25. WTGETA gpWTGetA = NULL;
  26. WTSETA gpWTSetA = NULL;
  27. WTCLOSE gpWTClose = NULL;
  28. WTPACKET gpWTPacket = NULL;
  29. WTENABLE gpWTEnable = NULL;
  30. WTOVERLAP gpWTOverlap = NULL;
  31. WTSAVE gpWTSave = NULL;
  32. WTCONFIG gpWTConfig = NULL;
  33. WTRESTORE gpWTRestore = NULL;
  34. WTEXTSET gpWTExtSet = NULL;
  35. WTEXTGET gpWTExtGet = NULL;
  36. WTQUEUESIZESET gpWTQueueSizeSet = NULL;
  37. WTDATAPEEK gpWTDataPeek = NULL;
  38. WTPACKETSGET gpWTPacketsGet = NULL;
  39. // TODO - add more wintab32 function pointers as needed
  40. char* pszProgramName = NULL;
  41. #define GETPROCADDRESS(type, func) \
  42. gp##func = (type)GetProcAddress(ghWintab, #func); \
  43. if (!gp##func){ WACOM_ASSERT(FALSE); UnloadWintab(); return FALSE; }
  44. //////////////////////////////////////////////////////////////////////////////
  45. // Purpose
  46. // Find wintab32.dll and load it.
  47. // Find the exported functions we need from it.
  48. //
  49. // Returns
  50. // TRUE on success.
  51. // FALSE on failure.
  52. //
  53. BOOL LoadWintab(void)
  54. {
  55. ghWintab = LoadLibraryA("Wintab32.dll");
  56. if (!ghWintab)
  57. {
  58. DWORD err = GetLastError();
  59. WACOM_TRACE("LoadLibrary error: %i\n", err);
  60. OutputDebugStringA("Could not load Wintab32.dll");
  61. return FALSE;
  62. }
  63. // Explicitly find the exported Wintab functions in which we are interested.
  64. // We are using the ASCII, not unicode versions (where applicable).
  65. GETPROCADDRESS(WTOPENA, WTOpenA);
  66. GETPROCADDRESS(WTINFOA, WTInfoA);
  67. GETPROCADDRESS(WTGETA, WTGetA);
  68. GETPROCADDRESS(WTSETA, WTSetA);
  69. GETPROCADDRESS(WTPACKET, WTPacket);
  70. GETPROCADDRESS(WTCLOSE, WTClose);
  71. GETPROCADDRESS(WTENABLE, WTEnable);
  72. GETPROCADDRESS(WTOVERLAP, WTOverlap);
  73. GETPROCADDRESS(WTSAVE, WTSave);
  74. GETPROCADDRESS(WTCONFIG, WTConfig);
  75. GETPROCADDRESS(WTRESTORE, WTRestore);
  76. GETPROCADDRESS(WTEXTSET, WTExtSet);
  77. GETPROCADDRESS(WTEXTGET, WTExtGet);
  78. GETPROCADDRESS(WTQUEUESIZESET, WTQueueSizeSet);
  79. GETPROCADDRESS(WTDATAPEEK, WTDataPeek);
  80. GETPROCADDRESS(WTPACKETSGET, WTPacketsGet);
  81. // TODO - don't forget to NULL out pointers in UnloadWintab().
  82. return TRUE;
  83. }
  84. //////////////////////////////////////////////////////////////////////////////
  85. // Purpose
  86. // Uninitializes use of wintab32.dll
  87. //
  88. // Returns
  89. // Nothing.
  90. //
  91. void UnloadWintab(void)
  92. {
  93. WACOM_TRACE("UnloadWintab()\n");
  94. if (ghWintab)
  95. {
  96. FreeLibrary(ghWintab);
  97. ghWintab = NULL;
  98. }
  99. gpWTOpenA = NULL;
  100. gpWTClose = NULL;
  101. gpWTInfoA = NULL;
  102. gpWTPacket = NULL;
  103. gpWTEnable = NULL;
  104. gpWTOverlap = NULL;
  105. gpWTSave = NULL;
  106. gpWTConfig = NULL;
  107. gpWTGetA = NULL;
  108. gpWTSetA = NULL;
  109. gpWTRestore = NULL;
  110. gpWTExtSet = NULL;
  111. gpWTExtGet = NULL;
  112. gpWTQueueSizeSet = NULL;
  113. gpWTDataPeek = NULL;
  114. gpWTPacketsGet = NULL;
  115. }
  116. #ifdef WACOM_DEBUG
  117. //////////////////////////////////////////////////////////////////////////////
  118. void WacomTrace(char* lpszFormat, ...)
  119. {
  120. char szTraceMessage[128];
  121. int nBytesWritten;
  122. va_list args;
  123. WACOM_ASSERT(lpszFormat);
  124. va_start(args, lpszFormat);
  125. nBytesWritten = _vsnprintf(szTraceMessage, sizeof(szTraceMessage) - 1,
  126. lpszFormat, args);
  127. if (nBytesWritten > 0)
  128. {
  129. OutputDebugStringA(szTraceMessage);
  130. }
  131. va_end(args);
  132. }
  133. #endif // WACOM_DEBUG