设置注册表数据和类型
设置注册表数据和类型
LONG RegSetValueEx(
HKEY hKey, 键
LPCTSTR lpValueName, 子健
DWORD Reserved, 保留值,必须强制为0
DWORD dwType, 数据类型
CONST BYTE *lpData, 数据
DWORD cbData 数据大小
);
删除一个注册表键
LONG WINAPI RegDeleteKey(
__in HKEY hKey, 注册表打开的键值的句柄。删除的键值必须是拥有访问权限的。
__in LPCTSTR lpSubKey 被删除的键值名称
);
该函数主要为了获取要删除键值句柄
LONG RegOpenKey(
HKEY hKey, // 要打开键的句柄
LPCTSTR lpSubKey, // 要打开子键的名字的地址
PHKEY phkResult ); // 要打开键的句柄的地址 传出参数 HKEY hKey,
LONG RegDeleteValue(
HKEY hKey, // 要打开键的句柄
LPCWSTR lpValueName ); //删除一个键值。
注册表遍历
RegEnumKeyEx ------》 Example Code
For an example, see Using the Registry.
照搬即可
//写注册表
for (int i = 0; i < sizeof(g_Regs) / sizeof(g_Regs[0]); i++) { const char* SubKey = g_Regs[i][0]; const char* ValueName = g_Regs[i][1]; const char* Value = g_Regs[i][2]; if (Value == NULL) Value = Path; HKEY hKey; //RegCreateKey(HKEY_CLASSES_ROOT, SubKey, &hKey); LONG lRet = RegSetKeyValue(HKEY_CLASSES_ROOT, SubKey, ValueName, REG_SZ, Value, strlen(Value)); if (lRet != ERROR_SUCCESS)
因为不可能dll路径固定,所以需要在注册表中添加dll路径
使每次可以系统的查询dll路径位置。
注册表中,dll路径加载位置
计算机\HKEY_CLASSES_ROOT\WOW6432Node\CLSID
通过 regsvr32.exe 来加载dll 使dll路径添加到注册表中
一般dll里面的导出函数
STDAPI DllGetClassObject
STDAPI DllRegisterServer()
STDAPI DllUnregisterServer()
STDAPI DllCanUnloadNow()
类产生对象都和其他工厂,没有关系
template<typename class_name, typename class_base> class CMyFactory :public ImpIUnknown<class_name, class_base> { public: CMyFactory() :ImpIUnknown(IID_IMyClassFactory) { } virtual HRESULT __stdcall CreateObject(const GUID & iid, void**ppObject) { static class_name *pObject = NULL; if (pObject == NULL) pObject = new class_name; HRESULT hr = pObject->QueryInterface(iid, ppObject); if (FAILED(hr) && class_name::m_RefCount == 0) { delete pObject; pObject = NULL; } return hr; } static HRESULT Create(const GUID & clsid, const GUID & iid, void** ppObject) { static IMyClassFactory *pObject = NULL; if (pObject == NULL) { pObject = new CMyFactory(); } HRESULT hr = pObject->QueryInterface(iid, ppObject); if (FAILED(hr) && m_RefCount == 0) { delete pObject; pObject = NULL; } return hr; } public: static int m_RefCount; }; template<typename class_name, typename class_base> int CMyFactory<class_name, class_base>::m_RefCount = 0;