#define CACHE_CONFIG_ROOT "Software\\CPFC_FLG"
#define CACHE_KEY "CPFC_PASS"
/*************************************************************************
Purpose : 设置值
Input :nVal 值
Return : 0--成功 其他--返回错误码
Modify :
Remark :
*************************************************************************/
DWORD IE_SetRegConfig(CHAR *nPin)
{
LONG lRet = 0;
HKEY hKey = NULL;
char szTmpSite[1024] = {0};
DWORD dwDisp = 0;
sprintf(szTmpSite, "%s", CACHE_CONFIG_ROOT);
char szFlag[32] = {0};
char dwData[32] = {0};
char szInfo[1024] = {0};
DWORD dwInfo = 0;
DWORD dwBufLen = 1024;
strcpy(szFlag, CACHE_KEY);
lRet = RegOpenKeyExA(HKEY_CURRENT_USER, szTmpSite, 0, KEY_ALL_ACCESS, &hKey);
if (lRet != ERROR_SUCCESS)
{
//不存在该键值就创建
lRet = RegCreateKeyExA(HKEY_CURRENT_USER, szTmpSite, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwDisp);
if (lRet != ERROR_SUCCESS)
{
return lRet;
}
}
strcpy(dwData, nPin);
lRet = RegSetValueExA(hKey, szFlag, NULL, REG_BINARY, (LPBYTE)dwData, strlen(dwData)+1);
if(lRet != 0)
{
RegCloseKey(hKey);
return lRet;
}
RegCloseKey(hKey);
return 0;
}
/*************************************************************************
Purpose : 读取值
Input : pnVal 值
Return : None
Modify :
Remark :
*************************************************************************/
void IE_ReadRegConfig(CHAR *pnVal)
{
LONG lRet = 0;
HKEY hKey = NULL;
char szTmpSite[1024] = {0};
char szFlag[32] = {0};
char szInfo[1024] = {0};
DWORD dwBufLen = 1024;
CHAR dwData[32] = {0};
sprintf(szTmpSite, "%s", CACHE_CONFIG_ROOT);
strcpy(szFlag, CACHE_KEY);
lRet = RegOpenKeyExA(HKEY_CURRENT_USER, szTmpSite, 0, KEY_ALL_ACCESS, &hKey);
if (lRet != ERROR_SUCCESS)
{
memcpy(pnVal, "0", 1); //给一个默认值
return ;
}
lRet = RegQueryValueExA(hKey, szFlag, NULL, NULL, (LPBYTE)szInfo, &dwBufLen);
if (lRet != 0)
{
memcpy(pnVal, "0", 1); //给一个默认值
return ;
}
memcpy(pnVal, szInfo, dwBufLen);
return ;
}
创建注册表,设置和读取注册表中的值
最新推荐文章于 2021-07-19 22:52:43 发布