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.

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