Skip to content

Commit 9492a8a

Browse files
Copilotkatahiromz
andcommitted
Fix MBmpView to use .avi extension for temp files and add MCI error logging
Co-authored-by: katahiromz <2107452+katahiromz@users.noreply.github.com>
1 parent 72d4d94 commit 9492a8a

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

src/MBmpView.hpp

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,28 @@
2727
#ifndef _INC_VFW
2828
#include <vfw.h>
2929
#endif
30+
#include <mmsystem.h> // for mciGetErrorString
3031

3132
class MBmpView;
3233

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+
3352
//////////////////////////////////////////////////////////////////////////////
3453

3554
class MMciSubclassed : public MWindowBase
@@ -179,15 +198,43 @@ class MBmpView : public MWindowBase
179198
TCHAR szTempPath[MAX_PATH];
180199
GetTempPath(MAX_PATH, szTempPath);
181200
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+
182218
ShowScrollBar(m_hwnd, SB_BOTH, FALSE);
183219

184220
MByteStreamEx stream;
185221
stream.WriteData(ptr, size);
186222
if (stream.SaveToFile(m_szTempFile))
187223
{
188224
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+
}
191238
}
192239
}
193240

0 commit comments

Comments
 (0)