Наши проекты:
Журнал · Discuz!ML · Wiki · DRKB · Помощь проекту |
||
ПРАВИЛА | FAQ | Помощь | Поиск | Участники | Календарь | Избранное | RSS |
[18.225.149.238] |
|
Сообщ.
#1
,
|
|
|
Программа открывает HKEY_CURRENT_USER\Software
Если там нет раздела Sms то она создает его, плюс, создает несколько параметров и записывает в них данные. И заканчивает свою работу. При следующем запуске раздел Sms уже создан. И программа ПЫТАЕТСЯ прочесть данные в этом разделе. И вот ту начинается полная лажа. Плиз если не сложно откомпилируйте и посмотрите. Также есть другая проблема при чтении данных. Этот участок кода я закомментировал (как получить прочесть число) так как он дает переполнение буфера. Заранее благодарен за помощь. #include <windows.h> #include <iostream.h> main() { HKEY hKey,hKey2; DWORD s = 5, n = 200; DWORD Disp = REG_OPENED_EXISTING_KEY; char *from = new char[128]; char *to = new char[128]; char *buf = new char[128]; long lnRes = RegOpenKeyEx(HKEY_CURRENT_USER,"Software",0,KEY_ALL_ACCESS,&hKey); if( lnRes != ERROR_SUCCESS ) return 0; lnRes = RegOpenKeyEx(hKey,"Sms",0,KEY_ALL_ACCESS,&hKey2); if( lnRes == ERROR_SUCCESS ) { int index = 1; DWORD l = 128; UINT number, sleep; RegEnumValue(hKey2,index,buf,&l,0l,NULL,(unsigned char *)from,&l); cout<<index<<" : "<<buf<<"\t"<<from<<"\n"; ZeroMemory( buf,128 ); index++; RegEnumValue(hKey2,index,buf,&l,0l,NULL,(unsigned char *)to,&l); cout<<index<<" : "<<buf<<"\t"<<to<<"\n"; ZeroMemory( buf,128 ); /* l = sizeof(int); index++; RegEnumValue(hKey2,index,buf,&l,0l, NULL,(unsigned char *)number,&l); cout<<index<<" : "<<buf<<"\t"<<number<<"\n"; ZeroMemory( buf,128 ); index++; RegEnumValue(hKey2,index,buf,&l,0l, NULL,(unsigned char *)sleep,&l); cout<<index<<" : "<<buf<<"\t"<<sleep<<"\n"; ZeroMemory( buf,128 ); */ } else { lnRes = RegCreateKeyEx(hKey,"Sms",0,NULL,REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hKey,&Disp); if( lnRes != ERROR_SUCCESS ) return 0; RegSetValueEx(hKey,"FROM",0,REG_SZ,(const unsigned char *)"hello",5); RegSetValueEx(hKey,"TO",0,REG_SZ,(const unsigned char *)"lalala",6); RegSetValueEx(hKey,"Number",0,REG_DWORD,(const unsigned char *)&n,sizeof(n)); RegSetValueEx(hKey,"Sleep",0,REG_DWORD,(const unsigned char *)&s,sizeof(s)); } RegCloseKey(hKey); RegCloseKey(hKey2); return 0; } |
Сообщ.
#2
,
|
|
|
Читай SDK
dwIndex : [in] Specifies the index of the value to retrieve. This parameter should be zero for the first call to the RegEnumValue function and then be incremented for subsequent calls. Понял ??? Нет ??? Тогда int index = 0; индекс д. б. = 0 когда ты первый раз вызываешь ф-ию RegEnumValue У меня работает ! |
Сообщ.
#3
,
|
|
|
А когда во второй раз вызываешь ф-ию опять выдает ошибку "More data is availible"
|
Сообщ.
#4
,
|
|
|
А вообще вот пример
The following example demonstrates the use of the RegQueryInfoKey, RegEnumKey, and RegEnumValue functions. The hKey parameter passed to each function is a handle to an open key. This key must be opened before the function call and closed afterward. // QueryKey - enumerates the subkeys of a given key and the associated // values and then copies the information about the keys and values // into a pair of edit controls and list boxes. // hDlg - dialog box that contains the edit controls and list boxes // hKey - key whose subkeys and values are to be enumerated VOID QueryKey(HWND hDlg, HANDLE hKey) { CHAR achKey[MAX_PATH]; CHAR achClass[MAX_PATH] = ""; // buffer for class name DWORD cchClassName = MAX_PATH; // length of class string DWORD cSubKeys; // number of subkeys DWORD cbMaxSubKey; // longest subkey size DWORD cchMaxClass; // longest class string DWORD cValues; // number of values for key DWORD cchMaxValue; // longest value name DWORD cbMaxValueData; // longest value data DWORD cbSecurityDescriptor; // size of security descriptor FILETIME ftLastWriteTime; // last write time DWORD i, j; DWORD retCode, retValue; CHAR achValue[MAX_VALUE_NAME]; DWORD cchValue = MAX_VALUE_NAME; CHAR achBuff[80]; // Get the class name and the value count. RegQueryInfoKey(hKey, // key handle achClass, // buffer for class name &cchClassName, // length of class string NULL, // reserved &cSubKeys, // number of subkeys &cbMaxSubKey, // longest subkey size &cchMaxClass, // longest class string &cValues, // number of values for this key &cchMaxValue, // longest value name &cbMaxValueData, // longest value data &cbSecurityDescriptor, // security descriptor &ftLastWriteTime); // last write time SetDlgItemText(hDlg, IDE_CLASS, achClass); SetDlgItemInt(hDlg, IDE_CVALUES, cValues, FALSE); SendMessage(GetDlgItem(hDlg, IDL_LISTBOX), LB_ADDSTRING, 0, (LONG) ".."); // Enumerate the child keys, looping until RegEnumKey fails. Then // get the name of each child key and copy it into the list box. SetCursor(LoadCursor(NULL, IDC_WAIT)); for (i = 0, retCode = ERROR_SUCCESS; retCode == ERROR_SUCCESS; i++) { retCode = RegEnumKey(hKey, i, achKey, MAX_PATH); if (retCode == (DWORD)ERROR_SUCCESS) { SendMessage(GetDlgItem(hDlg, IDL_LISTBOX), LB_ADDSTRING, 0, (LONG) achKey); } } SetCursor(LoadCursor (NULL, IDC_ARROW)); // Enumerate the key values. SetCursor(LoadCursor(NULL, IDC_WAIT)); if (cValues) { for (j = 0, retValue = ERROR_SUCCESS; j < cValues; j++) { cchValue = MAX_VALUE_NAME; achValue[0] = '\0'; retValue = RegEnumValue(hKey, j, achValue, &cchValue, NULL, NULL, // &dwType, NULL, // &bData, NULL); // &bcData if (retValue != (DWORD) ERROR_SUCCESS && retValue != ERROR_INSUFFICIENT_BUFFER) { wsprintf (achBuff, "Line:\%d 0 based index = \%d, retValue = \%d, " "ValueLen = \%d", __LINE__, j, retValue, cchValue); MessageBox (hDlg, achBuff, "Debug", MB_OK); } achBuff[0] = '\0'; // Add each value to a list box. if (!lstrlen(achValue)) lstrcpy(achValue, "<NO NAME>"); wsprintf(achBuff, "\%d) \%s ", j, achValue); SendMessage(GetDlgItem(hDlg,IDL_LISTBOX2), LB_ADDSTRING, 0, (LONG) achBuff); } SetCursor(LoadCursor(NULL, IDC_ARROW)); } Microsoft Platform SDK, February 2001 Edition. This content last built on Thursday, February 01, 2001. |