Want to modify the registry by the program, controlling the printer printing set,
First remove the current set point, change again after back,
TRegistry * Reg;
Reg=new TRegistry (KEY_ALL_ACCESS);
Reg - & gt; RootKey=HKEY_CURRENT_USER;
Reg - & gt; OpenKey (" Printers \ \ DevModePerUser ", true);
Reg - & gt; Wateress GetDataType (" ");
Int BuffLength=Reg - & gt; Wateress GetDataSize (" ");
Unsigned char * Buff=new unsigned char [BuffLength + 1];
Reg - & gt; ReadBinaryData (" wateress ", Buff, BuffLength);
AnsiString strHex;
for(int i=0; I
StrHex=strHex + "" + IntToHex (((int) Buff [I]), 2);
}
//left left left modify Settings left left left
StrHex=...
//write write write modified value write write write
Then I want to have the above revised strHex in back in the same type, how to do it, please?
Reg - & gt; WriteBinaryData (" wateress strHex BuffLength);
Please help me check it out!
CodePudding user response:
Top,
Dry c + + for the first time encountered such a problem!
CodePudding user response:
Consult example
http://docwiki.embarcadero.com/CodeExamples/Seattle/en/JumpListTest_%28C%2B%2B%29
CodePudding user response:
Reg - & gt; WriteBinaryData (" wateress, "strHex c_str (), BuffLength); CodePudding user response:
Reg - & gt; WriteBinaryData (" wateress, "strHex c_str (), strHex. The Length ()); CodePudding user response:
The
reference 3 floor ksrsoft response: Reg - & gt; WriteBinaryData (" wateress, "strHex c_str (), BuffLength); Thank you for your reply, That's what I write do you, The results don't know why, registry keys have been deleted, Then I just what all don't change, after out directly strHex. C_str (), home is the same effect (registry keys are deleted), For some reason, CodePudding user response:
Are not met? For dry c + +, for the first time I met MAO how intractable problems, CodePudding user response:
Test not I delete, add at the end of the Reg - & gt; CloseKey (); The delete Reg. In addition your data to read, write is have change void __fastcall TForm3: : Button2Click (TObject * Sender) { TRegistry * Reg; Reg=new TRegistry (KEY_ALL_ACCESS); Reg - & gt; RootKey=HKEY_CURRENT_USER; Reg - & gt; OpenKey (" Printers \ \ DevModePerUser ", true); Reg - & gt; Wateress GetDataType (" "); Int BuffLength=Reg - & gt; Wateress GetDataSize (" "); Byte Buff [20]. Reg - & gt; ReadBinaryData (" wateress ", Buff, sizeof (Buff)); AnsiString strHex; for (int i=0; I & lt; BuffLength; I++) { StrHex=strHex + "" + IntToHex (((int) Buff [I]), 2); } //left left left modify Settings left left left If (strHex. Length ()==0) { Buff [0]=0 x01; Reg - & gt; WriteBinaryData (" wateress ", Buff, 1); } The else { Reg - & gt; WriteBinaryData (" wateress, "strHex c_str (), strHex. The Length ()); } Reg - & gt; CloseKey (); The delete Reg. } CodePudding user response:
Thank you for your reply, I am also the new test again, The reason can make me out and I deposited in the different, Like me, take out the {" 01 "} Through the following processing, deposit not again {" 01 "}, Become {" 20 to 30 31}, Could you tell me the blame to solve? TRegistry * Reg; Reg=new TRegistry (KEY_ALL_ACCESS); Reg - & gt; RootKey=HKEY_CURRENT_USER; Reg - & gt; OpenKey (" Printers \ \ DevModePerUser ", true); Reg - & gt; Wateress GetDataType (" "); Int BuffLength=Reg - & gt; Wateress GetDataSize (" "); //unsigned char * Buff=new unsigned char [BuffLength + 1]; Unsigned char * Buff=new unsigned char [BuffLength]; Reg - & gt; ReadBinaryData (" wateress ", Buff, BuffLength); AnsiString strHex; for(int i=0; I StrHex=strHex + "" + IntToHex (((int) Buff [I]), 2); } If (strHex. Length ()==0) { Buff [0]=0 x01; Reg - & gt; WriteBinaryData (" wateress ", Buff, 1); } else { Reg - & gt; WriteBinaryData (" wateress, "strHex c_str (), strHex. The Length ()); } Reg - & gt; CloseKey (); The delete Reg. CodePudding user response:
void __fastcall TForm3: : Button2Click (TObject * Sender) { TRegistry * Reg; Reg=new TRegistry (KEY_ALL_ACCESS); Reg - & gt; RootKey=HKEY_CURRENT_USER; Reg - & gt; OpenKey (" Printers \ \ DevModePerUser ", true); Reg - & gt; Wateress GetDataType (" "); Int BuffLength=Reg - & gt; Wateress GetDataSize (" "); Byte Buff [20]. Reg - & gt; ReadBinaryData (" wateress ", Buff, sizeof (Buff)); //left left left modify Settings left left left If (BuffLength==0) { Buff [0]=0 x01; Reg - & gt; WriteBinaryData (" wateress ", Buff, 1); } The else { Buff [0]=Buff [0] + 1; Reg - & gt; WriteBinaryData (" wateress ", Buff, BuffLength); } Reg - & gt; CloseKey (); The delete Reg. } CodePudding user response:
references 9 f ksrsoft response: void __fastcall TForm3: : Button2Click (TObject * Sender) { TRegistry * Reg; Reg=new TRegistry (KEY_ALL_ACCESS); Reg - & gt; RootKey=HKEY_CURRENT_USER; Reg - & gt; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull