2002-07-22 22:32:53 +02:00
|
|
|
/*
|
|
|
|
* SHLWAPI thread and MT synchronisation functions
|
|
|
|
*
|
|
|
|
* Copyright 2002 Juergen Schmied
|
|
|
|
* Copyright 2002 Jon Griffiths
|
|
|
|
*
|
|
|
|
* 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
|
2002-07-22 22:32:53 +02:00
|
|
|
*/
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2002-07-22 22:32:53 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2004-10-07 05:06:48 +02:00
|
|
|
#define COBJMACROS
|
|
|
|
|
2002-07-22 22:32:53 +02:00
|
|
|
#include "windef.h"
|
2003-08-20 20:22:31 +02:00
|
|
|
#include "winbase.h"
|
2002-07-22 22:32:53 +02:00
|
|
|
#include "winnls.h"
|
2007-03-28 13:13:54 +02:00
|
|
|
#include "winuser.h"
|
2002-07-22 22:32:53 +02:00
|
|
|
#define NO_SHLWAPI_REG
|
|
|
|
#define NO_SHLWAPI_PATH
|
|
|
|
#define NO_SHLWAPI_GDI
|
|
|
|
#define NO_SHLWAPI_STREAM
|
|
|
|
#define NO_SHLWAPI_USER
|
|
|
|
#include "shlwapi.h"
|
2007-03-28 13:13:54 +02:00
|
|
|
#include "shlobj.h"
|
|
|
|
#include "wine/debug.h"
|
2002-07-22 22:32:53 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
|
|
|
|
2002-09-20 21:41:08 +02:00
|
|
|
extern DWORD SHLWAPI_ThreadRef_index; /* Initialised in shlwapi_main.c */
|
|
|
|
|
2007-04-14 14:48:21 +02:00
|
|
|
INT WINAPI SHStringFromGUIDA(REFGUID,LPSTR,INT);
|
2002-07-22 22:32:53 +02:00
|
|
|
|
|
|
|
/**************************************************************************
|
2007-10-26 11:31:55 +02:00
|
|
|
* CreateAllAccessSecurityAttributes [SHLWAPI.356]
|
2002-07-22 22:32:53 +02:00
|
|
|
*
|
|
|
|
* Initialise security attributes from a security descriptor.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpAttr [O] Security attributes
|
|
|
|
* lpSec [I] Security descriptor
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: lpAttr, initialised using lpSec.
|
|
|
|
* Failure: NULL, if any parameters are invalid.
|
|
|
|
*
|
|
|
|
* NOTES
|
2003-04-02 03:23:43 +02:00
|
|
|
* This function always returns NULL if the underlying OS version
|
2002-07-22 22:32:53 +02:00
|
|
|
* Wine is impersonating does not use security descriptors (i.e. anything
|
|
|
|
* before Windows NT).
|
|
|
|
*/
|
2007-10-26 11:31:55 +02:00
|
|
|
LPSECURITY_ATTRIBUTES WINAPI CreateAllAccessSecurityAttributes(
|
2003-01-15 01:53:39 +01:00
|
|
|
LPSECURITY_ATTRIBUTES lpAttr,
|
2005-08-09 22:34:57 +02:00
|
|
|
PSECURITY_DESCRIPTOR lpSec,
|
|
|
|
DWORD p3)
|
2002-07-22 22:32:53 +02:00
|
|
|
{
|
|
|
|
/* This function is used within SHLWAPI only to create security attributes
|
|
|
|
* for shell semaphores. */
|
|
|
|
|
2022-02-18 09:16:21 +01:00
|
|
|
TRACE("(%p,%p,%08lx)\n", lpAttr, lpSec, p3);
|
2002-07-22 22:32:53 +02:00
|
|
|
|
2002-08-20 01:56:15 +02:00
|
|
|
if (!(GetVersion() & 0x80000000)) /* NT */
|
2002-07-22 22:32:53 +02:00
|
|
|
{
|
|
|
|
if (!lpSec || !lpAttr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (InitializeSecurityDescriptor(lpSec, 1))
|
|
|
|
{
|
|
|
|
if (SetSecurityDescriptorDacl(lpSec, TRUE, NULL, FALSE))
|
|
|
|
{
|
|
|
|
lpAttr->nLength = sizeof(SECURITY_ATTRIBUTES);
|
|
|
|
lpAttr->lpSecurityDescriptor = lpSec;
|
|
|
|
lpAttr->bInheritHandle = FALSE;
|
|
|
|
return lpAttr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
* _SHGetInstanceExplorer [SHLWAPI.@]
|
|
|
|
*
|
|
|
|
* Get an interface to the shell explorer.
|
|
|
|
*
|
|
|
|
* PARAMS
|
2003-07-19 00:55:39 +02:00
|
|
|
* lppUnknown [O] Destination for explorers IUnknown interface.
|
2002-07-22 22:32:53 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Success: S_OK. lppUnknown contains the explorer interface.
|
|
|
|
* Failure: An HRESULT error code.
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI _SHGetInstanceExplorer(IUnknown **lppUnknown)
|
|
|
|
{
|
|
|
|
/* This function is used within SHLWAPI only to hold the IE reference
|
|
|
|
* for threads created with the CTF_PROCESS_REF flag set. */
|
2007-03-28 13:13:54 +02:00
|
|
|
return SHGetInstanceExplorer(lppUnknown);
|
2002-07-22 22:32:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2007-10-26 11:31:55 +02:00
|
|
|
* SHGlobalCounterGetValue [SHLWAPI.223]
|
2002-07-22 22:32:53 +02:00
|
|
|
*
|
|
|
|
* Get the current count of a semaphore.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hSem [I] Semaphore handle
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The current count of the semaphore.
|
|
|
|
*/
|
2007-10-26 11:31:55 +02:00
|
|
|
LONG WINAPI SHGlobalCounterGetValue(HANDLE hSem)
|
2002-07-22 22:32:53 +02:00
|
|
|
{
|
2003-07-19 00:55:39 +02:00
|
|
|
LONG dwOldCount = 0;
|
2002-07-22 22:32:53 +02:00
|
|
|
|
2002-10-25 05:12:32 +02:00
|
|
|
TRACE("(%p)\n", hSem);
|
2002-07-22 22:32:53 +02:00
|
|
|
ReleaseSemaphore(hSem, 1, &dwOldCount); /* +1 */
|
|
|
|
WaitForSingleObject(hSem, 0); /* -1 */
|
|
|
|
return dwOldCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2007-10-26 11:31:55 +02:00
|
|
|
* SHGlobalCounterIncrement [SHLWAPI.224]
|
2002-07-22 22:32:53 +02:00
|
|
|
*
|
|
|
|
* Claim a semaphore.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hSem [I] Semaphore handle
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The new count of the semaphore.
|
|
|
|
*/
|
2007-10-26 11:31:55 +02:00
|
|
|
LONG WINAPI SHGlobalCounterIncrement(HANDLE hSem)
|
2002-07-22 22:32:53 +02:00
|
|
|
{
|
2003-07-19 00:55:39 +02:00
|
|
|
LONG dwOldCount = 0;
|
2002-07-22 22:32:53 +02:00
|
|
|
|
2002-10-25 05:12:32 +02:00
|
|
|
TRACE("(%p)\n", hSem);
|
2002-07-22 22:32:53 +02:00
|
|
|
ReleaseSemaphore(hSem, 1, &dwOldCount);
|
|
|
|
return dwOldCount + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2007-10-26 11:31:55 +02:00
|
|
|
* SHGlobalCounterDecrement [SHLWAPI.424]
|
2002-07-22 22:32:53 +02:00
|
|
|
*
|
|
|
|
* Release a semaphore.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* hSem [I] Semaphore handle
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* The new count of the semaphore.
|
|
|
|
*/
|
2007-10-26 11:31:55 +02:00
|
|
|
DWORD WINAPI SHGlobalCounterDecrement(HANDLE hSem)
|
2002-07-22 22:32:53 +02:00
|
|
|
{
|
|
|
|
DWORD dwOldCount = 0;
|
|
|
|
|
2002-10-25 05:12:32 +02:00
|
|
|
TRACE("(%p)\n", hSem);
|
2002-07-22 22:32:53 +02:00
|
|
|
|
2007-10-26 11:31:55 +02:00
|
|
|
dwOldCount = SHGlobalCounterGetValue(hSem);
|
2002-07-22 22:32:53 +02:00
|
|
|
WaitForSingleObject(hSem, 0);
|
|
|
|
return dwOldCount - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2007-10-26 11:31:55 +02:00
|
|
|
* SHGlobalCounterCreateNamedW [SHLWAPI.423]
|
2002-07-22 22:32:53 +02:00
|
|
|
*
|
2007-10-26 11:31:55 +02:00
|
|
|
* Unicode version of SHGlobalCounterCreateNamedA.
|
2002-07-22 22:32:53 +02:00
|
|
|
*/
|
2007-10-26 11:31:55 +02:00
|
|
|
HANDLE WINAPI SHGlobalCounterCreateNamedW(LPCWSTR lpszName, DWORD iInitial)
|
2002-07-22 22:32:53 +02:00
|
|
|
{
|
|
|
|
static const WCHAR szPrefix[] = { 's', 'h', 'e', 'l', 'l', '.', '\0' };
|
|
|
|
const int iPrefixLen = 6;
|
|
|
|
WCHAR szBuff[MAX_PATH];
|
|
|
|
SECURITY_DESCRIPTOR sd;
|
|
|
|
SECURITY_ATTRIBUTES sAttr, *pSecAttr;
|
|
|
|
HANDLE hRet;
|
|
|
|
|
2022-02-18 09:16:21 +01:00
|
|
|
TRACE("(%s,%ld)\n", debugstr_w(lpszName), iInitial);
|
2002-07-22 22:32:53 +02:00
|
|
|
|
|
|
|
/* Create Semaphore name */
|
|
|
|
memcpy(szBuff, szPrefix, (iPrefixLen + 1) * sizeof(WCHAR));
|
|
|
|
if (lpszName)
|
2018-09-15 00:10:29 +02:00
|
|
|
StrCpyNW(szBuff + iPrefixLen, lpszName, ARRAY_SIZE(szBuff) - iPrefixLen);
|
2002-07-22 22:32:53 +02:00
|
|
|
|
|
|
|
/* Initialise security attributes */
|
2007-10-26 11:31:55 +02:00
|
|
|
pSecAttr = CreateAllAccessSecurityAttributes(&sAttr, &sd, 0);
|
2002-07-22 22:32:53 +02:00
|
|
|
|
|
|
|
if (!(hRet = CreateSemaphoreW(pSecAttr , iInitial, MAXLONG, szBuff)))
|
|
|
|
hRet = OpenSemaphoreW(SYNCHRONIZE|SEMAPHORE_MODIFY_STATE, 0, szBuff);
|
|
|
|
return hRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2007-10-26 11:31:55 +02:00
|
|
|
* SHGlobalCounterCreateNamedA [SHLWAPI.422]
|
2002-07-22 22:32:53 +02:00
|
|
|
*
|
|
|
|
* Create a semaphore.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* lpszName [I] Name of semaphore
|
|
|
|
* iInitial [I] Initial count for semaphore
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* A new semaphore handle.
|
|
|
|
*/
|
2007-10-26 11:31:55 +02:00
|
|
|
HANDLE WINAPI SHGlobalCounterCreateNamedA(LPCSTR lpszName, DWORD iInitial)
|
2002-07-22 22:32:53 +02:00
|
|
|
{
|
|
|
|
WCHAR szBuff[MAX_PATH];
|
|
|
|
|
2022-02-18 09:16:21 +01:00
|
|
|
TRACE("(%s,%ld)\n", debugstr_a(lpszName), iInitial);
|
2002-07-22 22:32:53 +02:00
|
|
|
|
|
|
|
if (lpszName)
|
2012-09-24 13:04:26 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, lpszName, -1, szBuff, MAX_PATH);
|
2007-10-26 11:31:55 +02:00
|
|
|
return SHGlobalCounterCreateNamedW(lpszName ? szBuff : NULL, iInitial);
|
2002-07-22 22:32:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
2007-10-26 11:31:55 +02:00
|
|
|
* SHGlobalCounterCreate [SHLWAPI.222]
|
2002-07-22 22:32:53 +02:00
|
|
|
*
|
|
|
|
* Create a semaphore using the name of a GUID.
|
|
|
|
*
|
|
|
|
* PARAMS
|
|
|
|
* guid [I] GUID to use as semaphore name
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* A handle to the semaphore.
|
|
|
|
*
|
|
|
|
* NOTES
|
|
|
|
* The initial count of the semaphore is set to 0.
|
|
|
|
*/
|
2007-10-26 11:31:55 +02:00
|
|
|
HANDLE WINAPI SHGlobalCounterCreate (REFGUID guid)
|
2002-07-22 22:32:53 +02:00
|
|
|
{
|
|
|
|
char szName[40];
|
|
|
|
|
|
|
|
TRACE("(%s)\n", debugstr_guid(guid));
|
|
|
|
|
|
|
|
/* Create a named semaphore using the GUID string */
|
2003-09-11 04:56:15 +02:00
|
|
|
SHStringFromGUIDA(guid, szName, sizeof(szName) - 1);
|
2007-10-26 11:31:55 +02:00
|
|
|
return SHGlobalCounterCreateNamedA(szName, 0);
|
2002-07-22 22:32:53 +02:00
|
|
|
}
|