mfc 注册表
作者:互联网
#include <windows.h>
typedef BOOL(WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
BOOL RegWriteString(HKEY hKey, string keyName, string keyValue, bool valueResult)
{
if (keyValue == "") {
return valueResult;
}
return RegSetValueEx(hKey, keyName.c_str(), 0, REG_SZ, (const BYTE*)keyValue.c_str(), strlen(keyValue.c_str()));
}
LPFN_ISWOW64PROCESS
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(
GetModuleHandle("kernel32"), "IsWow64Process");
BOOL SystemUtil::IsWow64()
{
BOOL bIsWow64 = FALSE;
if (NULL != fnIsWow64Process)
{
if (!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
{
// handle error
}
}
return bIsWow64;
}
/// <summary>
/// 读取指定的key
/// </summary>
/// <param name="displayName"></param>
/// <returns></returns>
/// <summary>
/// 获取32/64对应的注册表值
/// </summary>
/// <returns></returns>
string GetUninstallKey() {
if (IsWow64()) {
return "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
}
else {
return "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\";
}
}
CString GetRegKeyString(string displayName, const char* subKey) {
string key = GetUninstallKey() + displayName;
LONG ires;
HKEY hMyKey;
DWORD Type = REG_SZ;
DWORD count = 256;
byte mstr[256] = "";
ires = RegOpenKeyEx(HKEY_LOCAL_MACHINE, key.c_str(), 0,
KEY_READ, &hMyKey);
if (ERROR_SUCCESS != ires)
return "";
else
ires = RegQueryValueEx(hMyKey, subKey, 0, &Type,
mstr, &count);
ires = RegCloseKey(hMyKey);
CString tms = (LPCTSTR)mstr;
return tms;
}
标签:mfc,return,string,ires,keyValue,hMyKey,注册表,BOOL 来源: https://www.cnblogs.com/ives/p/14900640.html