Leaked source code of windows server 2003
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.

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