这期内容当中小编将会给大家带来有关如何写注册表REG_BINARY,REG_DWORD,REG_SZ值,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。
inline BYTE CharToBin(TCHAR ch)
{
if(ch>='0' && ch<='9')
return ch - '0';
if(ch>='a' && ch<='f')
return ch - 'a' + 10;
if(ch>='A' && ch<= 'F')
return ch - 'A' + 10;
return 0xff;
}
inline bool Hex2Bin(LPCTSTR lpHex,LPBYTE lpBin,DWORD &dwLen)
{
LPCTSTR lpChar = lpHex;
TCHAR char1 = *lpChar;
TCHAR char2 = *(lpChar+1);
if(!char1 || !char2)
return false;
LPBYTE lpOut = lpBin;
DWORD inputBuf = dwLen;
dwLen = 0;
BYTE h = CharToBin(char1);
BYTE l = CharToBin(char2);
while(0xff != h && 0xff != l)
{
*lpOut = l | h<<4;
lpOut++;
dwLen++;
lpChar+=2;
if(inputBuf<=dwLen)
break;
h = CharToBin(*lpChar);
l = CharToBin(*(lpChar+1));
}
return true;
}
BOOL RegWrite(HKEY hKey,LPCSTR lpSubKey,LPCSTR lpValue,DWORD dwType,void* pData,DWORD dwLen)
{
if(!pData)
return FALSE;
if(REG_BINARY == dwType)
{
void* pBuffer = new BYTE[lstrlen((char*)pData)];
memset(pBuffer,0,lstrlen((char*)pData));
if(pBuffer)
{
Hex2Bin((LPCTSTR)pData,(LPBYTE)pBuffer,dwLen);
SHSetValue(hKey,lpSubKey,lpValue,REG_BINARY,pBuffer,dwLen);
delete []pBuffer;
}
}
else
{
if(REG_SZ == dwType)
{
dwLen = lstrlen((const char*)pData);
}
else if(REG_DWORD == dwType)
dwLen = 4;
SHSetValue(hKey,lpSubKey,lpValue,dwType,pData,dwLen);
}
return TRUE;
}
void main(int argc,char*argv[])
{
RegWrite(HKEY_LOCAL_MACHINE,"SOFTWARE//aaaa//","b",REG_BINARY,"123456abcdef",6);
DWORD dwValue = 1234;
RegWrite(HKEY_LOCAL_MACHINE,"SOFTWARE//aaaa//","c",REG_DWORD,&dwValue,4);
RegWrite(HKEY_LOCAL_MACHINE,"SOFTWARE//aaaa//","d",REG_SZ,"asdfgh",0);
}
上述就是小编为大家分享的如何写注册表REG_BINARY,REG_DWORD,REG_SZ值了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。