4 * Copyright 2014 - David Quintana
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 extern HRESULT
InitShellServices(HDPA
* phdpa
);
24 extern HRESULT
ShutdownShellServices(HDPA hdpa
);
26 static int CALLBACK
InitializeAllCallback(void* pItem
, void* pData
)
28 IOleCommandTarget
* pOct
= reinterpret_cast<IOleCommandTarget
*>(pItem
);
29 HRESULT
* phr
= reinterpret_cast<HRESULT
*>(pData
);
30 TRACE("Initializing SSO %p\n", pOct
);
31 *phr
= pOct
->Exec(&CGID_ShellServiceObject
, OLECMDID_NEW
, OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
32 return SUCCEEDED(*phr
);
35 static int CALLBACK
ShutdownAllCallback(void* pItem
, void* pData
)
37 IOleCommandTarget
* pOct
= reinterpret_cast<IOleCommandTarget
*>(pItem
);
38 TRACE("Shutting down SSO %p\n", pOct
);
39 pOct
->Exec(&CGID_ShellServiceObject
, OLECMDID_SAVE
, OLECMDEXECOPT_DODEFAULT
, NULL
, NULL
);
43 static int CALLBACK
DeleteAllEnumCallback(void* pItem
, void* pData
)
45 IOleCommandTarget
* pOct
= reinterpret_cast<IOleCommandTarget
*>(pItem
);
46 TRACE("Releasing SSO %p\n", pOct
);
51 HRESULT
InitShellServices(HDPA
* phdpa
)
53 IOleCommandTarget
* pOct
;
57 WCHAR value
[MAX_PATH
];
66 TRACE("Enumerating Shell Service Ojbect GUIDs...\n");
68 if (RegOpenKey(HKEY_LOCAL_MACHINE
,
69 L
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ShellServiceObjectDelayLoad",
72 ERR("RegOpenKey failed.\n");
73 return HRESULT_FROM_WIN32(GetLastError());
81 DWORD name_len
= MAX_PATH
;
82 DWORD value_len
= sizeof(value
); /* byte count! */
84 ret
= RegEnumValueW(hkey
, count
, name
, &name_len
, 0, &type
, (LPBYTE
) &value
, &value_len
);
90 WARN("Value type was not REG_SZ.\n");
94 hr
= CLSIDFromString(value
, &clsid
);
95 if (FAILED_UNEXPECTEDLY(hr
))
97 ERR("CLSIDFromString failed %08x.\n", hr
);
101 hr
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
, IID_PPV_ARG(IOleCommandTarget
, &pOct
));
102 if (FAILED_UNEXPECTEDLY(hr
))
104 ERR("CoCreateInstance failed %08x.\n", hr
);
108 DPA_AppendPtr(hdpa
, pOct
);
114 if (ret
!= ERROR_NO_MORE_ITEMS
)
116 ERR("RegEnumValueW failed %08x.\n", ret
);
117 hr
= HRESULT_FROM_WIN32(GetLastError());
124 DPA_EnumCallback(hdpa
, InitializeAllCallback
, &hr
);
125 if (FAILED_UNEXPECTEDLY(hr
))
129 return count
> 0 ? S_OK
: S_FALSE
;
133 ShutdownShellServices(hdpa
);
137 HRESULT
ShutdownShellServices(HDPA hdpa
)
139 DPA_EnumCallback(hdpa
, ShutdownAllCallback
, NULL
);
140 DPA_EnumCallback(hdpa
, DeleteAllEnumCallback
, NULL
);