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. What is wrong in this piece of code...

What is wrong in this piece of code...

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
7 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.
  • E Offline
    E Offline
    Exceter
    wrote on last edited by
    #1

    private: CButton Comps[5]; CRegKey reg; ....... (reg.Open(HKEY_LOCAL_MACHINE, "Software\\ShutDown") == ERROR_SUCCESS ) { reg.QueryDWORDValue("NumOfComputers", num); POINT pt1, pt2; pt1.x = 20; pt1.y = 20; pt2.x = 120; pt2.y = 50; ULONG Cname_sz; char buf[20]; CString cn, Cname; for (int i=0; i< maxComps; i++) { CRect tmpRect(pt1, pt2); LPCTSTR val = (LPCTSTR) itoa(i, buf, 10); int len = Cname.GetLength(); reg.QueryStringValue(val, (Cname.GetBuffer(len)), &Cname_sz); Comps[i].Create(_T(Cname), WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, tmpRect, this, 1210+i); pt1.y += 30; pt2.y += 30; Cname.Empty(); } ......... Best Regards, exceter

    T 1 Reply Last reply
    0
    • E Exceter

      private: CButton Comps[5]; CRegKey reg; ....... (reg.Open(HKEY_LOCAL_MACHINE, "Software\\ShutDown") == ERROR_SUCCESS ) { reg.QueryDWORDValue("NumOfComputers", num); POINT pt1, pt2; pt1.x = 20; pt1.y = 20; pt2.x = 120; pt2.y = 50; ULONG Cname_sz; char buf[20]; CString cn, Cname; for (int i=0; i< maxComps; i++) { CRect tmpRect(pt1, pt2); LPCTSTR val = (LPCTSTR) itoa(i, buf, 10); int len = Cname.GetLength(); reg.QueryStringValue(val, (Cname.GetBuffer(len)), &Cname_sz); Comps[i].Create(_T(Cname), WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX, tmpRect, this, 1210+i); pt1.y += 30; pt2.y += 30; Cname.Empty(); } ......... Best Regards, exceter

      T Offline
      T Offline
      Toni78
      wrote on last edited by
      #2

      Exceter wrote: reg.QueryDWORDValue("NumOfComputers", num); Exceter wrote: reg.QueryStringValue(val, (Cname.GetBuffer(len)), &Cname_sz); These functions don't exist (I am talking about VC++ 6.0, I don't know about .NET). You need to use QueryValue. I didn't check the rest of the code. You need to compile it and read the errors that the compiler will give you. I am sure that the compiler will complain very loudly by saying that QueryDWORDValue does not exist, and the same thing can be said about the rest of the code. // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

      E 1 Reply Last reply
      0
      • T Toni78

        Exceter wrote: reg.QueryDWORDValue("NumOfComputers", num); Exceter wrote: reg.QueryStringValue(val, (Cname.GetBuffer(len)), &Cname_sz); These functions don't exist (I am talking about VC++ 6.0, I don't know about .NET). You need to use QueryValue. I didn't check the rest of the code. You need to compile it and read the errors that the compiler will give you. I am sure that the compiler will complain very loudly by saying that QueryDWORDValue does not exist, and the same thing can be said about the rest of the code. // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

        E Offline
        E Offline
        Exceter
        wrote on last edited by
        #3

        reg.QueryDWORDValue("NumOfComputers", num); reg.QueryStringValue(val, (Cname.GetBuffer(len)), &Cname_sz); These functions exists in VC7, they do not make the error. The error is I think with the CButton array, because if I make a sinlge button (not array) the program works, that is, the dialog and the button are created.

        T 1 Reply Last reply
        0
        • E Exceter

          reg.QueryDWORDValue("NumOfComputers", num); reg.QueryStringValue(val, (Cname.GetBuffer(len)), &Cname_sz); These functions exists in VC7, they do not make the error. The error is I think with the CButton array, because if I make a sinlge button (not array) the program works, that is, the dialog and the button are created.

          T Offline
          T Offline
          Toni78
          wrote on last edited by
          #4

          reg.QueryStringValue(val,(Cname.GetBuffer(len)), &Cname_sz);
          Comps[i].Create(_T(Cname),
          WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,
          tmpRect, this, 1210+i);
          pt1.y += 30; pt2.y += 30;
          Cname.Empty();

          I do see something wrong with your code(but then again it is 3:43 am for me and I am very tired). Again I have never used VC7 so I could be wrong again, but a call to GetBuffer should be followed by a call to ReleaseBuffer (before you can use any other CString functions). Therefor, after QueryStringValue make a call to ReleaseBuffer. Exceter wrote: These functions exists in VC7, they do not make the error. I didn't know that, that's why I refered VC6.:) // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

          E 1 Reply Last reply
          0
          • T Toni78

            reg.QueryStringValue(val,(Cname.GetBuffer(len)), &Cname_sz);
            Comps[i].Create(_T(Cname),
            WS_CHILD|WS_VISIBLE|BS_AUTOCHECKBOX,
            tmpRect, this, 1210+i);
            pt1.y += 30; pt2.y += 30;
            Cname.Empty();

            I do see something wrong with your code(but then again it is 3:43 am for me and I am very tired). Again I have never used VC7 so I could be wrong again, but a call to GetBuffer should be followed by a call to ReleaseBuffer (before you can use any other CString functions). Therefor, after QueryStringValue make a call to ReleaseBuffer. Exceter wrote: These functions exists in VC7, they do not make the error. I didn't know that, that's why I refered VC6.:) // Afterall, I realized that even my comment lines have bugs When one cannot invent, one must at least improve (in bed).-My latest fortune cookie

            E Offline
            E Offline
            Exceter
            wrote on last edited by
            #5

            Yes, I gorgot to Release the buffer, thanks. but, now I have an error in ReleaseBuffer()!!! the error message is: file:c:/...vc7//atlmfc/include/atlsimpstr.h line: 718 Expression: nLength <= GetData()->nAllocLength

            S 1 Reply Last reply
            0
            • E Exceter

              Yes, I gorgot to Release the buffer, thanks. but, now I have an error in ReleaseBuffer()!!! the error message is: file:c:/...vc7//atlmfc/include/atlsimpstr.h line: 718 Expression: nLength <= GetData()->nAllocLength

              S Offline
              S Offline
              Steve S
              wrote on last edited by
              #6

              Could well be a buffer overrun then. When you do GetBuffer() instead of using the length, try specifying something like 512. Steve S [This signature space available for rent]

              E 1 Reply Last reply
              0
              • S Steve S

                Could well be a buffer overrun then. When you do GetBuffer() instead of using the length, try specifying something like 512. Steve S [This signature space available for rent]

                E Offline
                E Offline
                Exceter
                wrote on last edited by
                #7

                Greate, it works. thanx. but, how to make it to work with Getbuffer()? well, in this program I know the estimated sizes of the buffer, but if it exceeds the buffer size I've shoen there?

                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