• 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;
    }
    
    留待后查,同时方便他人
    联系我:renhanlinbsl@163.com
  • 相关阅读:
    Eclipse 安装插件
    java 之 Spring 框架(Java之负基础实战)
    tomcat 修改网站路径(Java之负基础实战)
    tomcat 修改编码(Java之负基础实战)
    tomcat 修改端口(Java之负基础实战)
    linux vi 操作
    解压文件--linux
    smarty用法
    thinkphp调试手段
    kindeditor上传文件的使用
  • 原文地址:https://www.cnblogs.com/ives/p/14900640.html
Copyright © 2020-2023  润新知