[C] error in RegGetValue

This is a discussion on [C] error in RegGetValue within the Windows Programming forums, part of the Platform Specific Boards category; Hi to all.. Code: #include <stdio.h> #include <stdlib.h> #include <windows.h> #include <string.h> .. .. .. char ControllaCartelleStartup(char chiave[]){ HKEY hKey; ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    161

    [C] error in RegGetValue

    Hi to all..

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <string.h>
    
    ..
    ..
    ..
    
    char ControllaCartelleStartup(char chiave[]){
        
         HKEY hKey;
         
         char folder[MAX_KEY];
              
         if((RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                              "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
                              0,
                              KEY_ALL_ACCESS,
                              &hKey))!= ERROR_SUCCESS){
                                   
                              MessageBox(NULL,
                                         "Errore nel leggere il registro.\n",
                                         "Errore in lettura:", // Titolo del messagebox
                                          MB_OK);
                         }//End errore nell'aprire reg
                         
                         RegGetValue(hKey,
                                     "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
                                     "Common Startup",
                                     RRF_RT_ANY,
                                     NULL,
                                     folder,
                                     sizeof(folder));
                                     
       
    }//end ControllaCartelleStartup
    why why and why RRF_RT_ANY is not recognized??

    776 C:\Programmi\Dev-Cpp\Progetti\Enumera Valori\main.c `RRF_RT_ANY' undeclared (first use in this function)
    thanx

    documentation : RegGetValue

    dwFlags
    [in] Restricts the data type of value to be queried. If the data type of the value does not meet this criteria, the function fails. This parameter can be one of the following values.

    RRF_RT_ANY No type restriction.
    Last edited by BianConiglio; 10-13-2004 at 10:28 AM.
    This forum is the best one I've ever seen. Great ppl, great coders

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Are you running Windows Server 2003 SP1 (see the 'Requirements' section at the foot of the GetRegValue msdn page)?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    DAMN!!!! what should I do on Xp/9x ?

    RegEnumValue untill I find the wanted value? booooooooring!!
    This forum is the best one I've ever seen. Great ppl, great coders

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    RegEnumValue untill I find the wanted value?
    Sounds like a good idea to me.

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,680
    Here is another solution

    gg

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Why can't you use RegQueryValueEx()? Even easier is SHGetValue():
    Code:
    {
       DWORD dwType,
             dwSize = sizeof(folder) - 1;
    
       if (SHGetValue(HKEY_LOCAL_MACHINE,
                  TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"),
                  TEXT("Common Startup"),
                  &dwType,
                  folder,
                  &dwSize) != ERROR_SUCCESS)
        {
            // Error!
        }
    
        /* Make sure the returned value is nul terminated. */
        folder[dwSize / sizeof(folder[0])] = TEXT('\0');
    }
    Last edited by anonytmouse; 10-15-2004 at 12:23 AM. Reason: Removed extra semicolon.

  7. #7
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    thanx guys
    This forum is the best one I've ever seen. Great ppl, great coders

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    (quite) working code:

    Code:
    char ControllaCartelleStartup(void){
    
       char folder[MAX_KEY];
       
       DWORD dwType,
             dwSize = sizeof(folder) - 1;
    
       if (SHGetValue(HKEY_LOCAL_MACHINE,
                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
                  "Common Startup",
                  &dwType,
                  folder,
                  &dwSize) != ERROR_SUCCESS);
        {
        MessageBox(NULL,
                   "Error.\n",
                   "Error while reading:", // Titolo del messagebox
                   MB_OK);
        }
    
        folder[dwSize / sizeof(folder[0])] = TEXT('\0');
        
        printf("%s\n", folder);
    }
    As I said it is a quite-working code.. SHGetValue returns something != ERROR_SUCCESS. Anyway "folder" contains the wanted common startup link.. So every time I call the function I have an Error PopUp.. Any suggestion about why it doesn't return ERROR_SUCCESS?
    This forum is the best one I've ever seen. Great ppl, great coders

  9. #9
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    I thought it was SHGet.. so I rewrited it a bit :

    Code:
    char BufferCartellaCommonStartup(void){
    
       HKEY hKey;
      
       char folder[MAX_KEY];
       
       DWORD dwSize = sizeof(folder) - 1;
    
      if((RegOpenKeyEx(HKEY_LOCAL_MACHINE,
                       "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
                       0,
                       KEY_ALL_ACCESS,
                       &hKey))!= ERROR_SUCCESS){
                               
            MessageBox(NULL,
                       "Errore nel leggere il registro.\n",
                       "Errore in lettura:", // Titolo del messagebox
                       MB_OK);
            } 
            
       if (RegQueryValueEx(hKey,
                           "Common Startup",
                           NULL,
                           NULL,
                           folder,
                           &dwSize) != ERROR_SUCCESS);   
            
            {MessageBox(NULL,
                       "Errore nel leggere il link al CommonStartup.\n",
                       "Errore in lettura:", // Titolo del messagebox
                       MB_OK);
            }
    
        RegCloseKey(hKey);
         
        folder[dwSize / sizeof(folder[0])] = '\0';
        
        printf("%s\n", folder);
        
    }//end ControllaCartelleStartup
    and again the same.. it works (I get the common startup link) but it appears again the error message box... RegQueryValueEx seems to fail
    This forum is the best one I've ever seen. Great ppl, great coders

  10. #10
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Code:
      if (SHGetValue(HKEY_LOCAL_MACHINE,
                  "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Expl  orer\\Shell Folders",
                  "Common Startup",
                  &dwType,
                  folder,
                  &dwSize) != ERROR_SUCCESS); // <<------ You don't want this! 
    Sorry mate, this was a typo in my original post. The semicolon ends the if clause. Some compilers will give a warning about this oddly placed semicolon.
    Last edited by anonytmouse; 10-15-2004 at 12:33 AM.

  11. #11
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    hahah yesterday I lost 30 mins for this stupid thing!!
    thanx for the solution, I feel stupid
    This forum is the best one I've ever seen. Great ppl, great coders

  12. #12
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    I've just realised that you shouldn't be querying the registry for this information anyway. This is the correct method to get a shell folder path:
    Code:
    TCHAR folder[MAX_PATH];
    SHGetSpecialFolderPath(NULL, folder, CSIDL_COMMON_STARTUP, TRUE);

  13. #13
    Registered User
    Join Date
    Mar 2004
    Posts
    161
    ah excellent!!!!
    This forum is the best one I've ever seen. Great ppl, great coders

  14. #14
    Registered User
    Join Date
    Mar 2009
    Posts
    1
    ooh mayi god...how is this working??
    i got this error
    error C2664: 'RegQueryValueExA' : cannot convert parameter 5 from 'char *' to 'LPBYTE'

    5th parameter you are passing is char*, but LPBYTE exptected...

    ~calvin

  15. #15
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,823
    Cast it to BYTE* and it will work.
    BYTE is really unsigned char anyway.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [C] Setbits function
    By Tool in forum C Programming
    Replies: 25
    Last Post: 07-31-2014, 02:05 PM
  2. [C] keeping a TreeView always expanded or collapsed
    By pc2-brazil in forum Windows Programming
    Replies: 2
    Last Post: 08-28-2008, 04:46 PM
  3. [C#] howto compare combobox-item with DataSet
    By Jelte in forum C# Programming
    Replies: 3
    Last Post: 08-26-2008, 06:25 PM
  4. [C#] How to use This Array
    By Jelte in forum C# Programming
    Replies: 6
    Last Post: 08-12-2008, 03:29 AM
  5. RegGetValue' : undeclared identifier?
    By Sephiroth222 in forum C++ Programming
    Replies: 9
    Last Post: 09-25-2005, 05:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21