開発環境 Microsoft Visual Studio Express 2013 for Windows Desktop
実行環境 Microsoft Windows 8.1 (64bit)
プロジェクトの種類 Visual C++/Win32 コンソール アプリケーション
プロジェクト名 ocxlist
アプリケーションの種類 コンソール アプリケーション
追加のオプション 空のプロジェクト, SDLチェック

ocxlist.cpp
#include <stdio.h>
#include <Windows.h>
 
int main()
{
	LONG ret;
 
	// レジストリキーを開く
	// HKEY_LOCAL_MACHINE "Software\\Classes"
	HKEY hKey;
	ret = RegOpenKeyEx(HKEY_CLASSES_ROOT, NULL, 0, KEY_READ, &hKey);
	if (ret != ERROR_SUCCESS) {
		return 1;
	}
 
	// サブキーの列挙
	for (DWORD dwIndex = 0; ; dwIndex++) {
		TCHAR name[256];
		DWORD cName = _countof(name);
		ret = RegEnumKeyEx(hKey, dwIndex, name, &cName, NULL, NULL, NULL, NULL);
		if (ret != ERROR_SUCCESS) {
			break;	// 259 ERROR_NO_MORE_ITEMS
		}
 
		// CLSIDキーがあるか
		wcscat_s(name, L"\\CLSID");
		HKEY hSubKey;
		ret = RegOpenKeyEx(HKEY_CLASSES_ROOT, name, 0, KEY_READ, &hSubKey);
		if (ret != ERROR_SUCCESS) {
			continue;
		}
		ret = RegCloseKey(hSubKey);
		wprintf(L"%u:[%s]\n", dwIndex, name);
	}
 
	// レジストリキーのハンドルを閉じる
	ret = RegCloseKey(hKey);
 
	return 0;
}
 

+ ...
ocxlist.cpp
#include <stdio.h>
#include <Windows.h>
 
int main()
{
	HKEY hKey;
	LONG ret;
 
	// レジストリキーを開く
	ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software\\Classes", 0, KEY_READ, &hKey);
	if (ret != ERROR_SUCCESS) {
		return 1;
	}
 
	// サブキーの列挙
	for (DWORD dwIndex = 0; ; dwIndex++) {
		TCHAR name[256];
		DWORD cName = _countof(name);
		ret = RegEnumKeyEx(hKey, dwIndex, name, &cName, NULL, NULL, NULL, NULL);
		if (ret != ERROR_SUCCESS) {
			break;	// 259 ERROR_NO_MORE_ITEMS
		}
		wprintf(L"%u:[%s]\n", dwIndex, name);
	}
 
	// レジストリキーのハンドルを閉じる
	ret = RegCloseKey(hKey);
 
	return 0;
}
 
最終更新:2014年04月03日 21:57