2000-12-13 03:07:40 +01:00
|
|
|
/*
|
|
|
|
* WINE Drivers functions
|
|
|
|
*
|
|
|
|
* Copyright 1994 Martin Ayotte
|
|
|
|
* Copyright 1998 Marcus Meissner
|
|
|
|
* Copyright 1999 Eric Pouech
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-12-13 03:07:40 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2003-09-15 22:13:30 +02:00
|
|
|
#include <stdarg.h>
|
2000-12-13 03:07:40 +01:00
|
|
|
#include "windef.h"
|
2003-09-15 22:13:30 +02:00
|
|
|
#include "winbase.h"
|
2002-10-29 22:51:24 +01:00
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2003-09-15 22:13:30 +02:00
|
|
|
#include "winnls.h"
|
2004-06-30 20:12:20 +02:00
|
|
|
#include "winreg.h"
|
2000-12-13 03:07:40 +01:00
|
|
|
#include "mmddk.h"
|
|
|
|
#include "winemm.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2005-07-15 11:56:17 +02:00
|
|
|
#include "excpt.h"
|
|
|
|
#include "wine/exception.h"
|
2000-12-13 03:07:40 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(driver);
|
2000-12-13 03:07:40 +01:00
|
|
|
|
2006-02-14 12:22:57 +01:00
|
|
|
static CRITICAL_SECTION mmdriver_lock;
|
|
|
|
static CRITICAL_SECTION_DEBUG mmdriver_lock_debug =
|
|
|
|
{
|
|
|
|
0, 0, &mmdriver_lock,
|
|
|
|
{ &mmdriver_lock_debug.ProcessLocksList, &mmdriver_lock_debug.ProcessLocksList },
|
|
|
|
0, 0, { (DWORD_PTR)(__FILE__ ": mmdriver_lock") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION mmdriver_lock = { &mmdriver_lock_debug, -1, 0, 0, 0, 0 };
|
|
|
|
|
2002-10-29 22:51:24 +01:00
|
|
|
static LPWINE_DRIVER lpDrvItemList /* = NULL */;
|
2000-12-13 03:07:40 +01:00
|
|
|
|
2006-02-14 12:22:57 +01:00
|
|
|
static void DRIVER_Dump(const char *comment)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
LPWINE_DRIVER lpDrv;
|
|
|
|
|
|
|
|
TRACE("%s\n", comment);
|
|
|
|
|
|
|
|
EnterCriticalSection( &mmdriver_lock );
|
|
|
|
|
|
|
|
for (lpDrv = lpDrvItemList; lpDrv != NULL; lpDrv = lpDrv->lpNextItem)
|
|
|
|
{
|
2009-02-20 10:23:08 +01:00
|
|
|
TRACE("%p, magic %04lx, id %p, next %p\n", lpDrv, lpDrv->dwMagic, lpDrv->d.d32.dwDriverID, lpDrv->lpNextItem);
|
2006-02-14 12:22:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection( &mmdriver_lock );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-12-13 03:07:40 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* DRIVER_GetNumberOfModuleRefs [internal]
|
|
|
|
*
|
|
|
|
* Returns the number of open drivers which share the same module.
|
|
|
|
*/
|
2002-05-12 00:55:29 +02:00
|
|
|
static unsigned DRIVER_GetNumberOfModuleRefs(HMODULE hModule, WINE_DRIVER** found)
|
2000-12-13 03:07:40 +01:00
|
|
|
{
|
|
|
|
LPWINE_DRIVER lpDrv;
|
2002-05-12 00:55:29 +02:00
|
|
|
unsigned count = 0;
|
|
|
|
|
2006-02-14 12:22:57 +01:00
|
|
|
EnterCriticalSection( &mmdriver_lock );
|
|
|
|
|
2002-05-12 00:55:29 +02:00
|
|
|
if (found) *found = NULL;
|
2002-06-01 01:06:46 +02:00
|
|
|
for (lpDrv = lpDrvItemList; lpDrv; lpDrv = lpDrv->lpNextItem)
|
2002-05-12 00:55:29 +02:00
|
|
|
{
|
2009-10-22 22:11:15 +02:00
|
|
|
if (lpDrv->hModule == hModule)
|
2002-05-12 00:55:29 +02:00
|
|
|
{
|
|
|
|
if (found && !*found) *found = lpDrv;
|
2000-12-13 03:07:40 +01:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2006-02-14 12:22:57 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection( &mmdriver_lock );
|
2000-12-13 03:07:40 +01:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* DRIVER_FindFromHDrvr [internal]
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-12-13 03:07:40 +01:00
|
|
|
* From a hDrvr being 32 bits, returns the WINE internal structure.
|
|
|
|
*/
|
|
|
|
LPWINE_DRIVER DRIVER_FindFromHDrvr(HDRVR hDrvr)
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2005-09-08 20:59:52 +02:00
|
|
|
LPWINE_DRIVER d;
|
2000-12-13 03:07:40 +01:00
|
|
|
|
2005-07-15 11:56:17 +02:00
|
|
|
__TRY
|
|
|
|
{
|
2005-09-08 20:59:52 +02:00
|
|
|
d = (LPWINE_DRIVER)hDrvr;
|
2005-07-15 11:56:17 +02:00
|
|
|
if (d && d->dwMagic != WINE_DI_MAGIC) d = NULL;
|
|
|
|
}
|
2005-12-16 17:17:57 +01:00
|
|
|
__EXCEPT_PAGE_FAULT
|
2005-07-15 11:56:17 +02:00
|
|
|
{
|
|
|
|
return NULL;
|
2000-12-13 03:07:40 +01:00
|
|
|
}
|
2005-07-15 11:56:17 +02:00
|
|
|
__ENDTRY;
|
|
|
|
|
2009-10-22 22:11:15 +02:00
|
|
|
if (d) TRACE("%p -> %p, %p\n", hDrvr, d->lpDrvProc, (void *)d->dwDriverID);
|
2006-02-14 12:22:57 +01:00
|
|
|
else TRACE("%p -> NULL\n", hDrvr);
|
|
|
|
|
2005-07-15 11:56:17 +02:00
|
|
|
return d;
|
2000-12-13 03:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* DRIVER_SendMessage [internal]
|
|
|
|
*/
|
2007-03-23 16:10:05 +01:00
|
|
|
static inline LRESULT DRIVER_SendMessage(LPWINE_DRIVER lpDrv, UINT msg,
|
2002-10-29 22:51:24 +01:00
|
|
|
LPARAM lParam1, LPARAM lParam2)
|
2000-12-13 03:07:40 +01:00
|
|
|
{
|
2011-04-11 14:57:30 +02:00
|
|
|
LRESULT ret;
|
2002-10-29 22:51:24 +01:00
|
|
|
|
2022-02-22 15:15:19 +01:00
|
|
|
TRACE("Before call32 proc=%p drvrID=%08Ix hDrv=%p wMsg=%04x p1=%08Ix p2=%08Ix\n",
|
2009-10-22 22:11:15 +02:00
|
|
|
lpDrv->lpDrvProc, lpDrv->dwDriverID, lpDrv, msg, lParam1, lParam2);
|
|
|
|
ret = lpDrv->lpDrvProc(lpDrv->dwDriverID, (HDRVR)lpDrv, msg, lParam1, lParam2);
|
2022-02-22 15:15:19 +01:00
|
|
|
TRACE("After call32 proc=%p drvrID=%08Ix hDrv=%p wMsg=%04x p1=%08Ix p2=%08Ix => %08Ix\n",
|
2009-10-22 22:11:15 +02:00
|
|
|
lpDrv->lpDrvProc, lpDrv->dwDriverID, lpDrv, msg, lParam1, lParam2, ret);
|
|
|
|
|
2002-10-29 22:51:24 +01:00
|
|
|
return ret;
|
2000-12-13 03:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* SendDriverMessage [WINMM.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* DrvSendMessage [WINMM.@]
|
2000-12-13 03:07:40 +01:00
|
|
|
*/
|
|
|
|
LRESULT WINAPI SendDriverMessage(HDRVR hDriver, UINT msg, LPARAM lParam1,
|
|
|
|
LPARAM lParam2)
|
|
|
|
{
|
|
|
|
LPWINE_DRIVER lpDrv;
|
|
|
|
LRESULT retval = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2022-02-22 15:15:19 +01:00
|
|
|
TRACE("(%p, %04X, %08IX, %08IX)\n", hDriver, msg, lParam1, lParam2);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-12-13 03:07:40 +01:00
|
|
|
if ((lpDrv = DRIVER_FindFromHDrvr(hDriver)) != NULL) {
|
|
|
|
retval = DRIVER_SendMessage(lpDrv, msg, lParam1, lParam2);
|
|
|
|
} else {
|
2002-10-31 02:02:41 +01:00
|
|
|
WARN("Bad driver handle %p\n", hDriver);
|
2000-12-13 03:07:40 +01:00
|
|
|
}
|
2022-02-22 15:15:19 +01:00
|
|
|
TRACE("retval = %Id\n", retval);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-12-13 03:07:40 +01:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* DRIVER_RemoveFromList [internal]
|
|
|
|
*
|
|
|
|
* Generates all the logic to handle driver closure / deletion
|
|
|
|
* Removes a driver struct to the list of open drivers.
|
|
|
|
*/
|
|
|
|
static BOOL DRIVER_RemoveFromList(LPWINE_DRIVER lpDrv)
|
|
|
|
{
|
2009-10-22 22:11:15 +02:00
|
|
|
/* last of this driver in list ? */
|
|
|
|
if (DRIVER_GetNumberOfModuleRefs(lpDrv->hModule, NULL) == 1) {
|
|
|
|
DRIVER_SendMessage(lpDrv, DRV_DISABLE, 0L, 0L);
|
|
|
|
DRIVER_SendMessage(lpDrv, DRV_FREE, 0L, 0L);
|
2000-12-13 03:07:40 +01:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-02-14 12:22:57 +01:00
|
|
|
EnterCriticalSection( &mmdriver_lock );
|
|
|
|
|
2000-12-13 03:07:40 +01:00
|
|
|
if (lpDrv->lpPrevItem)
|
|
|
|
lpDrv->lpPrevItem->lpNextItem = lpDrv->lpNextItem;
|
|
|
|
else
|
|
|
|
lpDrvItemList = lpDrv->lpNextItem;
|
|
|
|
if (lpDrv->lpNextItem)
|
|
|
|
lpDrv->lpNextItem->lpPrevItem = lpDrv->lpPrevItem;
|
2002-05-12 00:55:29 +02:00
|
|
|
/* trash magic number */
|
|
|
|
lpDrv->dwMagic ^= 0xa5a5a5a5;
|
2009-10-22 22:11:15 +02:00
|
|
|
lpDrv->lpDrvProc = NULL;
|
|
|
|
lpDrv->dwDriverID = 0;
|
2006-02-14 12:22:57 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection( &mmdriver_lock );
|
2000-12-13 03:07:40 +01:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* DRIVER_AddToList [internal]
|
|
|
|
*
|
|
|
|
* Adds a driver struct to the list of open drivers.
|
|
|
|
* Generates all the logic to handle driver creation / open.
|
|
|
|
*/
|
|
|
|
static BOOL DRIVER_AddToList(LPWINE_DRIVER lpNewDrv, LPARAM lParam1, LPARAM lParam2)
|
|
|
|
{
|
|
|
|
lpNewDrv->dwMagic = WINE_DI_MAGIC;
|
|
|
|
/* First driver to be loaded for this module, need to load correctly the module */
|
2009-10-22 22:11:15 +02:00
|
|
|
/* first of this driver in list ? */
|
|
|
|
if (DRIVER_GetNumberOfModuleRefs(lpNewDrv->hModule, NULL) == 0) {
|
|
|
|
if (DRIVER_SendMessage(lpNewDrv, DRV_LOAD, 0L, 0L) != DRV_SUCCESS) {
|
|
|
|
TRACE("DRV_LOAD failed on driver %p\n", lpNewDrv);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
/* returned value is not checked */
|
|
|
|
DRIVER_SendMessage(lpNewDrv, DRV_ENABLE, 0L, 0L);
|
|
|
|
}
|
2006-02-14 12:22:57 +01:00
|
|
|
|
2009-10-22 22:11:15 +02:00
|
|
|
/* Now just open a new instance of a driver on this module */
|
|
|
|
lpNewDrv->dwDriverID = DRIVER_SendMessage(lpNewDrv, DRV_OPEN, lParam1, lParam2);
|
2006-02-14 12:22:57 +01:00
|
|
|
|
2009-10-22 22:11:15 +02:00
|
|
|
if (lpNewDrv->dwDriverID == 0)
|
|
|
|
{
|
|
|
|
TRACE("DRV_OPEN failed on driver %p\n", lpNewDrv);
|
|
|
|
return FALSE;
|
2000-12-13 03:07:40 +01:00
|
|
|
}
|
|
|
|
|
2006-02-14 12:22:57 +01:00
|
|
|
EnterCriticalSection( &mmdriver_lock );
|
|
|
|
|
2000-12-13 03:07:40 +01:00
|
|
|
lpNewDrv->lpNextItem = NULL;
|
|
|
|
if (lpDrvItemList == NULL) {
|
|
|
|
lpDrvItemList = lpNewDrv;
|
|
|
|
lpNewDrv->lpPrevItem = NULL;
|
|
|
|
} else {
|
|
|
|
LPWINE_DRIVER lpDrv = lpDrvItemList; /* find end of list */
|
|
|
|
while (lpDrv->lpNextItem != NULL)
|
|
|
|
lpDrv = lpDrv->lpNextItem;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-12-13 03:07:40 +01:00
|
|
|
lpDrv->lpNextItem = lpNewDrv;
|
|
|
|
lpNewDrv->lpPrevItem = lpDrv;
|
|
|
|
}
|
|
|
|
|
2006-02-14 12:22:57 +01:00
|
|
|
LeaveCriticalSection( &mmdriver_lock );
|
2000-12-13 03:07:40 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* DRIVER_GetLibName [internal]
|
|
|
|
*
|
|
|
|
*/
|
2005-02-09 23:26:25 +01:00
|
|
|
BOOL DRIVER_GetLibName(LPCWSTR keyName, LPCWSTR sectName, LPWSTR buf, int sz)
|
2000-12-13 03:07:40 +01:00
|
|
|
{
|
2004-06-30 20:12:20 +02:00
|
|
|
HKEY hKey, hSecKey;
|
|
|
|
DWORD bufLen, lRet;
|
|
|
|
|
2006-02-14 12:22:57 +01:00
|
|
|
TRACE("registry: %s, %s, %p, %d\n", debugstr_w(keyName), debugstr_w(sectName), buf, sz);
|
|
|
|
|
2020-11-18 00:06:38 +01:00
|
|
|
lRet = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Windows NT\\CurrentVersion",
|
|
|
|
0, KEY_QUERY_VALUE, &hKey);
|
2004-06-30 20:12:20 +02:00
|
|
|
if (lRet == ERROR_SUCCESS) {
|
2005-02-09 23:26:25 +01:00
|
|
|
lRet = RegOpenKeyExW(hKey, sectName, 0, KEY_QUERY_VALUE, &hSecKey);
|
2004-06-30 20:12:20 +02:00
|
|
|
if (lRet == ERROR_SUCCESS) {
|
2005-02-09 23:26:25 +01:00
|
|
|
bufLen = sz;
|
|
|
|
lRet = RegQueryValueExW(hSecKey, keyName, 0, 0, (void*)buf, &bufLen);
|
2004-06-30 20:12:20 +02:00
|
|
|
RegCloseKey( hSecKey );
|
|
|
|
}
|
|
|
|
RegCloseKey( hKey );
|
|
|
|
}
|
|
|
|
if (lRet == ERROR_SUCCESS) return TRUE;
|
2006-02-14 12:22:57 +01:00
|
|
|
|
2004-06-30 20:12:20 +02:00
|
|
|
/* default to system.ini if we can't find it in the registry,
|
|
|
|
* to support native installations where system.ini is still used */
|
2006-02-14 12:22:57 +01:00
|
|
|
TRACE("system.ini: %s, %s, %p, %d\n", debugstr_w(keyName), debugstr_w(sectName), buf, sz);
|
2020-11-18 00:06:38 +01:00
|
|
|
return GetPrivateProfileStringW(sectName, keyName, L"", buf, sz / sizeof(WCHAR), L"SYSTEM.INI");
|
2000-12-13 03:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* DRIVER_TryOpenDriver32 [internal]
|
|
|
|
*
|
|
|
|
* Tries to load a 32 bit driver whose DLL's (module) name is fn
|
|
|
|
*/
|
2005-02-09 23:26:25 +01:00
|
|
|
LPWINE_DRIVER DRIVER_TryOpenDriver32(LPCWSTR fn, LPARAM lParam2)
|
2000-12-13 03:07:40 +01:00
|
|
|
{
|
|
|
|
LPWINE_DRIVER lpDrv = NULL;
|
|
|
|
HMODULE hModule = 0;
|
2005-02-09 23:26:25 +01:00
|
|
|
LPWSTR ptr;
|
2000-12-13 03:07:40 +01:00
|
|
|
LPCSTR cause = 0;
|
|
|
|
|
2022-02-22 15:15:19 +01:00
|
|
|
TRACE("(%s, %08IX);\n", debugstr_w(fn), lParam2);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2019-07-02 20:00:47 +02:00
|
|
|
if ((ptr = wcschr(fn, ' ')) != NULL) {
|
2000-12-13 03:07:40 +01:00
|
|
|
*ptr++ = '\0';
|
|
|
|
while (*ptr == ' ') ptr++;
|
|
|
|
if (*ptr == '\0') ptr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpDrv = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_DRIVER));
|
|
|
|
if (lpDrv == NULL) {cause = "OOM"; goto exit;}
|
|
|
|
|
2005-02-09 23:26:25 +01:00
|
|
|
if ((hModule = LoadLibraryW(fn)) == 0) {cause = "Not a 32 bit lib"; goto exit;}
|
2000-12-13 03:07:40 +01:00
|
|
|
|
2009-10-22 22:11:15 +02:00
|
|
|
lpDrv->lpDrvProc = (DRIVERPROC)GetProcAddress(hModule, "DriverProc");
|
|
|
|
if (lpDrv->lpDrvProc == NULL) {cause = "no DriverProc"; goto exit;}
|
2000-12-13 03:07:40 +01:00
|
|
|
|
2009-10-22 22:11:15 +02:00
|
|
|
lpDrv->dwFlags = 0;
|
|
|
|
lpDrv->hModule = hModule;
|
|
|
|
lpDrv->dwDriverID = 0;
|
2000-12-13 03:07:40 +01:00
|
|
|
|
2002-05-12 00:55:29 +02:00
|
|
|
/* Win32 installable drivers must support a two phase opening scheme:
|
2002-06-01 01:06:46 +02:00
|
|
|
* + first open with NULL as lParam2 (session instance),
|
2002-05-12 00:55:29 +02:00
|
|
|
* + then do a second open with the real non null lParam2)
|
|
|
|
*/
|
2009-10-22 22:11:15 +02:00
|
|
|
if (DRIVER_GetNumberOfModuleRefs(lpDrv->hModule, NULL) == 0 && lParam2)
|
2002-05-12 00:55:29 +02:00
|
|
|
{
|
|
|
|
LPWINE_DRIVER ret;
|
|
|
|
|
|
|
|
if (!DRIVER_AddToList(lpDrv, (LPARAM)ptr, 0L))
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
cause = "load0 failed";
|
2002-05-12 00:55:29 +02:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
ret = DRIVER_TryOpenDriver32(fn, lParam2);
|
2002-06-01 01:06:46 +02:00
|
|
|
if (!ret)
|
2002-05-12 00:55:29 +02:00
|
|
|
{
|
|
|
|
CloseDriver((HDRVR)lpDrv, 0L, 0L);
|
2002-06-01 01:06:46 +02:00
|
|
|
cause = "load1 failed";
|
2002-05-12 00:55:29 +02:00
|
|
|
goto exit;
|
|
|
|
}
|
2005-12-05 12:01:26 +01:00
|
|
|
lpDrv->dwFlags |= WINE_GDF_SESSION;
|
2002-05-12 00:55:29 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if (!DRIVER_AddToList(lpDrv, (LPARAM)ptr, lParam2))
|
2002-05-12 00:55:29 +02:00
|
|
|
{cause = "load failed"; goto exit;}
|
2000-12-13 03:07:40 +01:00
|
|
|
|
|
|
|
TRACE("=> %p\n", lpDrv);
|
|
|
|
return lpDrv;
|
|
|
|
exit:
|
|
|
|
FreeLibrary(hModule);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpDrv);
|
2005-02-09 23:26:25 +01:00
|
|
|
TRACE("Unable to load 32 bit module %s: %s\n", debugstr_w(fn), cause);
|
2000-12-13 03:07:40 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* OpenDriverA [WINMM.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* DrvOpenA [WINMM.@]
|
2000-12-13 03:07:40 +01:00
|
|
|
* (0,1,DRV_LOAD ,0 ,0)
|
|
|
|
* (0,1,DRV_ENABLE,0 ,0)
|
|
|
|
* (0,1,DRV_OPEN ,buf[256],0)
|
|
|
|
*/
|
2005-02-09 23:26:25 +01:00
|
|
|
HDRVR WINAPI OpenDriverA(LPCSTR lpDriverName, LPCSTR lpSectionName, LPARAM lParam)
|
|
|
|
{
|
|
|
|
INT len;
|
|
|
|
LPWSTR dn = NULL;
|
|
|
|
LPWSTR sn = NULL;
|
2005-03-11 13:50:27 +01:00
|
|
|
HDRVR ret = 0;
|
2005-02-09 23:26:25 +01:00
|
|
|
|
|
|
|
if (lpDriverName)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, NULL, 0 );
|
|
|
|
dn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
2005-03-11 13:50:27 +01:00
|
|
|
if (!dn) goto done;
|
2005-02-09 23:26:25 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpDriverName, -1, dn, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpSectionName)
|
|
|
|
{
|
|
|
|
len = MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, NULL, 0 );
|
|
|
|
sn = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
|
2005-03-11 13:50:27 +01:00
|
|
|
if (!sn) goto done;
|
2005-02-09 23:26:25 +01:00
|
|
|
MultiByteToWideChar( CP_ACP, 0, lpSectionName, -1, sn, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = OpenDriver(dn, sn, lParam);
|
|
|
|
|
2005-03-11 13:50:27 +01:00
|
|
|
done:
|
|
|
|
HeapFree(GetProcessHeap(), 0, dn);
|
|
|
|
HeapFree(GetProcessHeap(), 0, sn);
|
2005-02-09 23:26:25 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* OpenDriver [WINMM.@]
|
|
|
|
* DrvOpen [WINMM.@]
|
|
|
|
*/
|
|
|
|
HDRVR WINAPI OpenDriver(LPCWSTR lpDriverName, LPCWSTR lpSectionName, LPARAM lParam)
|
2000-12-13 03:07:40 +01:00
|
|
|
{
|
|
|
|
LPWINE_DRIVER lpDrv = NULL;
|
2006-02-14 12:22:57 +01:00
|
|
|
WCHAR libName[MAX_PATH + 1];
|
2005-02-09 23:26:25 +01:00
|
|
|
LPCWSTR lsn = lpSectionName;
|
2000-12-13 03:07:40 +01:00
|
|
|
|
2022-02-22 15:15:19 +01:00
|
|
|
TRACE("(%s, %s, 0x%08Ix);\n",
|
2005-02-09 23:26:25 +01:00
|
|
|
debugstr_w(lpDriverName), debugstr_w(lpSectionName), lParam);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-02-14 12:22:57 +01:00
|
|
|
DRIVER_Dump("BEFORE:");
|
|
|
|
|
2000-12-13 03:07:40 +01:00
|
|
|
if (lsn == NULL) {
|
2018-09-19 21:01:11 +02:00
|
|
|
lstrcpynW(libName, lpDriverName, ARRAY_SIZE(libName));
|
2000-12-13 03:07:40 +01:00
|
|
|
|
2005-02-09 23:26:25 +01:00
|
|
|
if ((lpDrv = DRIVER_TryOpenDriver32(libName, lParam)))
|
2000-12-13 03:07:40 +01:00
|
|
|
goto the_end;
|
2020-11-18 00:06:38 +01:00
|
|
|
lsn = L"Drivers32";
|
2000-12-13 03:07:40 +01:00
|
|
|
}
|
|
|
|
if (DRIVER_GetLibName(lpDriverName, lsn, libName, sizeof(libName)) &&
|
2005-02-09 23:26:25 +01:00
|
|
|
(lpDrv = DRIVER_TryOpenDriver32(libName, lParam)))
|
2000-12-13 03:07:40 +01:00
|
|
|
goto the_end;
|
|
|
|
|
2005-02-09 23:26:25 +01:00
|
|
|
TRACE("Failed to open driver %s from system.ini file, section %s\n",
|
|
|
|
debugstr_w(lpDriverName), debugstr_w(lpSectionName));
|
2002-10-29 22:51:24 +01:00
|
|
|
|
2006-02-14 12:22:57 +01:00
|
|
|
the_end:
|
|
|
|
TRACE("=> %p\n", lpDrv);
|
|
|
|
|
|
|
|
DRIVER_Dump("AFTER:");
|
|
|
|
|
2002-08-09 03:02:25 +02:00
|
|
|
return (HDRVR)lpDrv;
|
2000-12-13 03:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* CloseDriver [WINMM.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* DrvClose [WINMM.@]
|
2000-12-13 03:07:40 +01:00
|
|
|
*/
|
|
|
|
LRESULT WINAPI CloseDriver(HDRVR hDrvr, LPARAM lParam1, LPARAM lParam2)
|
|
|
|
{
|
2006-02-14 12:22:57 +01:00
|
|
|
BOOL ret;
|
2000-12-13 03:07:40 +01:00
|
|
|
LPWINE_DRIVER lpDrv;
|
|
|
|
|
2022-02-22 15:15:19 +01:00
|
|
|
TRACE("(%p, %08IX, %08IX);\n", hDrvr, lParam1, lParam2);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2006-02-14 12:22:57 +01:00
|
|
|
DRIVER_Dump("BEFORE:");
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL)
|
2002-05-12 00:55:29 +02:00
|
|
|
{
|
2009-10-22 22:11:15 +02:00
|
|
|
LPWINE_DRIVER lpDrv0;
|
|
|
|
|
|
|
|
DRIVER_SendMessage(lpDrv, DRV_CLOSE, lParam1, lParam2);
|
2006-02-14 12:22:57 +01:00
|
|
|
|
|
|
|
DRIVER_RemoveFromList(lpDrv);
|
|
|
|
|
2009-10-22 22:11:15 +02:00
|
|
|
if (lpDrv->dwFlags & WINE_GDF_SESSION)
|
|
|
|
FIXME("WINE_GDF_SESSION: Shouldn't happen (%p)\n", lpDrv);
|
|
|
|
/* if driver has an opened session instance, we have to close it too */
|
|
|
|
if (DRIVER_GetNumberOfModuleRefs(lpDrv->hModule, &lpDrv0) == 1 &&
|
|
|
|
(lpDrv0->dwFlags & WINE_GDF_SESSION))
|
2006-02-14 12:22:57 +01:00
|
|
|
{
|
2009-10-22 22:11:15 +02:00
|
|
|
DRIVER_SendMessage(lpDrv0, DRV_CLOSE, 0, 0);
|
|
|
|
DRIVER_RemoveFromList(lpDrv0);
|
|
|
|
FreeLibrary(lpDrv0->hModule);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpDrv0);
|
2002-05-12 00:55:29 +02:00
|
|
|
}
|
2009-10-22 22:11:15 +02:00
|
|
|
FreeLibrary(lpDrv->hModule);
|
|
|
|
|
2006-02-14 12:22:57 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpDrv);
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WARN("Failed to close driver\n");
|
|
|
|
ret = FALSE;
|
2000-12-13 03:07:40 +01:00
|
|
|
}
|
2006-02-14 12:22:57 +01:00
|
|
|
|
|
|
|
DRIVER_Dump("AFTER:");
|
|
|
|
|
|
|
|
return ret;
|
2000-12-13 03:07:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* GetDriverFlags [WINMM.@]
|
2000-12-13 03:07:40 +01:00
|
|
|
* [in] hDrvr handle to the driver
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0x00000000 if hDrvr is an invalid handle
|
|
|
|
* 0x80000000 if hDrvr is a valid 32 bit driver
|
|
|
|
* 0x90000000 if hDrvr is a valid 16 bit driver
|
|
|
|
*
|
|
|
|
* native WINMM doesn't return those flags
|
|
|
|
* 0x80000000 for a valid 32 bit driver and that's it
|
|
|
|
* (I may have mixed up the two flags :-(
|
|
|
|
*/
|
|
|
|
DWORD WINAPI GetDriverFlags(HDRVR hDrvr)
|
|
|
|
{
|
|
|
|
LPWINE_DRIVER lpDrv;
|
|
|
|
DWORD ret = 0;
|
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p)\n", hDrvr);
|
2000-12-13 03:07:40 +01:00
|
|
|
|
|
|
|
if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
|
2005-12-05 12:01:26 +01:00
|
|
|
ret = WINE_GDF_EXIST | (lpDrv->dwFlags & WINE_GDF_EXTERNAL_MASK);
|
2000-12-13 03:07:40 +01:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* GetDriverModuleHandle [WINMM.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* DrvGetModuleHandle [WINMM.@]
|
2000-12-13 03:07:40 +01:00
|
|
|
*/
|
|
|
|
HMODULE WINAPI GetDriverModuleHandle(HDRVR hDrvr)
|
|
|
|
{
|
|
|
|
LPWINE_DRIVER lpDrv;
|
|
|
|
HMODULE hModule = 0;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("(%p);\n", hDrvr);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-12-13 03:07:40 +01:00
|
|
|
if ((lpDrv = DRIVER_FindFromHDrvr(hDrvr)) != NULL) {
|
2009-10-22 22:11:15 +02:00
|
|
|
hModule = lpDrv->hModule;
|
2000-12-13 03:07:40 +01:00
|
|
|
}
|
2002-10-31 02:02:41 +01:00
|
|
|
TRACE("=> %p\n", hModule);
|
2000-12-13 03:07:40 +01:00
|
|
|
return hModule;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* DefDriverProc [WINMM.@]
|
2001-07-11 20:56:41 +02:00
|
|
|
* DrvDefDriverProc [WINMM.@]
|
2000-12-13 03:07:40 +01:00
|
|
|
*/
|
2004-10-20 01:55:15 +02:00
|
|
|
LRESULT WINAPI DefDriverProc(DWORD_PTR dwDriverIdentifier, HDRVR hDrv,
|
2000-12-13 03:07:40 +01:00
|
|
|
UINT Msg, LPARAM lParam1, LPARAM lParam2)
|
|
|
|
{
|
|
|
|
switch (Msg) {
|
|
|
|
case DRV_LOAD:
|
|
|
|
case DRV_FREE:
|
|
|
|
case DRV_ENABLE:
|
|
|
|
case DRV_DISABLE:
|
|
|
|
return 1;
|
|
|
|
case DRV_INSTALL:
|
|
|
|
case DRV_REMOVE:
|
|
|
|
return DRV_SUCCESS;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2002-10-29 22:51:24 +01:00
|
|
|
|
2011-03-29 20:51:15 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* DRIVER_getCallback [internal]
|
|
|
|
*/
|
|
|
|
static const char* DRIVER_getCallback(DWORD uFlags)
|
|
|
|
{
|
|
|
|
switch(uFlags & DCB_TYPEMASK) {
|
|
|
|
case DCB_NULL: return "null";
|
|
|
|
case DCB_WINDOW: return "window";
|
|
|
|
case DCB_TASK: return "task";
|
|
|
|
case DCB_EVENT: return "event";
|
|
|
|
case DCB_FUNCTION: return "32bit function";
|
|
|
|
default: return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-29 22:51:24 +01:00
|
|
|
/**************************************************************************
|
|
|
|
* DriverCallback [WINMM.@]
|
|
|
|
*/
|
2007-05-31 16:01:53 +02:00
|
|
|
BOOL WINAPI DriverCallback(DWORD_PTR dwCallBack, DWORD uFlags, HDRVR hDev,
|
|
|
|
DWORD wMsg, DWORD_PTR dwUser, DWORD_PTR dwParam1,
|
|
|
|
DWORD_PTR dwParam2)
|
2002-10-29 22:51:24 +01:00
|
|
|
{
|
2011-04-11 14:57:30 +02:00
|
|
|
BOOL ret = FALSE;
|
2022-02-22 15:15:19 +01:00
|
|
|
TRACE("(%08IX, %s %04lX, %p, %04lX, %08IX, %08IX, %08IX)\n",
|
2011-03-29 20:51:15 +02:00
|
|
|
dwCallBack, DRIVER_getCallback(uFlags), uFlags, hDev, wMsg, dwUser, dwParam1, dwParam2);
|
2011-04-11 14:57:30 +02:00
|
|
|
if (!dwCallBack)
|
|
|
|
return ret;
|
2002-10-29 22:51:24 +01:00
|
|
|
|
|
|
|
switch (uFlags & DCB_TYPEMASK) {
|
|
|
|
case DCB_NULL:
|
2011-04-11 14:57:30 +02:00
|
|
|
/* Native returns FALSE = no notification, not TRUE */
|
|
|
|
return ret;
|
2002-10-29 22:51:24 +01:00
|
|
|
case DCB_WINDOW:
|
2011-04-11 14:57:30 +02:00
|
|
|
ret = PostMessageA((HWND)dwCallBack, wMsg, (WPARAM)hDev, dwParam1);
|
2002-10-29 22:51:24 +01:00
|
|
|
break;
|
|
|
|
case DCB_TASK: /* aka DCB_THREAD */
|
2011-04-11 14:57:30 +02:00
|
|
|
ret = PostThreadMessageA(dwCallBack, wMsg, (WPARAM)hDev, dwParam1);
|
2002-10-29 22:51:24 +01:00
|
|
|
break;
|
|
|
|
case DCB_FUNCTION:
|
2011-04-11 14:57:30 +02:00
|
|
|
((LPDRVCALLBACK)dwCallBack)(hDev, wMsg, dwUser, dwParam1, dwParam2);
|
|
|
|
ret = TRUE;
|
2002-10-29 22:51:24 +01:00
|
|
|
break;
|
|
|
|
case DCB_EVENT:
|
2011-04-11 14:57:30 +02:00
|
|
|
ret = SetEvent((HANDLE)dwCallBack);
|
2002-10-29 22:51:24 +01:00
|
|
|
break;
|
2009-10-22 22:10:47 +02:00
|
|
|
#if 0
|
|
|
|
/* FIXME: for now only usable in mmsystem.dll16
|
|
|
|
* If needed, should be enabled back
|
|
|
|
*/
|
2002-10-29 22:51:24 +01:00
|
|
|
case 6: /* I would dub it DCB_MMTHREADSIGNAL */
|
|
|
|
/* this is an undocumented DCB_ value used for mmThreads
|
|
|
|
* loword of dwCallBack contains the handle of the lpMMThd block
|
|
|
|
* which dwSignalCount has to be incremented
|
|
|
|
*/
|
|
|
|
if (pFnGetMMThread16)
|
|
|
|
{
|
|
|
|
WINE_MMTHREAD* lpMMThd = pFnGetMMThread16(LOWORD(dwCallBack));
|
|
|
|
|
|
|
|
TRACE("mmThread (%04x, %p) !\n", LOWORD(dwCallBack), lpMMThd);
|
|
|
|
/* same as mmThreadSignal16 */
|
|
|
|
InterlockedIncrement(&lpMMThd->dwSignalCount);
|
|
|
|
SetEvent(lpMMThd->hEvent);
|
|
|
|
/* some other stuff on lpMMThd->hVxD */
|
|
|
|
}
|
|
|
|
break;
|
2009-10-22 22:10:47 +02:00
|
|
|
#endif
|
2002-10-29 22:51:24 +01:00
|
|
|
#if 0
|
|
|
|
case 4:
|
|
|
|
/* this is an undocumented DCB_ value for... I don't know */
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2022-02-22 15:15:19 +01:00
|
|
|
WARN("Unknown callback type %ld\n", uFlags & DCB_TYPEMASK);
|
2002-10-29 22:51:24 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-04-11 14:57:30 +02:00
|
|
|
if (ret)
|
|
|
|
TRACE("Done\n");
|
|
|
|
else
|
|
|
|
WARN("Notification failure\n");
|
|
|
|
return ret;
|
2002-10-29 22:51:24 +01:00
|
|
|
}
|
2002-11-11 20:53:01 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* DRIVER_UnloadAll
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void DRIVER_UnloadAll(void)
|
|
|
|
{
|
|
|
|
LPWINE_DRIVER lpDrv;
|
|
|
|
LPWINE_DRIVER lpNextDrv = NULL;
|
|
|
|
unsigned count = 0;
|
|
|
|
|
2006-02-14 12:22:57 +01:00
|
|
|
restart:
|
|
|
|
EnterCriticalSection( &mmdriver_lock );
|
|
|
|
|
2002-11-11 20:53:01 +01:00
|
|
|
for (lpDrv = lpDrvItemList; lpDrv != NULL; lpDrv = lpNextDrv)
|
|
|
|
{
|
|
|
|
lpNextDrv = lpDrv->lpNextItem;
|
2006-02-14 12:22:57 +01:00
|
|
|
|
|
|
|
/* session instances will be unloaded automatically */
|
|
|
|
if (!(lpDrv->dwFlags & WINE_GDF_SESSION))
|
|
|
|
{
|
|
|
|
LeaveCriticalSection( &mmdriver_lock );
|
|
|
|
CloseDriver((HDRVR)lpDrv, 0, 0);
|
|
|
|
count++;
|
|
|
|
/* restart from the beginning of the list */
|
|
|
|
goto restart;
|
|
|
|
}
|
2002-11-11 20:53:01 +01:00
|
|
|
}
|
2006-02-14 12:22:57 +01:00
|
|
|
|
|
|
|
LeaveCriticalSection( &mmdriver_lock );
|
|
|
|
|
2002-11-11 20:53:01 +01:00
|
|
|
TRACE("Unloaded %u drivers\n", count);
|
|
|
|
}
|