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. RegQueryValueEx + DWORD problem

RegQueryValueEx + DWORD problem

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
2 Posts 2 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hi I need to use 'RegQueryValueEx(...)' to retrieve a subkey's value. CString strReturnWaarde(""); long lResult=0L; DWORD dwLength=0L, dwType=0L; TCHAR keyValue[256]; HKEY SrcKey; if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\COMPANY\\PRODUCT\\" + strKey, 0, KEY_READ, &SrcKey) == ERROR_SUCCESS ) { dwLength = 256*sizeof(TCHAR); lResult = RegQueryValueEx(SrcKey,strKeyName, NULL, &dwType, (BYTE*)keyValue, &dwLength ); if ( lResult == ERROR_SUCCESS ) { strReturnWaarde = CString(keyValue); } RegCloseKey(SrcKey); } ::AfxMessageBox(strReturnWaarde); This code works when getting Text but not when trying to get numbers (DWORD). What is wrong with it? :x I replaced the 'strReturnWaarde' as ' int iReturnWaarde' and without the conversation to CString ofcourse. Greetings Jens

    G 1 Reply Last reply
    0
    • A Anonymous

      Hi I need to use 'RegQueryValueEx(...)' to retrieve a subkey's value. CString strReturnWaarde(""); long lResult=0L; DWORD dwLength=0L, dwType=0L; TCHAR keyValue[256]; HKEY SrcKey; if ( RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\COMPANY\\PRODUCT\\" + strKey, 0, KEY_READ, &SrcKey) == ERROR_SUCCESS ) { dwLength = 256*sizeof(TCHAR); lResult = RegQueryValueEx(SrcKey,strKeyName, NULL, &dwType, (BYTE*)keyValue, &dwLength ); if ( lResult == ERROR_SUCCESS ) { strReturnWaarde = CString(keyValue); } RegCloseKey(SrcKey); } ::AfxMessageBox(strReturnWaarde); This code works when getting Text but not when trying to get numbers (DWORD). What is wrong with it? :x I replaced the 'strReturnWaarde' as ' int iReturnWaarde' and without the conversation to CString ofcourse. Greetings Jens

      G Offline
      G Offline
      G Steudtel
      wrote on last edited by
      #2

      Hi, The problem is in typcasting. It is right to cast the type into a pointer to byte (LPBYTE) but then you have to provide the adress of your DWORD variable too. Also keyValue must be of type DWORD. Like: DWORD dwType,dwLength,keyValue; ... RegResult=::RegQueryValueEx(SrcKey,strKeyName,NULL,&dwType,(LPBYTE)&(keyValue),&dwLength); You may not use a TCHAR buffer array for this purpose. I couldn't find a way to cast this in a DWORD.;) Regards G. Steudtel

      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