Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Beginner registry problem

Beginner registry problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialwindows-adminjsonhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Scozturk
    wrote on last edited by
    #1

    Hi! I am trying to use the registry with win32 api c++. But I have difficulties using the RegQueryValue functions. I found some examples on the net but they all use CString and I cant use it because I dont write in MFC... Can someone write an example? ( if possible the whole thing how to get a value?) Thanks in advance! Well... I am a beginner ...

    D D 2 Replies Last reply
    0
    • S Scozturk

      Hi! I am trying to use the registry with win32 api c++. But I have difficulties using the RegQueryValue functions. I found some examples on the net but they all use CString and I cant use it because I dont write in MFC... Can someone write an example? ( if possible the whole thing how to get a value?) Thanks in advance! Well... I am a beginner ...

      D Offline
      D Offline
      Dominik Reichl
      wrote on last edited by
      #2

      A very simple example how to get the Windows product name:

      HKEY hKey;
      TCHAR tszProductName[128];
      DWORD dwBufSize = 128;
      
      RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion"), 0, KEY_READ, &hKey);
      RegQueryValueEx(hKey, _T("ProductName"), NULL, REG_SZ, (LPBYTE)tszProductName, &dwBufSize);
      RegCloseKey(hKey);
      
      printf("Windows Product Name: ");
      printf(tszProductName);
      

      Hope that helps :-D Dominik


      _outp(0x64, 0xAD); and __asm mov al, 0xAD __asm out 0x64, al do the same... but what do they do?? ;) (doesn't work on NT)

      1 Reply Last reply
      0
      • S Scozturk

        Hi! I am trying to use the registry with win32 api c++. But I have difficulties using the RegQueryValue functions. I found some examples on the net but they all use CString and I cant use it because I dont write in MFC... Can someone write an example? ( if possible the whole thing how to get a value?) Thanks in advance! Well... I am a beginner ...

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Scolinks wrote: But I have difficulties using the RegQueryValue functions. I found some examples on the net but they all use CString and I cant use it because I dont write in MFC... There are plenty of MSDN examples that do not use MFC. Here's but one:

        #define RTN_UNKNOWN 0
        #define RTN_SERVER 1
        #define RTN_WORKSTATION 2
        #define RTN_NTAS 3
        #define RTN_ERROR 13

        DWORD GetWindowsVariant(void)
        {
        #define MY_BUFSIZE 32 // Arbitrary initial value.
        // Dynamic allocation will be used.
        HKEY hKey;
        TCHAR szProductType[MY_BUFSIZE];
        DWORD dwBufLen = MY_BUFSIZE;
        LONG lRet;

        if(RegOpenKeyEx(HKEY\_LOCAL\_MACHINE,
            TEXT("SYSTEM\\\\CurrentControlSet\\\\Control\\\\ProductOptions"),
                        0,
                        KEY\_QUERY\_VALUE,
                        &hKey) != ERROR\_SUCCESS) return RTN\_ERROR;
        
        lRet = RegQueryValueEx(hKey,
                        TEXT("ProductType"),
                        NULL,
                        NULL,
                        (LPBYTE)szProductType,
                        &dwBufLen);
        
        RegCloseKey(hKey);
        
        if(lRet != ERROR\_SUCCESS) return RTN\_ERROR;
        
        // check product options, in order of likelihood
        if(lstrcmpi(TEXT("WINNT"), szProductType) == 0) 
             return RTN\_WORKSTATION;
        if(lstrcmpi(TEXT("SERVERNT"), szProductType) == 0) 
             return RTN\_SERVER;
        if(lstrcmpi(TEXT("LANMANNT"), szProductType) == 0) 
             return RTN\_NTAS;
        // else return "unknown variant" code
        else return RTN\_UNKNOWN;
        

        }

        Here are some searches returned from Google: http://www.windowsitlibrary.com/Content/69/07/1.html http://www.geocities.com/merijn\_bellekom/new/win9xcpu.html http://www.pc-magazin.de/common/forum/forum.php?id=30000624&forum=30&dsp\_start=120&expand=1&suchwort=


        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups