最近再写程序的时候,想读取注册表中一个键值的数据。可是查了很多资料,都不能取到注册表中键值。
最后终于搞定了。下面是代码:
void GetInternalPictureLocation(TCHAR *outBuffer)
{
LRESULT lr = E_FAIL;
HKEY hKey = NULL;
DWORD dwValueDataLen = 123456;
BYTE *dwValueData = (BYTE *) LocalAlloc(LMEM_FIXED, dwValueDataLen);
DWORD dwValueType = 0;
LONG rc = NULL;
rc = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"\\System\\Pictures\\Camera\\OEM\\PictureLocation",0,0,&hKey);
if(rc==ERROR_SUCCESS)
{
lr = RegQueryValueEx(hKey,TEXT("Internal"),NULL,&dwValueType,(LPBYTE)dwValueData,&dwValueDataLen);
*outBuffer = TEXT('\0');
lstrcat (outBuffer, TEXT("\""));
lstrcat (outBuffer, (LPTSTR) dwValueData);
lstrcat (outBuffer, TEXT("\""));
RegCloseKey(hKey);
}
}
http://msdn.microsoft.com/en-us/library/ms838625.aspx
http://hi.baidu.com/february16/blog/item/274195b0626726520823027e.html
http://windowsmobilepro.blogspot.com/