|
I think if he tried the code I posted, the wait timeout would not occur. Essentially what is probably happening is that the value of the BOOL is being retrieved from L1 or L2 cache because the thread is doing nothing else to the stack/registers. The atomic operation would prevent the cache hit.
-Randor (David Delaune)
|
|
|
|
|
tried your code,but i don't really understand this part:
while(InterlockedCompareExchange(piLock,1,1))
what does it do? and I need to manually terminate the thread, but this while loop doesn't seem to do that...
|
|
|
|
|
See this article for shutdown/pause examples.
"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
|
|
|
|
|
Hello every one!
I've written a program to collect some information about currently opened processes in the system; When i executed it within IDE(Ctrl+F5), there was nothing wrong with it; But when i tried to execute it alone(within Windows Explorer, we had got some problem with function OpenProcess, that's it'd returned NULL and when i tried to access last error code using GetLastError() function, it said: ERROR_ACCESS_DENIED!
What kind of diffrence is there between theses two scenario (execuing via IDE and executing alone (via OS))? And what can i do to access information about various processes with diffrent access rights?
|
|
|
|
|
try enabling debug privileges.
Something like:
<br />
HANDLE hToken=INVALID_HANDLE_VALUE;<br />
<br />
if (hToken || OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hToken))<br />
{<br />
TOKEN_PRIVILEGES tp;<br />
tp.PrivilegeCount = 1;<br />
SetLastError(0);<br />
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &tp.Privileges[0].Luid);<br />
tp.Privileges[0].Attributes = E_PRIVILEGE_ENABLED;<br />
SetLastError(0);<br />
AdjustTokenPrivileges(hToken, FALSE, &tp, sizeof(tp), NULL, NULL);<br />
}<br />
-Randor (David Delaune)
|
|
|
|
|
Usef Marzbani wrote: ...we had got some problem with function OpenProcess...
What does the call to that function look like?
"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
|
|
|
|
|
I recently added a manifest file to the resource for a program to enable it to be drawn with WinXP themes. One thing I have noticed is that the data in a report view list control is being drawn 2 pixels higher and 2 pixels to the right. I have no objection with this, but I usually use custom draw facilities to set the background colour of a line and I paint the background myself the same colour as the first line's background colour. I now find I've got an ugly vertical white line 2 pixels wide to the left of the data. Anybody any idea how to get rid of it?
I've put sample images at good.jpg for the program before I added the manifest and
bad.jpg for after I added it.
|
|
|
|
|
Hello,
I'm following this tutorial for MFC/C++: http://www.codeproject.com/listctrl/creportctrl.asp . This concerns implementing a CListCtrl-derived class with certain "out of the box" functionality that the MFC "report style" CListCtrl lacks. For example, the user can re-order items by clicking on a column header, and, optionally, the programmer can include a checkbox beside nodes.
I created a dialog that uses this CReportCtrl, but that didn't work - I could see entries, but there were no headings, and no lines, even though I'd called the SetGridLines() member function.
I then called ModifyStyle(0,LVS_REPORT), which is meant to be used with the CListCtrl base class. Now, CReportCtrl was mostly fully functional. The column headers were visible. When I called SetGridLines(TRUE), gridlines appeared. However, one last important piece of functionality was still missing: I couldn't re-order column entries by clicking on a column header, in the style of windows explorer.
I can confirm that the function(OnColumnClick) is called when I click on a column header. I can confirm that _CompareFunction is *not* being called.
Most recently, I changed the List dialog item properties view from "Icon" to "Report". This had the effect of causing all sorts of errors such as "Unhandled exception at 0x78144580 in Lustre.exe: 0xC0000005: Access violation reading location 0x0aa30324" when I debugged. Apparently, this was the offending code:
int CReportCtrl::InsertItem(int nIndex, LPCTSTR pszText, ...)<br />
{<br />
const int iIndex = CListCtrl::InsertItem(nIndex, pszText);<br />
<br />
if (!_IsValidIndex(iIndex))<br />
return iIndex;<br />
<br />
CStringArray arr;<br />
arr.Add(pszText);<br />
<br />
va_list list;<br />
va_start(list, pszText);<br />
<br />
for(int iColumn = 1; iColumn < GetColumnCount(); iColumn++)<br />
{<br />
LPCTSTR lpsz = va_arg(list, LPCTSTR);<br />
CString str = (lpsz == NULL) ? _T("") : lpsz;<br />
arr.Add(str);
CListCtrl::SetItemText(iIndex, iColumn, str);<br />
}<br />
<br />
va_end(list);<br />
<br />
_AssignNewItemData(iIndex, arr.GetData(), arr.GetSize());<br />
<br />
return iIndex;<br />
}
I'd be very grateful if someone could point me in the right direction. I suspect this has something to do with the fact that I am using visual studio 2005, and this tutorial was created with visual studio 6,
Thanks a lot,
Sternocera ( ( (
|
|
|
|
|
Sternocera wrote: arr.Add(str); // This particular line was flagged by visual studio
As what?
"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
|
|
|
|
|
You know when you're debugging and you get the little green arrow that highlights the offending code? Thats what I meant by flagged.
|
|
|
|
|
So what is the value of str at that point?
"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
|
|
|
|
|
At that juncture, the value of str is "‹ÿU‹ìV‹u÷Æ"
Hope that helps
|
|
|
|
|
Sternocera wrote: for(int iColumn = 1; iColumn < GetColumnCount(); iColumn++)
{
LPCTSTR lpsz = va_arg(list, LPCTSTR);
If you are not 100% sure you know what you are doing that is a very very bad idea.... it might be anyway
|
|
|
|
|
I didn't write the code. As stated, it is from a codeproject tutorial. Could you elaborate on why it is (potentially)such a bad idea?
|
|
|
|
|
Sternocera wrote: it is from a codeproject tutorial.
Which one? Post a link.
Sternocera wrote: Could you elaborate on why it is (potentially)such a bad idea?
The arg list is not infinite and the function relies on the number of columns matching the number of arguments. If they aren't, which appears to be what you are experiencing, I don't believe the test for NULL is not going to work because that is not how va_arg() works. I believe it will just keep reading memory beyond the end of what was actually provided by the caller.
|
|
|
|
|
The codeproject tutorial in question is http://www.codeproject.com/listctrl/creportctrl.asp[^]
I think you're right about it reading memory beyond its bounds. That would be consistent with str cotaining all that garbage. Could you suggest a solution?
Regards,
Sternocera
|
|
|
|
|
Sternocera wrote: Could you suggest a solution?
Call InsertItem() with a count of the number of variable arguments.
"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
|
|
|
|
|
I'm currently calling InsertItem in this fashion:
SampleReportCtrl.InsertItem(0, _T("test1"));
SampleReportCtrl.InsertItem(1, _T("test2"));
SampleReportCtrl.InsertItem(2, _T("test3"));
How could I call InsertItem() with a count of the number of variable arguments?
Thanks
Sternocera
|
|
|
|
|
Sternocera wrote: How could I call InsertItem() with a count of the number of variable arguments?
SampleReportCtrl.InsertItem(0, 1, _T("test1"));
SampleReportCtrl.InsertItem(1, 1, _T("test2"));
SampleReportCtrl.InsertItem(2, 1, _T("test3"));
"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
|
|
|
|
|
|
Sternocera wrote: There are 3 columns
But you were calling InsertItem() with only one variable argument, hence the 1 that I supplied. If you wanted to call it with three arguments, you would need to do:
SampleReportCtrl.InsertItem(0, 3, _T("test1"), _T("test2"), _T("test3")); You would obviously need to change the method's signature for this to work properly. Your solution of making the last argument 0 is probably a bit cleaner, however.
"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
|
|
|
|
|
InsertItem is an overloaded function. I found by calling it in this manner:
SampleReportCtrl.InsertItem(0, _T("test1"),0);
SampleReportCtrl.InsertItem(1, _T("test2"),0);
SampleReportCtrl.InsertItem(2, _T("test3"),0);
everything worked nicely. Thanks!
|
|
|
|
|
Sternocera wrote: I found by calling it in this manner:
SampleReportCtrl.InsertItem(0, _T("test1"),0);
SampleReportCtrl.InsertItem(1, _T("test2"),0);
SampleReportCtrl.InsertItem(2, _T("test3"),0);
everything worked nicely.
Which creates 3 rows and 1 column.
"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
|
|
|
|
|
Yes. Thanks for your help, David.
|
|
|
|
|
how many columns are there in the list control?
|
|
|
|