bigdogchina
版主
發表:238 回覆:523 積分:312 註冊:2003-04-28
發送簡訊給我
|
小弟使用TRegistry想将注册表中的一些值读出,但是出错了
我是这样做的:
在头文件中添加
#include
在单元文件中的代码如下
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TRegistry *RegInfo = new TRegistry();
try
{
RegInfo->RootKey = HKEY_LOCAL_MACHINE;
RegInfo->OpenKeyReadOnly("\\HARDWARE\\DESCRIPTION\\System"); Label1->Caption = RegInfo->ReadString("SystemBiosVersion");
Label2->Caption = RegInfo->ReadString("SystemBiosDate");
Label3->Caption = RegInfo->ReadString("VideoBiosVersion");
Label4->Caption = RegInfo->ReadString("VideoBiosDate");
}
__finally
{
RegInfo->CloseKey();
delete RegInfo;
}
}
在单击Button1后就会出现错误:
Project Project1.exe raised exception class ERegistryException with message 'Invalid data type for 'SystemBiosVersion'.Process stopped.Use
Step or Run to continue.
它的意思是说在读取SystemBiosVersion的时候有错误,我打开注册表,发现SystemBiosVersion的类型不是一般的REG_SZ,而是REG_MULTI_SZ,我就不知道该用什么函数来读取了,想请大大们告诉我应该这样来做呢?谢谢 人生在勤,不索何获?
------ 人生在勤,不索何获?
|
dllee
站務副站長
發表:321 回覆:2519 積分:1711 註冊:2002-04-15
發送簡訊給我
|
引言:
小弟使用TRegistry想将注册表中的一些值读出,但是出错了
我是这样做的:
在头文件中添加
#include
在单元文件中的代码如下
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TRegistry *RegInfo = new TRegistry();
try
{
RegInfo->RootKey = HKEY_LOCAL_MACHINE;
RegInfo->OpenKeyReadOnly("\\HARDWARE\\DESCRIPTION\\System"); Label1->Caption = RegInfo->ReadString("SystemBiosVersion");
Label2->Caption = RegInfo->ReadString("SystemBiosDate");
Label3->Caption = RegInfo->ReadString("VideoBiosVersion");
Label4->Caption = RegInfo->ReadString("VideoBiosDate");
}
__finally
{
RegInfo->CloseKey();
delete RegInfo;
}
}
在单击Button1后就会出现错误:
Project Project1.exe raised exception class ERegistryException with message 'Invalid data type for 'SystemBiosVersion'.Process stopped.Use
Step or Run to continue.
它的意思是说在读取SystemBiosVersion的时候有错误,我打开注册表,发现SystemBiosVersion的类型不是一般的REG_SZ,而是REG_MULTI_SZ,我就不知道该用什么函数来读取了,想请大大们告诉我应该这样来做呢?谢谢 人生在勤,不索何获?
必需使用 ReadBinaryData 來讀,例如:
int iLen;
char Buf[4096];
TRegistry *RegInfo = new TRegistry();
try
{
RegInfo->RootKey = HKEY_LOCAL_MACHINE;
RegInfo->OpenKeyReadOnly("\\HARDWARE\\DESCRIPTION\\System");
memset(Buf,0,4096);
iLen=RegInfo->ReadBinaryData("SystemBiosVersion",Buf,4095);
for(int i=0;iCaption = String(Buf);
Label2->Caption = RegInfo->ReadString("SystemBiosDate");
memset(Buf,0,4096);
iLen=RegInfo->ReadBinaryData("VideoBiosVersion",Buf,4095);
for(int i=0;iCaption = String(Buf);
Label4->Caption = RegInfo->ReadString("VideoBiosDate");
}
__finally
{
RegInfo->CloseKey();
delete RegInfo;
}
使用 TRegistry 要小心,只要型別不對,就是 Exception ! 沒空更新的網頁...
http://dllee.ktop.com.tw C及指標教學,計算機概論,資訊管理導論... http://dllee.adsldns.org 介紹Shells,LiteStep,GeoShell.... 發表人 - dllee 於 2003/06/21 07:16:59
------ http://www.ViewMove.com
|