Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem writing into registry

Status
Not open for further replies.

Amulet

Programmer
Sep 29, 2002
19
MY
1) i'm trying to write into the registry, a set of numbers like this :
00 00 00 00 00 00 00 00

the key was succesfully created, but the numbers appear in the registry as cc cc cc cc cc cc cc cc .

why ? please help thank you.

2) i'm trying to retrieve data from the registry and list them out in the list box on a click of a List button. how do i do it ?

please help. thank you.
 
Could you give an example code you use to write data to the registry?
 
hi.. here's the code.

BYTE bHexa[MAXIMUM_ATTR_STRING_LENGTH];
DWORD dwHexLength=0;

RegCreateKeyE....);

//create key is succesful

//write value into registry
StrToHelpBarCode, bHexa, &dwHexLength);
RegSetValueEx (hReg,
"BAR",
0,
REG_BINARY,
bHexa,
dwHexLength);

RegCloseKey(&hReg);
return S_OK;


****************

/////////////////////////////////////////////////////////////////////////////////////////////
//Name : StrToHe)
//Function : Convert String to Hexadecimal
/////////////////////////////////////////////////////////////////////////////////////////////

HRESULT StrToHeLPTSTR lpInputStr, BYTE *bHexOutput, DWORD *dwLength){
const MAXHEXLEN = 256;
int i=0;
int j=0;
BYTE bHexInput[MAXHEXLEN];

bHexInput[0] = NULL;
while(*lpInputStr != NULL){
sscanf((lpInputStr),"%2x",(bHexInput+i));
i++;
*lpInputStr++;
*lpInputStr++;
}

for(j=0;j<i;j++){
*(bHexOutput+j) = bHexOutput[j];
}

*dwLength = j;
return S_OK;
}

///////////////////////////////////////////////////////////////////////////////////////////////
//end StrToHe) function
///////////////////////////////////////////////////////////////////////////////////////////////

*******
 
how do i print out a list of strings (retrieve from the registry ) into a list box? appreciate if u could help..thx.
 
The error:
*(bHexOutput+j) = bHexOutput[j];
must be
*(bHexOutput+j) = bHexInput[j];

Additional hints:
1. sscanf() with format specifyer &quot;%x&quot; suspects pointer to int as a value buffer argument, so, temporary int variable must be used, not array of chars.
2. It is not good to change values of function arguments (like lpInputStr++) - it is potential source of further errors, better use local variables.

And finally - your function:

HRESULT StrToHex(LPTSTR lpInputStr, BYTE *bHexOutput, DWORD *dwLength)
{
int hex_val;
char *pnts;

*dwLength=0;
pnts=lpInputStr;

while(*pnts)
{
hex_val=0;
sscanf(pnts, &quot;%2x&quot;, &hex_val);
bHexOutput[(*dwLength)++]=hex_val;
pnts++;
if(*pnts) pnts++;
}

return S_OK;
}

I suppose, your input string is &quot;00000000&quot; not a &quot;00 00 00 00&quot;?
 
hi,
you're right, the string that i want to input is 00000000, it appears
as 00 00 00 00 in the registry.

i tried your suggestions and you're right again!!
thank you so much for pointing out that error.
i've been working on it for almost two weeks now but still couldnt make
it work.. thank you thank you so much.(actually i'm a very newbie with
programming and had never open the registry before i was handed this
project).

i have trouble displaying data that are retrieve from the registry
directly into the listbox . i created a button, that when click, will
automatically list out the data stored in the registry. previously i filled
the listbox with

CListBox* lbptr = (CListBox*)GetDlgItem(IDC_LIST1);

lbptr->AddString(&quot;F&N&quot;);
etc etc

the reason why i want to display the data directly into the listbox
from the registry by a click of a button is because since i created an
input button (based on the previous 00 000000 question ), i want the user
to get the latest data currently stored in the registry. so the button
also works as a refresh button.

code:

void CProDlg::OnButtonList(); //messages on BN_CLICKED

HKEY hKey;
TCHAR szProductType[MY_BUFSIZE];
DWORD dwBufLen = MY_BUFSIZE;
LONG lRet;
char buffer[100];

if(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT(&quot;KeyName&quot;),
0,
KEY_ALL_ACCESS,
&hKey)== ERROR_SUCCESS)
//return;

while ((lErrCode = RegEnumKeyEx(hKey,
dwIndex++,
szKeyName,
&dwBufLen,
NULL,
NULL,
NULL,
NULL)) != ERROR_NO_MORE_ITEMS)


lRet = RegQueryValueEx(hKey,
TEXT(&quot;KeyName&quot;),
NULL,
NULL,
(LPBYTE)szKeyName,
&dwBufLen);

CListBox* lbptr = (CListBox*)GetDlgItem(IDC_LIST1);

lbptr->AddString(&quot;F&N&quot;); // str );
lbCards->AddString(&quot;Bernas&quot;);
...
...
...
lbCards->AddString(&quot;FaizaLtd&quot;)
***end**

please suggest me a better way... thankyou.
 
Sorry, this question is not to me - I'm not familiar with visual programming.
 
aww.. ok .. what a bummer ... but u've been a great help really :) ...thanxx!! . i'll hope someone would look through my question and sugggest a better solution or correct my errors. Take care.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top