winmm: Simplify mciLoadCommandResource by dropping 16bit module support.

This commit is contained in:
Eric Pouech 2009-10-20 21:54:52 +02:00 committed by Alexandre Julliard
parent dd26bee14c
commit ebcbdb9cdc
4 changed files with 45 additions and 87 deletions

View File

@ -84,6 +84,7 @@ static const WCHAR wszSystemIni[] = {'s','y','s','t','e','m','.','i','n','i',0};
static WINE_MCIDRIVER *MciDrivers; static WINE_MCIDRIVER *MciDrivers;
static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data); static UINT WINAPI MCI_DefYieldProc(MCIDEVICEID wDevID, DWORD data);
static UINT MCI_SetCommandTable(HGLOBAL hMem, UINT uDevType);
/* dup a string and uppercase it */ /* dup a string and uppercase it */
static inline LPWSTR str_dup_upper( LPCWSTR str ) 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 { typedef struct tagWINE_MCICMDTABLE {
UINT uDevType; UINT uDevType;
HGLOBAL hMem;
const BYTE* lpTable; const BYTE* lpTable;
UINT nVerbs; /* number of verbs in command table */ UINT nVerbs; /* number of verbs in command table */
LPCWSTR* aVerbs; /* array of verbs to speed up the verb look up process */ 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 (hRsrc) hMem = LoadResource(hWinMM32Instance, hRsrc);
if (hMem) { if (hMem) {
uTbl = MCI_SetCommandTable(LockResource(hMem), uDevType); uTbl = MCI_SetCommandTable(hMem, uDevType);
} else { } else {
WARN("No command table found in resource %p[%s]\n", WARN("No command table found in resource %p[%s]\n",
hWinMM32Instance, debugstr_w(str)); hWinMM32Instance, debugstr_w(str));
@ -707,7 +709,7 @@ static UINT MCI_GetCommandTable(UINT uDevType)
/************************************************************************** /**************************************************************************
* MCI_SetCommandTable [internal] * MCI_SetCommandTable [internal]
*/ */
UINT MCI_SetCommandTable(void *table, UINT uDevType) static UINT MCI_SetCommandTable(HGLOBAL hMem, UINT uDevType)
{ {
int uTbl; int uTbl;
static BOOL bInitDone = FALSE; static BOOL bInitDone = FALSE;
@ -721,7 +723,7 @@ UINT MCI_SetCommandTable(void *table, UINT uDevType)
bInitDone = TRUE; bInitDone = TRUE;
MCI_GetCommandTable(0); MCI_GetCommandTable(0);
} }
TRACE("(%p, %u)\n", table, uDevType); TRACE("(%p, %u)\n", hMem, uDevType);
for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) { for (uTbl = 0; uTbl < MAX_MCICMDTABLE; uTbl++) {
if (!S_MciCmdTable[uTbl].lpTable) { if (!S_MciCmdTable[uTbl].lpTable) {
const BYTE* lmem; const BYTE* lmem;
@ -730,7 +732,8 @@ UINT MCI_SetCommandTable(void *table, UINT uDevType)
WORD count; WORD count;
S_MciCmdTable[uTbl].uDevType = uDevType; 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)) { if (TRACE_ON(mci)) {
MCI_DumpCommandTable(uTbl); MCI_DumpCommandTable(uTbl);
@ -770,21 +773,6 @@ UINT MCI_SetCommandTable(void *table, UINT uDevType)
return MCI_NO_COMMAND_TABLE; 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] * MCI_UnLoadMciDriver [internal]
*/ */
@ -1539,9 +1527,9 @@ BOOL WINAPI mciExecute(LPCSTR lpstrCommand)
*/ */
UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type) UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
{ {
HRSRC hRsrc = 0; UINT ret = MCI_NO_COMMAND_TABLE;
HGLOBAL hMem; HRSRC hRsrc = 0;
UINT16 ret = MCI_NO_COMMAND_TABLE; HGLOBAL hMem;
TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type); TRACE("(%p, %s, %d)!\n", hInst, debugstr_w(resNameW), type);
@ -1563,13 +1551,13 @@ UINT WINAPI mciLoadCommandResource(HINSTANCE hInst, LPCWSTR resNameW, UINT type)
} }
#endif #endif
} }
if (!(hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA))) { if ((hRsrc = FindResourceW(hInst, resNameW, (LPWSTR)RT_RCDATA)) &&
WARN("No command table found in resource\n"); (hMem = LoadResource(hInst, hRsrc))) {
} else if ((hMem = LoadResource(hInst, hRsrc))) { ret = MCI_SetCommandTable(hMem, type);
ret = MCI_SetCommandTable(LockResource(hMem), type); FreeResource(hMem);
} else {
WARN("Couldn't load resource.\n");
} }
else WARN("No command table found in module for %s\n", debugstr_w(resNameW));
TRACE("=> %04x\n", ret); TRACE("=> %04x\n", ret);
return ret; return ret;
} }
@ -1581,7 +1569,16 @@ BOOL WINAPI mciFreeCommandResource(UINT uTable)
{ {
TRACE("(%08x)!\n", 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;
} }
/************************************************************************** /**************************************************************************

View File

@ -323,3 +323,22 @@ DWORD WINAPI mciSendString16(LPCSTR lpstrCommand, LPSTR lpstrRet,
{ {
return mciSendStringA(lpstrCommand, lpstrRet, uRetLen, HWND_32(hwndCallback)); 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;
}

View File

@ -2509,62 +2509,6 @@ MMRESULT16 WINAPI timeEndPeriod16(UINT16 wPeriod)
return timeEndPeriod(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 # * # JOYSTICK #
* ################################################### * ###################################################

View File

@ -197,8 +197,6 @@ void MMDRV_InstallMap(unsigned int, MMDRV_MAPFUNC, MMDRV_UNMAPFUNC,
const char* MCI_MessageToString(UINT wMsg); const char* MCI_MessageToString(UINT wMsg);
DWORD MCI_SendCommand(UINT wDevID, UINT16 wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2); 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); LPWSTR MCI_strdupAtoW(LPCSTR str);
LPSTR MCI_strdupWtoA(LPCWSTR str); LPSTR MCI_strdupWtoA(LPCWSTR str);