The following is running without errors. But if one uncomment the marked line, the program crashes after some output lines.
I starr on it for long time, but ...
#define UNICODE
#include <stdio.h>
#include <windows.h>
#include <wchar.h>
#include <comcat.h>
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "ole32.lib")
#pragma comment(lib, "oleaut32.lib")
#pragma comment(lib, "uuid.lib")
int wmain(void)
{
CoInitializeEx(NULL, COINIT_MULTITHREADED);
ICatInformation* catInfo = NULL;
HRESULT hr = CoCreateInstance(&CLSID_StdComponentCategoriesMgr,
NULL, CLSCTX_INPROC_SERVER, &IID_ICatInformation, (void*)&catInfo);
IEnumGUID* enumGuid = NULL;
CATID catidImpl[1];
CATID catidReqd[1];
catidImpl[0] = catidReqd[0] = CATID_Programmable;
catInfo->lpVtbl->EnumClassesOfCategories(catInfo, 1, catidImpl, 1, catidReqd, &enumGuid);
CLSID clsid;
while((hr = enumGuid->lpVtbl->Next(enumGuid, 1, &clsid, NULL)) == S_OK)
{
BSTR name;
OleRegGetUserType(&clsid, USERCLASSTYPE_FULL, &name);
//if (name[0]==L'A') //<<<<<< uncomment
wprintf(L"%ls\n", name);
SysFreeString(name);
}
enumGuid->lpVtbl->Release(enumGuid);
catInfo->lpVtbl->Release(catInfo);
CoUninitialize();
return 0;
}