2014-07-23 18:00:36 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2014-07-28 13:18:57 +00:00
|
|
|
* FILE: dll\win32\stobject\stobject.cpp
|
2014-07-30 22:08:05 +00:00
|
|
|
* PURPOSE: COM registration services for STobject.dll
|
2014-07-28 13:18:57 +00:00
|
|
|
* PROGRAMMERS: Robert Naumann
|
|
|
|
David Quintana <gigaherz@gmail.com>
|
2014-07-23 18:00:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
|
|
|
#include <olectl.h>
|
2014-07-28 13:18:57 +00:00
|
|
|
#include <atlwin.h>
|
2014-07-23 18:00:36 +00:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(stobject);
|
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
BEGIN_OBJECT_MAP(ObjectMap)
|
|
|
|
OBJECT_ENTRY(CLSID_SysTray, CSysTray)
|
|
|
|
END_OBJECT_MAP()
|
2014-07-28 13:18:57 +00:00
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
class CShellTrayModule : public CComModule
|
2014-07-23 18:00:36 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
public:
|
2014-07-28 13:18:57 +00:00
|
|
|
};
|
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
HINSTANCE g_hInstance;
|
|
|
|
CShellTrayModule g_Module;
|
2014-07-28 13:18:57 +00:00
|
|
|
SysTrayIconHandlers_t g_IconHandlers [] = {
|
|
|
|
{ Volume_Init, Volume_Shutdown, Volume_Update, Volume_Message }
|
2014-07-23 18:00:36 +00:00
|
|
|
};
|
2014-07-30 22:08:05 +00:00
|
|
|
const int g_NumIcons = _countof(g_IconHandlers);
|
2014-07-23 18:00:36 +00:00
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
void *operator new (size_t, void *buf)
|
2014-07-23 18:00:36 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
return buf;
|
2014-07-28 13:18:57 +00:00
|
|
|
}
|
2014-07-23 18:00:36 +00:00
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID fImpLoad)
|
2014-07-28 13:18:57 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
if (fdwReason == DLL_PROCESS_ATTACH)
|
2014-07-23 18:00:36 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
g_hInstance = hinstDLL;
|
|
|
|
DisableThreadLibraryCalls(g_hInstance);
|
2014-07-23 18:00:36 +00:00
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
/* HACK - the global constructors don't run, so I placement new them here */
|
|
|
|
new (&g_Module) CShellTrayModule;
|
|
|
|
new (&_AtlWinModule) CAtlWinModule;
|
|
|
|
new (&_AtlBaseModule) CAtlBaseModule;
|
|
|
|
new (&_AtlComModule) CAtlComModule;
|
2014-07-28 13:18:57 +00:00
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
g_Module.Init(ObjectMap, g_hInstance, NULL);
|
2014-07-28 13:18:57 +00:00
|
|
|
}
|
2014-07-30 22:08:05 +00:00
|
|
|
else if (fdwReason == DLL_PROCESS_DETACH)
|
2014-07-28 13:18:57 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
g_hInstance = NULL;
|
|
|
|
g_Module.Term();
|
2014-07-28 13:18:57 +00:00
|
|
|
}
|
2014-07-30 22:08:05 +00:00
|
|
|
return TRUE;
|
2014-07-28 13:18:57 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
static
|
|
|
|
HRESULT
|
|
|
|
RegisterShellServiceObject(REFGUID guidClass, LPCWSTR lpName, BOOL bRegister)
|
2014-07-28 13:18:57 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
const LPCWSTR strRegistryLocation = L"Software\\Microsoft\\Windows\\CurrentVersion\\ShellServiceObjectDelayLoad";
|
2014-07-28 13:18:57 +00:00
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
HRESULT hr = E_FAIL;
|
2014-07-28 13:18:57 +00:00
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
OLECHAR strGuid[128];
|
2014-07-28 13:18:57 +00:00
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
HKEY hKey = 0;
|
2014-07-28 13:18:57 +00:00
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
if (!StringFromGUID2(guidClass, strGuid, _countof(strGuid)))
|
|
|
|
{
|
|
|
|
DbgPrint("StringFromGUID2 failed\n");
|
|
|
|
goto cleanup;
|
2014-07-23 18:00:36 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, strRegistryLocation, 0, KEY_WRITE, &hKey))
|
2014-07-28 13:18:57 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
DbgPrint("RegOpenKeyExW failed\n");
|
|
|
|
goto cleanup;
|
2014-07-28 13:18:57 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
if (bRegister)
|
2014-07-28 13:18:57 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
LONG cbGuid = (lstrlenW(strGuid) + 1) * 2;
|
|
|
|
if (RegSetValueExW(hKey, lpName, 0, REG_SZ, (const BYTE *) strGuid, cbGuid))
|
|
|
|
{
|
|
|
|
DbgPrint("RegSetValueExW failed\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2014-07-28 13:18:57 +00:00
|
|
|
}
|
2014-07-30 22:08:05 +00:00
|
|
|
else
|
2014-07-23 18:00:36 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
if (RegDeleteValueW(hKey, lpName))
|
2014-07-23 18:00:36 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
DbgPrint("RegDeleteValueW failed\n");
|
|
|
|
goto cleanup;
|
2014-07-23 18:00:36 +00:00
|
|
|
}
|
|
|
|
}
|
2014-07-30 22:08:05 +00:00
|
|
|
|
|
|
|
hr = S_OK;
|
|
|
|
|
|
|
|
cleanup:
|
2014-07-23 18:00:36 +00:00
|
|
|
if (hKey)
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
return hr;
|
2014-07-23 18:00:36 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
STDAPI
|
|
|
|
DllRegisterServer(void)
|
2014-07-23 18:00:36 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
HRESULT hr;
|
2014-07-23 18:00:36 +00:00
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
hr = g_Module.DllRegisterServer(FALSE);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
2014-07-23 18:00:36 +00:00
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
hr = RegisterShellServiceObject(CLSID_SysTray, L"SysTray", TRUE);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
2014-07-23 18:00:36 +00:00
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
return S_OK;
|
2014-07-23 18:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
STDAPI
|
2014-07-30 22:08:05 +00:00
|
|
|
DllUnregisterServer(void)
|
2014-07-23 18:00:36 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = RegisterShellServiceObject(CLSID_SysTray, L"SysTray", FALSE);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = g_Module.DllUnregisterServer(FALSE);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
2014-07-23 18:00:36 +00:00
|
|
|
return hr;
|
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
return S_OK;
|
2014-07-23 18:00:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
STDAPI
|
2014-07-30 22:08:05 +00:00
|
|
|
DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
|
2014-07-23 18:00:36 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
hr = g_Module.DllGetClassObject(rclsid, riid, ppv);
|
|
|
|
if (FAILED_UNEXPECTEDLY(hr))
|
|
|
|
return hr;
|
2014-07-23 18:00:36 +00:00
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
return S_OK;
|
2014-07-23 18:00:36 +00:00
|
|
|
}
|
|
|
|
|
2014-07-30 22:08:05 +00:00
|
|
|
HRESULT
|
|
|
|
WINAPI
|
|
|
|
DllCanUnloadNow(void)
|
2014-07-23 18:00:36 +00:00
|
|
|
{
|
2014-07-30 22:08:05 +00:00
|
|
|
return g_Module.DllCanUnloadNow();
|
2014-07-23 18:00:36 +00:00
|
|
|
}
|