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