[SHELL32] Implement LockServer (#9055)

This commit is contained in:
Alex Mendoza
2026-06-27 16:36:29 +02:00
committed by GitHub
parent d47cdbbdff
commit 02f2314139
4 changed files with 97 additions and 2 deletions
+28 -2
View File
@@ -209,8 +209,34 @@ HRESULT WINAPI IDefClFImpl::CreateInstance(IUnknown * pUnkOuter, REFIID riid, LP
*/
HRESULT WINAPI IDefClFImpl::LockServer(BOOL fLock)
{
TRACE("%p->(0x%x), not implemented\n", this, fLock);
return E_NOTIMPL;
TRACE("%p->(0x%x)\n", this, fLock);
if (fLock)
{
if (pcRefDll)
{
if (*pcRefDll == LONG_MAX)
ERR("pcRefDll is pinned, not incrementing\n");
else
InterlockedIncrement(pcRefDll);
}
_pAtlModule->Lock();
}
else
{
_pAtlModule->Unlock();
if (pcRefDll)
{
if (*pcRefDll == LONG_MAX)
ERR("pcRefDll is pinned, not decrementing\n");
else if (*pcRefDll > 0)
InterlockedDecrement(pcRefDll);
else
ERR("pcRefDll underflow\n");
}
}
return S_OK;
}
/**************************************************************************
@@ -17,6 +17,7 @@ list(APPEND SOURCE
FindExecutable.cpp
GetDisplayNameOf.cpp
GUIDFromString.cpp
LockServer.cpp
Int64ToString.cpp
IShellFolderViewCB.cpp
ItemIDList.cpp
@@ -0,0 +1,66 @@
/*
* PROJECT: ReactOS API tests
* LICENSE: MIT (https://spdx.org/licenses/MIT)
* PURPOSE: Test for LockServer
* COPYRIGHT: Copyright 2026 Alex Mendoza <[email protected]>
*/
#include "shelltest.h"
#include <undocshell.h>
static HRESULT CALLBACK CreateInstanceStub(IUnknown *pUnkOuter, REFIID riid, LPVOID *ppv)
{
*ppv = NULL;
return E_NOTIMPL;
}
static void test_LockServer(void)
{
IClassFactory *pcf = NULL;
LONG refDll = 0;
HRESULT hr;
hr = SHCreateDefClassObject(IID_IClassFactory,
(LPVOID*)&pcf,
CreateInstanceStub,
(LPDWORD)&refDll,
IID_IUnknown);
ok(hr == S_OK, "SHCreateDefClassObject failed: %08lx\n", hr);
ok(pcf != NULL, "pcf is NULL\n");
if (!pcf)
{
skip("pcf is NULL, skipping LockServer tests\n");
return;
}
ok(refDll == 1, "Expected refDll == 1 after init, got %ld\n", refDll);
hr = pcf->LockServer(TRUE);
ok(hr == S_OK, "LockServer() failed: %08lx\n", hr);
ok(refDll == 2, "Expected refDll == 2 after lock, got %ld\n", refDll);
hr = pcf->LockServer(FALSE);
ok(hr == S_OK, "LockServer() failed: %08lx\n", hr);
ok(refDll == 1, "Expected refDll == 1 after unlock, got %ld\n", refDll);
hr = pcf->LockServer(FALSE);
ok(hr == S_OK, "LockServer() failed: %08lx\n", hr);
ok(refDll >= 0, "refDll went negative after unlock when not locked: %ld\n", refDll);
hr = pcf->LockServer(TRUE);
ok(hr == S_OK, "LockServer() failed: %08lx\n", hr);
hr = pcf->LockServer(TRUE);
ok(hr == S_OK, "LockServer() failed: %08lx\n", hr);
hr = pcf->LockServer(FALSE);
ok(hr == S_OK, "LockServer() failed: %08lx\n", hr);
hr = pcf->LockServer(FALSE);
ok(hr == S_OK, "LockServer() failed: %08lx\n", hr);
pcf->Release();
ok(refDll == 0, "Expected refDll == 0 after Release, got %ld\n", refDll);
}
START_TEST(LockServer)
{
test_LockServer();
}
@@ -21,6 +21,7 @@ extern void func_ILCreateFromPath(void);
extern void func_ILIsEqual(void);
extern void func_Int64ToString(void);
extern void func_IShellFolderViewCB(void);
extern void func_LockServer(void);
extern void func_menu(void);
extern void func_OpenAs_RunDLL(void);
extern void func_PathIsEqualOrSubFolder(void);
@@ -80,6 +81,7 @@ const struct test winetest_testlist[] =
{ "ILIsEqual", func_ILIsEqual },
{ "Int64ToString", func_Int64ToString },
{ "IShellFolderViewCB", func_IShellFolderViewCB },
{ "LockServer", func_LockServer },
{ "menu", func_menu },
//{ "OpenAs_RunDLL", func_OpenAs_RunDLL }, // Test hangs on Win 2003
{ "PathIsEqualOrSubFolder", func_PathIsEqualOrSubFolder },