 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
LarryJ Guest
|
Posted: Thu Apr 26, 2007 8:10 am Post subject: Registry Help with Vista |
|
|
I have a few people using my software with Windows Vista and the
registration values that my program writes to the registry are not being
read from the registry when the program starts. Below is the registry Read
Write code that I am using? Do I need to change the RegistryKey value to be
compatible with Windows Vista?
//====================================================
RegistryKey = "\\Software\\MYCompany";
RegFolder1 = "\\MW3";
RegFolder2 = "\\AT3";
AnsiString First, Last, Source, S36,
//====================================================
try {
Registry = new TRegistry( KEY_WRITE );
}
catch (...) {
return;
}
try {
Registry->RootKey = HKEY_CURRENT_USER;
Registry->OpenKey(RegistryKey + RegFolder1, true);
Registry->WriteString("First", First);
Registry->WriteString("Last", Last);
Registry->WriteString("S36", S36);
Registry->CloseKey();
}
catch (...) {
delete Registry;
Registry=NULL;
return;
}
delete Registry;
Registry=NULL;
try {
Registry = new TRegistry( KEY_READ );
}
catch (...) {
fail=true;
}
try {
Registry->RootKey = HKEY_CURRENT_USER;
ck5 = Registry->KeyExists(RegistryKey + RegFolder1);
if(ck5==true){
Registry->OpenKeyReadOnly(RegistryKey + RegFolder1);
if(Registry->ValueExists("First")) {HDFstName =
Registry->ReadString("First");}else{HDFstName="";}
if(Registry->ValueExists("Last")) {HDLstName =
Registry->ReadString("Last");}else{HDLstName="";}
if(Registry->ValueExists("S36")) {S36 =
Registry->ReadString("S36");}else{S36="";}
Registry->CloseKey();
}
if(ck5==false){
fail=true;
}
}
catch (...) {
fail=true;
}
delete Registry;
Registry=NULL;
Thanks
Larry Johnson |
|
| Back to top |
|
 |
Miguel Gimenez Guest
|
Posted: Thu Apr 26, 2007 3:51 pm Post subject: Re: Registry Help with Vista |
|
|
LarryJ wrote:
| Quote: | I have a few people using my software with Windows Vista and the
registration values that my program writes to the registry are not being
read from the registry when the program starts. Below is the registry Read
Write code that I am using? Do I need to change the RegistryKey value to be
compatible with Windows Vista?
//====================================================
RegistryKey = "\\Software\\MYCompany";
RegFolder1 = "\\MW3";
RegFolder2 = "\\AT3";
AnsiString First, Last, Source, S36,
//====================================================
try {
Registry = new TRegistry( KEY_WRITE );
}
catch (...) {
return;
}
try {
Registry->RootKey = HKEY_CURRENT_USER;
Registry->OpenKey(RegistryKey + RegFolder1, true);
Registry->WriteString("First", First);
Registry->WriteString("Last", Last);
Registry->WriteString("S36", S36);
Registry->CloseKey();
}
catch (...) {
delete Registry;
Registry=NULL;
return;
}
delete Registry;
Registry=NULL;
try {
Registry = new TRegistry( KEY_READ );
}
catch (...) {
fail=true;
}
try {
Registry->RootKey = HKEY_CURRENT_USER;
ck5 = Registry->KeyExists(RegistryKey + RegFolder1);
if(ck5==true){
Registry->OpenKeyReadOnly(RegistryKey + RegFolder1);
if(Registry->ValueExists("First")) {HDFstName =
Registry->ReadString("First");}else{HDFstName="";}
if(Registry->ValueExists("Last")) {HDLstName =
Registry->ReadString("Last");}else{HDLstName="";}
if(Registry->ValueExists("S36")) {S36 =
Registry->ReadString("S36");}else{S36="";}
Registry->CloseKey();
}
if(ck5==false){
fail=true;
}
}
catch (...) {
fail=true;
}
delete Registry;
Registry=NULL;
Thanks
Larry Johnson
|
Did the write part work? Use regedit to verify this point.
--
Regards
Miguel Gimenez |
|
| Back to top |
|
 |
Thomas Maeder [TeamB] Guest
|
Posted: Thu Apr 26, 2007 9:43 pm Post subject: Re: Registry Help with Vista |
|
|
"LarryJ" <LarryJ33 (AT) austin (DOT) rr.com> writes:
| Quote: | I have a few people using my software with Windows Vista and the
registration values that my program writes to the registry are not being
read from the registry when the program starts. Below is the registry Read
Write code that I am using? Do I need to change the RegistryKey value to be
compatible with Windows Vista?
//====================================================
RegistryKey = "\\Software\\MYCompany";
RegFolder1 = "\\MW3";
RegFolder2 = "\\AT3";
AnsiString First, Last, Source, S36,
//====================================================
try {
Registry = new TRegistry( KEY_WRITE );
|
The first thing I'd do is check whether TRegistry instances really
have to be created dynymically. If not, changing Registry's type to
TRegistry will greatly simplify your code.
| Quote: | }
catch (...) {
return;
}
try {
Registry->RootKey = HKEY_CURRENT_USER;
Registry->OpenKey(RegistryKey + RegFolder1, true);
|
OpenKey() returns bool. You should check the return value before
blindly going on.
| Quote: | Registry->WriteString("First", First);
Registry->WriteString("Last", Last);
Registry->WriteString("S36", S36);
Registry->CloseKey();
}
catch (...) {
|
WriteString() and CloseKey() are documented to throw an exception if
they fail. Do you ever get into on of the catch clauses? |
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Apr 26, 2007 11:22 pm Post subject: Re: Registry Help with Vista |
|
|
"Thomas Maeder [TeamB]" <maeder (AT) glue (DOT) ch> wrote in message
news:m2r6q7krxj.fsf (AT) glue (DOT) ch...
| Quote: | The first thing I'd do is check whether TRegistry instances
really have to be created dynymically.
|
Yes, they do. All classes derived from the VCL TObject class must be
instantiated dynamically on the heap.
| Quote: | WriteString() and CloseKey() are documented to throw an
exception if they fail.
|
WaiteString() will raise an exception, but CloseKey() will not.
Gambit |
|
| Back to top |
|
 |
Thomas Maeder [TeamB] Guest
|
Posted: Fri Apr 27, 2007 1:26 am Post subject: Re: Registry Help with Vista |
|
|
"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> writes:
| Quote: | The first thing I'd do is check whether TRegistry instances
really have to be created dynymically.
Yes, they do. All classes derived from the VCL TObject class must be
instantiated dynamically on the heap.
|
I was afraid of that. But still, using a std::auto_ptr will still
simplify things a lot. |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|