[PATCH 3/5] [WinMM]: allow 32-bit mciLoadCommandResource to load out of 16 bit module
Eric Pouech
eric.pouech at orange.fr
Sat Oct 17 05:05:12 CDT 2009
(and move mciLoadCommandResource16 inner code to its 32bit counter part)
A+
---
dlls/winmm/mci.c | 72 ++++++++++++++++++++++++++++++++++++-------------
dlls/winmm/mci16.c | 33 ++++++++++++++++++++++
dlls/winmm/mmsystem.c | 56 --------------------------------------
dlls/winmm/winemm.h | 2 -
4 files changed, 86 insertions(+), 77 deletions(-)
diff --git a/dlls/winmm/mci.c b/dlls/winmm/mci.c
index 7790e7c..457b5b9 100644
--- a/dlls/winmm/mci.c
+++ b/dlls/winmm/mci.c
@@ -84,6 +84,7 @@ static const WCHAR wszSystemIni[] = {'s','y','s','t','e','m','.','i','n','i',0};
static WINE_MCIDRIVER *MciDrivers;
static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data);
+static UINT MCI_SetCommandTable(HGLOBAL hMem, void *table, UINT uDevType);
/* dup a string and uppercase it */
static inline LPWSTR str_dup_upper( LPCWSTR str )
@@ -581,6 +582,7 @@ static DWORD MCI_GetDevTypeFromFileName(LPCWSTR fileName, LPWSTR buf, UINT len)
typedef struct tagWINE_MCICMDTABLE {
UINT uDevType;
+ HGLOBAL hMem;
const BYTE* lpTable;
UINT nVerbs; /* number of verbs in command table */
LPCWSTR* aVerbs; /* array of verbs to speed up the verb look up process */
@@ -694,7 +696,7 @@ static UINT MCI_GetCommandTable(UINT uDevType)
if (hRsrc) hMem = LoadResource(hWinMM32Instance, hRsrc);
if (hMem) {
- uTbl = MCI_SetCommandTable(LockResource(hMem), uDevType);
+ uTbl = MCI_SetCommandTable(hMem, LockResource(hMem), uDevType);
} else {
WARN("No command table found in resource %p[%s]\n",
hWinMM32Instance, debugstr_w(str));
@@ -707,7 +709,7 @@ static UINT MCI_GetCommandTable(UINT uDevType)
/**************************************************************************
* MCI_SetCommandTable [internal]
*/
-UINT MCI_SetCommandTable(void *table, UINT uDevType)
+static UINT MCI_SetCommandTable(HGLOBAL hMem, void *table, UINT uDevType)
{
int uTbl;
static BOOL bInitDone = FALSE;
@@ -731,6 +733,7 @@ UINT MCI_SetCommandTable(void *table, UINT uDevType)
S_MciCmdTable[uTbl].uDevType = uDevType;
S_MciCmdTable[uTbl].lpTable = table;
+ S_MciCmdTable[uTbl].hMem = hMem;
if (TRACE_ON(mci)) {
MCI_DumpCommandTable(uTbl);
@@ -771,21 +774,6 @@ UINT MCI_SetCommandTable(void *table, UINT uDevType)
}
/**************************************************************************
- * MCI_DeleteCommandTable [internal]
- */
-BOOL MCI_DeleteCommandTable(UINT uTbl, BOOL delete)
-{
- if (uTbl >= MAX_MCICMDTABLE || !S_MciCmdTable[uTbl].lpTable)
- return FALSE;
-
- if (delete) HeapFree(GetProcessHeap(), 0, (void*)S_MciCmdTable[uTbl].lpTable);
- S_MciCmdTable[uTbl].lpTable = NULL;
- HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTbl].aVerbs);
- S_MciCmdTable[uTbl].aVerbs = 0;
- return TRUE;
-}
-
-/**************************************************************************
* MCI_UnLoadMciDriver [internal]
*/
static BOOL MCI_UnLoadMciDriver(LPWINE_MCIDRIVER wmd)
@@ -1566,7 +1554,41 @@ UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
if (!(hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA))) {
WARN("No command table found in resource\n");
} else if ((hMem = LoadResource(hInst, hRsrc))) {
- ret = MCI_SetCommandTable(LockResource(hMem), type);
+ if (!HIWORD(hInst)) { /* it's a 16bit resource, convert it */
+ const BYTE* ptr16 = LockResource(hMem);
+ BYTE* ptr32;
+ unsigned pos = 0, size = 1024, len;
+ const char* str;
+ DWORD flg;
+ WORD eid;
+
+ /* converting the 16 bit resource table into a 32W one */
+ if ((ptr32 = HeapAlloc(GetProcessHeap(), 0, size)))
+ {
+ do {
+ str = (LPCSTR)ptr16;
+ ptr16 += strlen(str) + 1;
+ flg = *(const DWORD*)ptr16;
+ eid = *(const WORD*)(ptr16 + sizeof(DWORD));
+ ptr16 += sizeof(DWORD) + sizeof(WORD);
+ len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0) * sizeof(WCHAR);
+ if (pos + len + sizeof(DWORD) + sizeof(WORD) > size)
+ {
+ while (pos + len * sizeof(WCHAR) + sizeof(DWORD) + sizeof(WORD) > size) size += 1024;
+ ptr32 = HeapReAlloc(GetProcessHeap(), 0, ptr32, size);
+ if (!ptr32) goto the_end;
+ }
+ MultiByteToWideChar(CP_ACP, 0, str, -1, (LPWSTR)(ptr32 + pos), len / sizeof(WCHAR));
+ *(DWORD*)(ptr32 + pos + len) = flg;
+ *(WORD*)(ptr32 + pos + len + sizeof(DWORD)) = eid;
+ pos += len + sizeof(DWORD) + sizeof(WORD);
+ } while (eid != MCI_END_COMMAND_LIST);
+ }
+ the_end:
+ FreeResource(hMem);
+ if (ptr32) ret = MCI_SetCommandTable(NULL, ptr32, type);
+ }
+ else ret = MCI_SetCommandTable(hMem, LockResource(hMem), type);
} else {
WARN("Couldn't load resource.\n");
}
@@ -1581,7 +1603,19 @@ BOOL WINAPI mciFreeCommandResource(UINT uTable)
{
TRACE("(%08x)!\n", uTable);
- return MCI_DeleteCommandTable(uTable, FALSE);
+ if (uTable >= MAX_MCICMDTABLE || !S_MciCmdTable[uTable].lpTable)
+ return FALSE;
+
+ if (S_MciCmdTable[uTable].hMem)
+ FreeResource(S_MciCmdTable[uTable].hMem);
+ else
+ HeapFree(GetProcessHeap(), 0, (void*)S_MciCmdTable[uTable].lpTable);
+ S_MciCmdTable[uTable].hMem = NULL;
+ S_MciCmdTable[uTable].lpTable = NULL;
+ HeapFree(GetProcessHeap(), 0, S_MciCmdTable[uTable].aVerbs);
+ S_MciCmdTable[uTable].aVerbs = 0;
+ S_MciCmdTable[uTable].nVerbs = 0;
+ return TRUE;
}
/**************************************************************************
diff --git a/dlls/winmm/mci16.c b/dlls/winmm/mci16.c
index 6155bdb..dc3c861 100644
--- a/dlls/winmm/mci16.c
+++ b/dlls/winmm/mci16.c
@@ -323,3 +323,36 @@ DWORD WINAPI mciSendString16(LPCSTR lpstrCommand, LPSTR lpstrRet,
{
return mciSendStringA(lpstrCommand, lpstrRet, uRetLen, HWND_32(hwndCallback));
}
+
+/**************************************************************************
+ * mciLoadCommandResource [MMSYSTEM.705]
+ */
+UINT16 WINAPI mciLoadCommandResource16(HINSTANCE16 hInst, LPCSTR resname, UINT16 type)
+{
+ LPWSTR resnameW = NULL;
+ BOOL ret;
+
+ TRACE("(%04x, %s, %x)!\n", hInst, resname, type);
+
+ if (resname)
+ {
+ unsigned len = MultiByteToWideChar( CP_ACP, 0, resname, -1, NULL, 0 );
+ resnameW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
+ if (resnameW) MultiByteToWideChar( CP_ACP, 0, resname, -1, resnameW, len );
+ } else resnameW = NULL;
+
+ ret = mciLoadCommandResource((HINSTANCE)(ULONG_PTR)hInst, resnameW, type);
+ HeapFree(GetProcessHeap(), 0, resnameW);
+ return ret;
+}
+
+/**************************************************************************
+ * mciFreeCommandResource [MMSYSTEM.713]
+ */
+BOOL16 WINAPI mciFreeCommandResource16(UINT16 uTable)
+{
+ TRACE("(%04x)!\n", uTable);
+
+ return mciFreeCommandResource(uTable);
+}
+
diff --git a/dlls/winmm/mmsystem.c b/dlls/winmm/mmsystem.c
index 3b36f8b..9710d3b 100644
--- a/dlls/winmm/mmsystem.c
+++ b/dlls/winmm/mmsystem.c
@@ -2433,62 +2433,6 @@ MMRESULT16 WINAPI timeEndPeriod16(UINT16 wPeriod)
return timeEndPeriod(wPeriod);
}
-/**************************************************************************
- * mciLoadCommandResource [MMSYSTEM.705]
- */
-UINT16 WINAPI mciLoadCommandResource16(HINSTANCE16 hInst, LPCSTR resname, UINT16 type)
-{
- HRSRC16 res;
- HGLOBAL16 handle;
- const BYTE* ptr16;
- BYTE* ptr32;
- unsigned pos = 0, size = 1024, len;
- const char* str;
- DWORD flg;
- WORD eid;
- UINT16 ret = MCIERR_OUT_OF_MEMORY;
-
- if (!(res = FindResource16( hInst, resname, (LPSTR)RT_RCDATA))) return MCI_NO_COMMAND_TABLE;
- if (!(handle = LoadResource16( hInst, res ))) return MCI_NO_COMMAND_TABLE;
- ptr16 = LockResource16(handle);
- /* converting the 16 bit resource table into a 32W one */
- if ((ptr32 = HeapAlloc(GetProcessHeap(), 0, size)))
- {
- do {
- str = (LPCSTR)ptr16;
- ptr16 += strlen(str) + 1;
- flg = *(const DWORD*)ptr16;
- eid = *(const WORD*)(ptr16 + sizeof(DWORD));
- ptr16 += sizeof(DWORD) + sizeof(WORD);
- len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0) * sizeof(WCHAR);
- if (pos + len + sizeof(DWORD) + sizeof(WORD) > size)
- {
- while (pos + len * sizeof(WCHAR) + sizeof(DWORD) + sizeof(WORD) > size) size += 1024;
- ptr32 = HeapReAlloc(GetProcessHeap(), 0, ptr32, size);
- if (!ptr32) goto the_end;
- }
- MultiByteToWideChar(CP_ACP, 0, str, -1, (LPWSTR)(ptr32 + pos), len / sizeof(WCHAR));
- *(DWORD*)(ptr32 + pos + len) = flg;
- *(WORD*)(ptr32 + pos + len + sizeof(DWORD)) = eid;
- pos += len + sizeof(DWORD) + sizeof(WORD);
- } while (eid != MCI_END_COMMAND_LIST);
- }
-the_end:
- FreeResource16( handle );
- if (ptr32) ret = MCI_SetCommandTable(ptr32, type);
- return ret;
-}
-
-/**************************************************************************
- * mciFreeCommandResource [MMSYSTEM.713]
- */
-BOOL16 WINAPI mciFreeCommandResource16(UINT16 uTable)
-{
- TRACE("(%04x)!\n", uTable);
-
- return MCI_DeleteCommandTable(uTable, TRUE);
-}
-
/* ###################################################
* # JOYSTICK #
* ###################################################
diff --git a/dlls/winmm/winemm.h b/dlls/winmm/winemm.h
index 22bf222..4e7b298 100644
--- a/dlls/winmm/winemm.h
+++ b/dlls/winmm/winemm.h
@@ -199,8 +199,6 @@ void MMDRV_InstallMap(unsigned int, MMDRV_MAPFUNC, MMDRV_UNMAPFUNC,
const char* MCI_MessageToString(UINT wMsg);
DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2);
-UINT MCI_SetCommandTable(void *table, UINT uDevType);
-BOOL MCI_DeleteCommandTable(UINT uTbl, BOOL delete);
LPWSTR MCI_strdupAtoW(LPCSTR str);
LPSTR MCI_strdupWtoA(LPCWSTR str);
More information about the wine-patches
mailing list