Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

276 lines
6.7 KiB

  1. /****************************************************************************
  2. *
  3. * capmisc.c
  4. *
  5. * Miscellaneous status and error routines.
  6. *
  7. * Microsoft Video for Windows Sample Capture Class
  8. *
  9. * Copyright (c) 1992, 1993 Microsoft Corporation. All Rights Reserved.
  10. *
  11. * You have a royalty-free right to use, modify, reproduce and
  12. * distribute the Sample Files (and/or any modified version) in
  13. * any way you find useful, provided that you agree that
  14. * Microsoft has no warranty obligations or liability for any
  15. * Sample Application Files which are modified.
  16. *
  17. ***************************************************************************/
  18. #define INC_OLE2
  19. #pragma warning(disable:4103)
  20. #include <windows.h>
  21. #include <windowsx.h>
  22. #include <win32.h>
  23. #include <mmsystem.h>
  24. #include <vfw.h>
  25. #include "ivideo32.h"
  26. #include "avicapi.h"
  27. #include <stdarg.h>
  28. static TCHAR szNull[] = TEXT("");
  29. /*
  30. *
  31. * GetKey
  32. * Peek into the message que and get a keystroke
  33. *
  34. */
  35. UINT GetKey(BOOL fWait)
  36. {
  37. MSG msg;
  38. msg.wParam = 0;
  39. if (fWait)
  40. GetMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST);
  41. while(PeekMessage(&msg, NULL, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE|PM_NOYIELD))
  42. ;
  43. return (UINT) msg.wParam;
  44. }
  45. // wID is the string resource, which can be a format string
  46. //
  47. void FAR CDECL statusUpdateStatus (LPCAPSTREAM lpcs, UINT wID, ...)
  48. {
  49. TCHAR ach[256];
  50. TCHAR szFmt[132];
  51. va_list va;
  52. if (!lpcs->CallbackOnStatus)
  53. return;
  54. if (wID == 0) {
  55. if (lpcs->fLastStatusWasNULL) // No need to send NULL twice in a row
  56. return;
  57. lpcs->fLastStatusWasNULL = TRUE;
  58. ach[0] = 0;
  59. }
  60. else {
  61. lpcs->fLastStatusWasNULL = FALSE;
  62. if (!LoadString(lpcs->hInst, wID, szFmt, NUMELMS(szFmt))) {
  63. MessageBeep (0);
  64. return;
  65. }
  66. else {
  67. va_start(va, wID);
  68. wvsprintf(ach, szFmt, va);
  69. va_end(va);
  70. }
  71. }
  72. #ifdef UNICODE
  73. //
  74. // if the status callback function is expecting ansi
  75. // strings, then convert the UNICODE status string to
  76. // ansi before calling him
  77. //
  78. if (lpcs->fUnicode & VUNICODE_STATUSISANSI) {
  79. char achAnsi[256];
  80. // convert string to Ansi and callback.
  81. // that we cast achAnsi to WChar on the call to
  82. // avoid a bogus warning.
  83. //
  84. WideToAnsi(achAnsi, ach, lstrlen(ach)+1);
  85. lpcs->CallbackOnStatus(lpcs->hwnd, wID, (LPWSTR)achAnsi);
  86. }
  87. else
  88. #endif
  89. lpcs->CallbackOnStatus(lpcs->hwnd, wID, ach);
  90. }
  91. // wID is the string resource, which can be a format string
  92. //
  93. void FAR CDECL errorUpdateError (LPCAPSTREAM lpcs, UINT wID, ...)
  94. {
  95. TCHAR ach[256];
  96. TCHAR szFmt[132];
  97. va_list va;
  98. lpcs->dwReturn = wID;
  99. if (!lpcs->CallbackOnError)
  100. return;
  101. if (wID == 0) {
  102. if (lpcs->fLastErrorWasNULL) // No need to send NULL twice in a row
  103. return;
  104. lpcs->fLastErrorWasNULL = TRUE;
  105. ach[0] = 0;
  106. }
  107. else if (!LoadString(lpcs->hInst, wID, szFmt, NUMELMS(szFmt))) {
  108. MessageBeep (0);
  109. lpcs->fLastErrorWasNULL = FALSE;
  110. return;
  111. }
  112. else {
  113. lpcs->fLastErrorWasNULL = FALSE;
  114. va_start(va, wID);
  115. wvsprintf(ach, szFmt, va);
  116. va_end(va);
  117. }
  118. #ifdef UNICODE
  119. if (lpcs->fUnicode & VUNICODE_ERRORISANSI)
  120. {
  121. char achAnsi[256];
  122. // convert string to Ansi and callback.
  123. // that we cast achAnsi to WChar on the call to
  124. // avoid a bogus warning.
  125. //
  126. WideToAnsi(achAnsi, ach, lstrlen(ach)+1);
  127. lpcs->CallbackOnError(lpcs->hwnd, wID, (LPWSTR)achAnsi);
  128. }
  129. else
  130. #endif
  131. {
  132. lpcs->CallbackOnError(lpcs->hwnd, wID, ach);
  133. }
  134. }
  135. // Callback client with ID of driver error msg
  136. void errorDriverID (LPCAPSTREAM lpcs, DWORD dwError)
  137. {
  138. // this is the correct code, but NT VfW 1.0 has a bug
  139. // that videoGetErrorText is ansi. need vfw1.1 to fix this
  140. #ifndef UNICODE
  141. char ach[132];
  142. #endif
  143. lpcs->fLastErrorWasNULL = FALSE;
  144. lpcs->dwReturn = dwError;
  145. if (!lpcs->CallbackOnError)
  146. return;
  147. #ifdef UNICODE
  148. if (lpcs->fUnicode & VUNICODE_ERRORISANSI) {
  149. char achAnsi[256];
  150. achAnsi[0]=0;
  151. if (dwError)
  152. videoGetErrorTextA(lpcs->hVideoIn, dwError, achAnsi, NUMELMS(achAnsi));
  153. lpcs->CallbackOnError (lpcs->hwnd, IDS_CAP_DRIVER_ERROR, (LPWSTR)achAnsi);
  154. } else {
  155. // pass unicode string to error handler
  156. WCHAR achWide[256];
  157. achWide[0]=0;
  158. if (dwError)
  159. videoGetErrorTextW(lpcs->hVideoIn, dwError, achWide, NUMELMS(achWide));
  160. lpcs->CallbackOnError (lpcs->hwnd, IDS_CAP_DRIVER_ERROR, (LPWSTR)achWide);
  161. }
  162. #else // not unicode
  163. ach[0] = 0;
  164. if (dwError)
  165. videoGetErrorText (lpcs->hVideoIn, dwError, ach, NUMELMS(ach));
  166. lpcs->CallbackOnError(lpcs->hwnd, IDS_CAP_DRIVER_ERROR, ach);
  167. #endif
  168. }
  169. #ifdef _DEBUG
  170. void FAR cdecl dprintf(LPSTR szFormat, ...)
  171. {
  172. UINT n;
  173. char ach[256];
  174. va_list va;
  175. static BOOL fDebug = -1;
  176. if (fDebug == -1)
  177. fDebug = GetProfileIntA("Debug", "AVICAP32", FALSE);
  178. if (!fDebug)
  179. return;
  180. #ifdef _WIN32
  181. n = wsprintfA(ach, "AVICAP32: (tid %x) ", GetCurrentThreadId());
  182. #else
  183. strcpy(ach, "AVICAP32: ");
  184. n = strlen(ach);
  185. #endif
  186. va_start(va, szFormat);
  187. wvsprintfA(ach+n, szFormat, va);
  188. va_end(va);
  189. lstrcatA(ach, "\r\n");
  190. OutputDebugStringA(ach);
  191. }
  192. /* _Assert(fExpr, szFile, iLine)
  193. *
  194. * If <fExpr> is TRUE, then do nothing. If <fExpr> is FALSE, then display
  195. * an "assertion failed" message box allowing the user to abort the program,
  196. * enter the debugger (the "Retry" button), or igore the error.
  197. *
  198. * <szFile> is the name of the source file; <iLine> is the line number
  199. * containing the _Assert() call.
  200. */
  201. BOOL FAR PASCAL
  202. _Assert(BOOL fExpr, LPSTR szFile, int iLine)
  203. {
  204. static char ach[300]; // debug output (avoid stack overflow)
  205. int id;
  206. int iExitCode;
  207. void FAR PASCAL DebugBreak(void);
  208. /* check if assertion failed */
  209. if (fExpr)
  210. return fExpr;
  211. /* display error message */
  212. wsprintfA(ach, "File %s, line %d", (LPSTR) szFile, iLine);
  213. MessageBeep(MB_ICONHAND);
  214. id = MessageBoxA (NULL, ach, "Assertion Failed",
  215. MB_SYSTEMMODAL | MB_ICONHAND | MB_ABORTRETRYIGNORE);
  216. /* abort, debug, or ignore */
  217. switch (id)
  218. {
  219. case IDABORT: /* kill this application */
  220. iExitCode = 0;
  221. ExitProcess(0);
  222. break;
  223. case IDRETRY: /* break into the debugger */
  224. DebugBreak();
  225. break;
  226. case IDIGNORE:
  227. /* ignore the assertion failure */
  228. break;
  229. }
  230. return FALSE;
  231. }
  232. #endif