Skocz do zawartości

Znowu problem z rejestrem -> RegEnumValue


sleeppower

Recommended Posts

 HKEY hKey;
    RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\jajo",0,KEY_ALL_ACCESS,&hKey);

    TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name
    DWORD    cbName;                   // size of name string 
    TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name
    DWORD    cchClassName = MAX_PATH;  // size of class string 
    DWORD    cSubKeys=0;               // 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, retCode; 
 
    TCHAR  achValue[MAX_VALUE_NAME]; 
    DWORD cchValue = MAX_VALUE_NAME; 
 
    // Get the class name and the value count. 
    retCode = RegQueryInfoKey(
        hKey,                    // key handle 
        achClass,                // buffer for class name 
        &cchClassName,           // size 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
         RegCloseKey(hKey);
        int liczba = (int) cValues;
        LPCTSTR ile;
        LPCTSTR tresc;
        for (int i=0;i<liczba;i++)
           {
            cchValue = MAX_VALUE_NAME;
            achValue[0] = '\0';
            retCode = RegEnumValue(hKey, i, 
                achValue, 
                &cchValue, 
                NULL, 
                NULL,
                NULL,
                NULL);

            MessageBox(hwnd,achValue,"info",MB_OK);
           }
         ile = liczba + "adas";
        MessageBox(hwnd,ile,"Ile",MB_OK);

Czy moze mi ktos powiedziec dlaczego kod ten nie wyswietla mi informacji o tym ile jest wartosci w podanym kluczu i w ogule jakie one maja nazwe ??

Nie wiem co zle zrobilem. Kod ten wyciagnelem od Microsoftu z biblioteki msdn. No chyba ze uzylem zlych funkcji. Prosze pomozcie

Link do komentarza
Udostępnij na innych stronach

Witam troszke przerobilem twoj kod powinno byc ok

//---------------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#define MAX_KEY_LENGTH          255
#define MAX_VALUE_NAME         16000
#define MAX_PATH               16000
//---------------------------------------------------------------------------
int MessageBoxPrintf(CHAR * szCaption,CHAR * szFormat, ...)
{
  va_list wsk_na_liste_arg;     
  CHAR bufor[1024]; 
  va_start(wsk_na_liste_arg,szFormat);
  _vsnprintf(bufor,sizeof(bufor),szFormat,wsk_na_liste_arg);
  va_end(wsk_na_liste_arg);
        return MessageBox(NULL,bufor,szCaption,0);
}
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
 //
        HKEY hKey; 
    if( RegOpenKeyEx(HKEY_CURRENT_USER,"Software\\jajo",0,KEY_ALL_ACCESS,&hKey) ==
                                                                                ERROR_SUCCESS ) 
        { 
    TCHAR    achKey[MAX_KEY_LENGTH];   // buffer for subkey name 
    DWORD    cbName;                   // size of name string 
    TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name 
    DWORD    cchClassName = MAX_PATH;  // size of class string 
    DWORD    cSubKeys=0;               // 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, retCode; 
  
    TCHAR  achValue[MAX_VALUE_NAME]; 
    DWORD cchValue = MAX_VALUE_NAME; 
  
    // Get the class name and the value count. 
    if( (retCode = RegQueryInfoKey( 
        hKey,                    // key handle 
        achClass,                // buffer for class name 
        &cchClassName,           // size 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 
                )==ERROR_SUCCESS)
             {
           //RegCloseKey(hKey); 
           int liczba = (int) cValues; 
           LPCTSTR ile; 
           LPCTSTR tresc; 
           for (int i=0;i<liczba;i++) 
             { 
              cchValue = MAX_VALUE_NAME; 
              achValue[0] = '\0'; 
              retCode = RegEnumValue(hKey, i, 
                achValue, 
                &cchValue, 
                NULL, 
                NULL, 
                NULL, 
                NULL); 

              MessageBox(NULL,achValue,"info",MB_OK); 
             } 
           //ile = liczba + "adas"; 
           //MessageBox(NULL,ile,"Ile",MB_OK);
                         MessageBoxPrintf("Ile","Znaleziono %d wartosci",liczba);
             }
           RegCloseKey(hKey); 
        } 
        return 0;
}
//---------------------------------------------------------------------------

Pozdrawiam

Link do komentarza
Udostępnij na innych stronach

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gość
Odpowiedz...

×   Wkleiłeś zawartość bez formatowania.   Usuń formatowanie

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Utwórz nowe...