|
27 | 27 | #ifndef _INC_VFW |
28 | 28 | #include <vfw.h> |
29 | 29 | #endif |
| 30 | +#include <mmsystem.h> // for mciGetErrorString |
30 | 31 |
|
31 | 32 | class MBmpView; |
32 | 33 |
|
| 34 | +// Helper to log MCI errors for debugging purposes |
| 35 | +inline void LogMCIError(DWORD dwError, LPCTSTR pszContext) |
| 36 | +{ |
| 37 | + TCHAR szError[256]; |
| 38 | + if (mciGetErrorString(dwError, szError, _countof(szError))) |
| 39 | + { |
| 40 | + TCHAR szMsg[512]; |
| 41 | + wsprintf(szMsg, TEXT("MCI Error in %s: %s (code %lu)\n"), pszContext, szError, dwError); |
| 42 | + OutputDebugString(szMsg); |
| 43 | + } |
| 44 | + else |
| 45 | + { |
| 46 | + TCHAR szMsg[128]; |
| 47 | + wsprintf(szMsg, TEXT("MCI Error in %s: code %lu\n"), pszContext, dwError); |
| 48 | + OutputDebugString(szMsg); |
| 49 | + } |
| 50 | +} |
| 51 | + |
33 | 52 | ////////////////////////////////////////////////////////////////////////////// |
34 | 53 |
|
35 | 54 | class MMciSubclassed : public MWindowBase |
@@ -179,15 +198,43 @@ class MBmpView : public MWindowBase |
179 | 198 | TCHAR szTempPath[MAX_PATH]; |
180 | 199 | GetTempPath(MAX_PATH, szTempPath); |
181 | 200 | GetTempFileName(szTempPath, TEXT("avi"), 0, m_szTempFile); |
| 201 | + |
| 202 | + // MCI relies on file extension to determine media type; rename .tmp to .avi |
| 203 | + // so that compressed AVI files are properly recognized on some systems. |
| 204 | + LPTSTR pszDot = _tcsrchr(m_szTempFile, TEXT('.')); |
| 205 | + if (pszDot != NULL) |
| 206 | + { |
| 207 | + // Ensure buffer has room for ".avi" (4 chars + null terminator) |
| 208 | + if (pszDot + 5 <= m_szTempFile + _countof(m_szTempFile)) |
| 209 | + { |
| 210 | + TCHAR szOldPath[MAX_PATH]; |
| 211 | + _tcscpy_s(szOldPath, m_szTempFile); |
| 212 | + _tcscpy_s(pszDot, _countof(m_szTempFile) - (pszDot - m_szTempFile), TEXT(".avi")); |
| 213 | + // Rename the temp file created by GetTempFileName |
| 214 | + MoveFile(szOldPath, m_szTempFile); |
| 215 | + } |
| 216 | + } |
| 217 | + |
182 | 218 | ShowScrollBar(m_hwnd, SB_BOTH, FALSE); |
183 | 219 |
|
184 | 220 | MByteStreamEx stream; |
185 | 221 | stream.WriteData(ptr, size); |
186 | 222 | if (stream.SaveToFile(m_szTempFile)) |
187 | 223 | { |
188 | 224 | ShowWindow(m_mci_window, SW_SHOWNOACTIVATE); |
189 | | - MCIWndOpen(m_mci_window, m_szTempFile, 0); |
190 | | - MCIWndPlay(m_mci_window); |
| 225 | + DWORD dwError = (DWORD)MCIWndOpen(m_mci_window, m_szTempFile, 0); |
| 226 | + if (dwError != 0) |
| 227 | + { |
| 228 | + LogMCIError(dwError, TEXT("MCIWndOpen")); |
| 229 | + ShowWindow(m_mci_window, SW_HIDE); |
| 230 | + return; |
| 231 | + } |
| 232 | + dwError = (DWORD)MCIWndPlay(m_mci_window); |
| 233 | + if (dwError != 0) |
| 234 | + { |
| 235 | + LogMCIError(dwError, TEXT("MCIWndPlay")); |
| 236 | + ShowWindow(m_mci_window, SW_HIDE); |
| 237 | + } |
191 | 238 | } |
192 | 239 | } |
193 | 240 |
|
|
0 commit comments