From ebcbdb9cdc8fbf60993a749a619ca04c80f396e7 Mon Sep 17 00:00:00 2001 From: Eric Pouech Date: Tue, 20 Oct 2009 21:54:52 +0200 Subject: [PATCH] winmm: Simplify mciLoadCommandResource by dropping 16bit module support. --- dlls/winmm/mci.c | 55 ++++++++++++++++++++---------------------- dlls/winmm/mci16.c | 19 +++++++++++++++ dlls/winmm/mmsystem.c | 56 ------------------------------------------- dlls/winmm/winemm.h | 2 -- 4 files changed, 45 insertions(+), 87 deletions(-) diff --git a/dlls/winmm/mci.c b/dlls/winmm/mci.c index 53908155257..f0634a6f750 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, 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, 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, UINT uDevType) { int uTbl; static BOOL bInitDone = FALSE; @@ -721,7 +723,7 @@ UINT MCI_SetCommandTable(void *table, UINT uDevType) bInitDone = TRUE; MCI_GetCommandTable(0); } - TRACE("(%p, %u)\n", table, uDevType); + TRACE("(%p, %u)\n", hMem, uDevType); for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) { if (!S_MciCmdTable[uTbl].lpTable) { const BYTE* lmem; @@ -730,7 +732,8 @@ UINT MCI_SetCommandTable(void *table, UINT uDevType) WORD count; S_MciCmdTable[uTbl].uDevType = uDevType; - S_MciCmdTable[uTbl].lpTable = table; + S_MciCmdTable[uTbl].lpTable = LockResource(hMem); + S_MciCmdTable[uTbl].hMem = hMem; if (TRACE_ON(mci)) { MCI_DumpCommandTable(uTbl); @@ -770,21 +773,6 @@ UINT MCI_SetCommandTable(void *table, UINT uDevType) return MCI_NO_COMMAND_TABLE; } -/************************************************************************** - * 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] */ @@ -1539,9 +1527,9 @@ BOOL WINAPI mciExecute(LPCSTR lpstrCommand) */ UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type) { - HRSRC hRsrc = 0; - HGLOBAL hMem; - UINT16 ret = MCI_NO_COMMAND_TABLE; + UINT ret = MCI_NO_COMMAND_TABLE; + HRSRC hRsrc = 0; + HGLOBAL hMem; TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type); @@ -1563,13 +1551,13 @@ UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type) } #endif } - 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); - } else { - WARN("Couldn't load resource.\n"); + if ((hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA)) && + (hMem = LoadResource(hInst, hRsrc))) { + ret = MCI_SetCommandTable(hMem, type); + FreeResource(hMem); } + else WARN("No command table found in module for %s\n", debugstr_w(resNameW)); + TRACE("=> %04x\n", ret); return ret; } @@ -1581,7 +1569,16 @@ BOOL WINAPI mciFreeCommandResource(UINT uTable) { TRACE("(%08x)!\n", uTable); - return MCI_DeleteCommandTable(uTable, FALSE); + if (uTable >= MAX_MCICMDTABLE || !S_MciCmdTable[uTable].lpTable) + return FALSE; + + FreeResource(S_MciCmdTable[uTable].hMem); + 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 6155bdbe9b8..e1586b76900 100644 --- a/dlls/winmm/mci16.c +++ b/dlls/winmm/mci16.c @@ -323,3 +323,22 @@ 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) +{ + TRACE("(%04x, %s, %x)!\n", hInst, resname, type); + return MCI_NO_COMMAND_TABLE; +} + +/************************************************************************** + * mciFreeCommandResource [MMSYSTEM.713] + */ +BOOL16 WINAPI mciFreeCommandResource16(UINT16 uTable) +{ + TRACE("(%04x)!\n", uTable); + + return FALSE; +} diff --git a/dlls/winmm/mmsystem.c b/dlls/winmm/mmsystem.c index 0b4a69461a5..d5607730b92 100644 --- a/dlls/winmm/mmsystem.c +++ b/dlls/winmm/mmsystem.c @@ -2509,62 +2509,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 97403e56bf0..6af5f01be90 100644 --- a/dlls/winmm/winemm.h +++ b/dlls/winmm/winemm.h @@ -197,8 +197,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);