您好,登錄后才能下訂單哦!
這期內容當中小編將會給大家帶來有關如何寫注冊表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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。