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. RegSetValueEx

RegSetValueEx

Scheduled Pinned Locked Moved C / C++ / MFC
helpwindows-admindebuggingquestionannouncement
10 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.
  • Y Offline
    Y Offline
    Yashusid
    wrote on last edited by
    #1

    Hello, I have one command line application, where i am setting registry key values . LPCTSTR lpResName=GetSourceName(RegFileName); rCode=RegSetValueEx( hDckey, lpResName, 0, REG_SZ, (LPBYTE)RegFileName, (DWORD) (lstrlen(RegFileName)+1)*sizeof(TCHAR) ); This RegSetValueEx sets the values in the registry if i run this exe in "Debug" mode setting lpResName correctly, but if i run in the "Release" mode the "Value Name" for hDckey is some garbage. whereas "Value Data" is correctly set in both the Modes. the GetSourceName returns the correct value for lpResName in both modes. what may be the problem with this ? please help me...

    D 1 Reply Last reply
    0
    • Y Yashusid

      Hello, I have one command line application, where i am setting registry key values . LPCTSTR lpResName=GetSourceName(RegFileName); rCode=RegSetValueEx( hDckey, lpResName, 0, REG_SZ, (LPBYTE)RegFileName, (DWORD) (lstrlen(RegFileName)+1)*sizeof(TCHAR) ); This RegSetValueEx sets the values in the registry if i run this exe in "Debug" mode setting lpResName correctly, but if i run in the "Release" mode the "Value Name" for hDckey is some garbage. whereas "Value Data" is correctly set in both the Modes. the GetSourceName returns the correct value for lpResName in both modes. what may be the problem with this ? please help me...

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

      If the first argument to RegSetValueEx() is garbage, that means the key was not opened correctly.


      "A good athlete is the result of a good and worthy opponent." - David Crow

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      Y 1 Reply Last reply
      0
      • D David Crow

        If the first argument to RegSetValueEx() is garbage, that means the key was not opened correctly.


        "A good athlete is the result of a good and worthy opponent." - David Crow

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        Y Offline
        Y Offline
        Yashusid
        wrote on last edited by
        #3

        not any of the parameters are garbage, after executing this, if i see in the registry the "Value name" is garbage. that too it will set the "Value Name" if i run in "Debug" mode, the problem is there only if i make the exe in "Release" mode.

        D 1 Reply Last reply
        0
        • Y Yashusid

          not any of the parameters are garbage, after executing this, if i see in the registry the "Value name" is garbage. that too it will set the "Value Name" if i run in "Debug" mode, the problem is there only if i make the exe in "Release" mode.

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

          Yashusid wrote:

          not any of the parameters are garbage,

          Then why would you state, "the 'Value Name' for hDckey is some garbage?" If none of the arguments being passed to RegSetValueEx() contain garbage, then what exactly is the problem? :confused:


          "A good athlete is the result of a good and worthy opponent." - David Crow

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          Y 1 Reply Last reply
          0
          • D David Crow

            Yashusid wrote:

            not any of the parameters are garbage,

            Then why would you state, "the 'Value Name' for hDckey is some garbage?" If none of the arguments being passed to RegSetValueEx() contain garbage, then what exactly is the problem? :confused:


            "A good athlete is the result of a good and worthy opponent." - David Crow

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            Y Offline
            Y Offline
            Yashusid
            wrote on last edited by
            #5

            oops sorry if it created confusion....my intention was to convey that... i have a key...for that key i am setting a property... my registry entry for key when u see in registry Name ------------ Type ----Data (garbage here)--- REG_SZ -- test.xml --> ------Release mode test--------------REG_SZ -- test.xml --> ------Debug mode i am getting garbage in Name field for the key...

            D 1 Reply Last reply
            0
            • Y Yashusid

              oops sorry if it created confusion....my intention was to convey that... i have a key...for that key i am setting a property... my registry entry for key when u see in registry Name ------------ Type ----Data (garbage here)--- REG_SZ -- test.xml --> ------Release mode test--------------REG_SZ -- test.xml --> ------Debug mode i am getting garbage in Name field for the key...

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

              Yashusid wrote:

              i am getting garbage in Name field for the key...

              Which would indicate that lpResName is wrong. Try:

              TCHAR s[128];
              _tcscpy(s, GetSourceName(RegFileName));
              rCode = RegSetValueEx(hDckey,
              s,
              0,
              REG_SZ,
              (LPBYTE) RegFileName,
              (DWORD) (_tcslen(RegFileName) + 1) * sizeof(TCHAR));


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              Y 1 Reply Last reply
              0
              • D David Crow

                Yashusid wrote:

                i am getting garbage in Name field for the key...

                Which would indicate that lpResName is wrong. Try:

                TCHAR s[128];
                _tcscpy(s, GetSourceName(RegFileName));
                rCode = RegSetValueEx(hDckey,
                s,
                0,
                REG_SZ,
                (LPBYTE) RegFileName,
                (DWORD) (_tcslen(RegFileName) + 1) * sizeof(TCHAR));


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                Y Offline
                Y Offline
                Yashusid
                wrote on last edited by
                #7

                You are great!!! Thanks a lot!!! It works........ but please help me in understaning why it was setting correctly in "Debug" mode ?

                D 1 Reply Last reply
                0
                • Y Yashusid

                  You are great!!! Thanks a lot!!! It works........ but please help me in understaning why it was setting correctly in "Debug" mode ?

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

                  Yashusid wrote:

                  but please help me in understaning why it was setting correctly in "Debug" mode ?

                  It's not. You just got lucky. Read here for the differences in the two. You should now be concerned as to what GetSourceName() is doing (wrong). If the code is short enough, post it and we can take a look.


                  "A good athlete is the result of a good and worthy opponent." - David Crow

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  Y 1 Reply Last reply
                  0
                  • D David Crow

                    Yashusid wrote:

                    but please help me in understaning why it was setting correctly in "Debug" mode ?

                    It's not. You just got lucky. Read here for the differences in the two. You should now be concerned as to what GetSourceName() is doing (wrong). If the code is short enough, post it and we can take a look.


                    "A good athlete is the result of a good and worthy opponent." - David Crow

                    "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                    Y Offline
                    Y Offline
                    Yashusid
                    wrote on last edited by
                    #9

                    In GetSourceName i am parsing a XML file. char *GetSourceName(char *RegFileName) { LPTSTR lpstrMsg; CoInitialize(NULL); CComPtr spXMLDOM; CComPtr spXMLNode; IXMLDOMAttribute *pIXMLDOMAttribute = NULL; IXMLDOMElement *pIXMLDOMElement = NULL; HRESULT hr = spXMLDOM.CoCreateInstance(__uuidof(DOMDocument)); VARIANT_BOOL bSuccess = false; USES_CONVERSION; _variant_t fileNameValue=T2W(RegFileName); hr = spXMLDOM->load(fileNameValue,&bSuccess); if(!hr) { hr = spXMLDOM->get_documentElement(&pIXMLDOMElement); _variant_t nameValue; if(!hr) { hr = pIXMLDOMElement->getAttribute(CComBSTR(L"source-name"),&nameValue); } if ( nameValue.vt == VT_BSTR ) { USES_CONVERSION; lpstrMsg = W2T(nameValue.bstrVal); } } spXMLDOM.Release(); CoUninitialize(); return lpstrMsg; }

                    D 1 Reply Last reply
                    0
                    • Y Yashusid

                      In GetSourceName i am parsing a XML file. char *GetSourceName(char *RegFileName) { LPTSTR lpstrMsg; CoInitialize(NULL); CComPtr spXMLDOM; CComPtr spXMLNode; IXMLDOMAttribute *pIXMLDOMAttribute = NULL; IXMLDOMElement *pIXMLDOMElement = NULL; HRESULT hr = spXMLDOM.CoCreateInstance(__uuidof(DOMDocument)); VARIANT_BOOL bSuccess = false; USES_CONVERSION; _variant_t fileNameValue=T2W(RegFileName); hr = spXMLDOM->load(fileNameValue,&bSuccess); if(!hr) { hr = spXMLDOM->get_documentElement(&pIXMLDOMElement); _variant_t nameValue; if(!hr) { hr = pIXMLDOMElement->getAttribute(CComBSTR(L"source-name"),&nameValue); } if ( nameValue.vt == VT_BSTR ) { USES_CONVERSION; lpstrMsg = W2T(nameValue.bstrVal); } } spXMLDOM.Release(); CoUninitialize(); return lpstrMsg; }

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

                      The memory that lpstrMsg points to is no longer valid when GetSourceName() goes out of scope. Return a CString or string object instead. Or you could leave it as is, and make the appropriate change to all places that use GetSourceName().


                      "A good athlete is the result of a good and worthy opponent." - David Crow

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      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