Hi aardvajk
For a method that supposedly does not work, well, I have to close a lot of windows.
Of course it is not your fault, the documentation is wrong and I'm pretty sure is
wrong intentionally. If you have Vista or 7 (x86) run this, I'm not sure on 64 bit
systems, I don't have the possibility to test.
#define UNICODE
#include <windows.h>
#include <shobjidl.h>
#include <shldisp.h>
#include <wchar.h>
#pragma comment(lib,"ole32.lib")
#pragma comment(lib,"uuid.lib")
#pragma comment(lib,"oleaut32.lib")
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow)
{
WIN32_FIND_DATA FileData;
HANDLE hSearch;
wchar_t first[MAX_PATH] = { 0 };
wchar_t *expand = malloc(sizeof(wchar_t));
if (expand)
{
DWORD d = ExpandEnvironmentStrings(L"%SystemRoot%", expand, 1);
expand = realloc(expand, d * sizeof(wchar_t));
if (expand)
{
ExpandEnvironmentStrings(L"%SystemRoot%", expand, d);
wcscpy(first, expand);
wcscat(first, L"\\System32\\*.cpl");
free(expand);
}
else
return 0;
}
else
return 0;
hSearch = FindFirstFile(first, &FileData);
if (hSearch == INVALID_HANDLE_VALUE)
return 0;
HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
if (FAILED(hr))
{
FindClose(hSearch);
return 0;
}
/////////////////////
IShellDispatch *shell;
/////////////////////
hr = CoCreateInstance(&CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, &IID_IShellDispatch, (void **)&shell);
if (FAILED(hr))
{
FindClose(hSearch);
CoInitialize(NULL);
return 0;
}
hr = shell->lpVtbl->ControlPanelItem(shell, FileData.cFileName);
while (1)
{
if (FindNextFile(hSearch, &FileData))
{
hr = shell->lpVtbl->ControlPanelItem(shell, FileData.cFileName);
if (FAILED(hr))
MessageBox(NULL, L"error", FileData.cFileName, MB_OK);
}
else
break;
}
shell->lpVtbl->Release(shell);
FindClose(hSearch);
CoInitialize(NULL);
return 0;
}
Laur