|
So what's failing?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Did you get any error or null result?
|
|
|
|
|
In the registry, the current user would be the account you're running from -
the system account.
See LocalSystem Account[^]
Are you trying to get the name of the current logged-on user
from a service running in a system account?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Did you look into this[^]?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
I have 80 lines in a text file with 30 values each line separated by a white space (some are ints, doubles and another strings). I have made a routine with fscanf() to read each line and store the values I need. But I only need 7 of the 30 values to store them in an array, so , for instance, I want to store the first data, and the second and third, then skip the next 4 values, store the next and so on.
Is there a way to skip entries with fscanf function?
Thank you.
|
|
|
|
|
José Luis Sogorb wrote: Is there a way to skip entries with fscanf function?
Oh yes. Simply read unwanted entries and then discard them.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
Yes, but I have to read the unwanted data and assign them a place to store them and then discard?
There are 23 unwanted entries in each line, and there are 80 lines. This is what I dont want to do.
|
|
|
|
|
Well you haven't accumulate the garbage data. You may use a restricted set of variables (one for each different data type).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
What's wrong with:
for (int x = 0; x < 80; x++)
{
fscanf(...);
if (some_condition)
{
}
}
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
<br />
for (int i=0; i<1000; i++)<br />
{<br />
if(FALSE == LoadBitmap(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDB_BITMAP)))<br />
{<br />
AfxMessageBox("error");<br />
} <br />
<br />
}<br />
these code would error when i around six hundred, maybe 632, may be 654...
why?
|
|
|
|
|
Call GetLastError to get additional info.
Anyway, the following maybe an hint (from MSDN http://msdn2.microsoft.com/en-us/library/ms532309.aspx[^])
If the bitmap pointed to by the lpBitmapName parameter does not exist or there is insufficient memory to load the bitmap, the function fails.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|
|
|
Why are you wanting to load an image 1000 times?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Can you more explain why you use of this loop and also you can use of CBitmap::Load.
|
|
|
|
|
i have a application based on tray icon
in that tray we used popup menu it contains minimise,maximize ;
when i click the maximize buton system menus r not shown like FILE,EDIT ..
can u help me
thanks
k.guru moorthy
|
|
|
|
|
I cannot understand what you said.
|
|
|
|
|
Hello everyone,
In the MSDN volatile sample,
http://msdn2.microsoft.com/en-us/library/12a04hfd(VS.80).aspx
I do not understand what is the purpose of the sample. I have tried to remove the keyword volatile, and the result is the same.
Any ideas?
thanks in advance,
George
|
|
|
|
|
Did you try in the release build?
« Superman »
|
|
|
|
|
Sure, I tried. Same result. Any ideas what is the purpose of the MSDN sample?
regards,
George
|
|
|
|
|
The qualifier volatile is to tell the compiler that the variable may be accessed/changed by any source, and the value of this variable should not be assumed by the compiler for optimization.
To see the effect of volatile , follow the below code, and have VC++ generate an ASM listing file, and compile in Release mode. You will see the difference!!
int v = 5;
int volatile m = 3;
int i;
for(i = 0; i < 10; i++) {
if(v == 5) { break; }
}
for(i = 0; i < 10; i++) {
if(m == 3) { break; }
}
Maxwell Chen
|
|
|
|
|
Cool, Maxwell!
Here is the generated assembly code. Could you show a more practical sample or describe what is the purpose of MSDN sample please? Thanks.
1311006 add byte ptr [eax],al
int i;
for(i = 0; i < 10; i++)
{
if(v == 5)
{
break;
}
}
for(i = 0; i < 10; i++)
01311008 xor eax,eax
0131100A lea ebx,[ebx]
{
if(m == 3)
01311010 mov ecx,dword ptr [esp]
01311013 cmp ecx,ecx
01311015 je main+1Dh (131101Dh)
01311017 inc eax
01311018 cmp eax,0Ah
0131101B jl main+10h (1311010h)
{
break;
}
}
}
regards,
George
|
|
|
|
|
The example in MSDN is interesting! (My computer at work can not paste text in CP, but the one at home can. So I can copy and paste. )
Please read my comments in the code for details.
The result:
Critical Data = 1
Success
volatile bool Sentinel = true;
int CriticalData = 0;
unsigned ThreadFunc1( void* pArguments ) {
while (Sentinel) {
Sleep(0);
}
cout << "Critical Data = " << CriticalData << endl;
return 0;
}
unsigned ThreadFunc2( void* pArguments ) {
Sleep(2000);
CriticalData++;
Sentinel = false;
return 0;
}
int main() {
HANDLE hThread1, hThread2;
DWORD retCode;
hThread1 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&ThreadFunc1,
NULL, 0, NULL);
hThread2 = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&ThreadFunc2,
NULL, 0, NULL);
if (hThread1 == NULL || hThread2 == NULL) {
cout << "CreateThread failed." << endl;
return 1;
}
retCode = WaitForSingleObject(hThread1,3000);
CloseHandle(hThread1);
CloseHandle(hThread2);
if (retCode == WAIT_OBJECT_0 && CriticalData == 1 )
cout << "Success" << endl;
else
cout << "Failure" << endl;
}
Maxwell Chen
|
|
|
|
|
Thanks Maxwell,
This is the code which makes me confused.
while (Sentinel)
{
Sleep(0);
}
I think when thread1 enters into the while loop, the value of Sentinel is true and it should invokes Sleep(0). Sleep(0) will wait until there is a signal. But in the program no other parties send thread1 a signal, and I think thread1 will wait forever to cause deadlock.
The only reason why there is no deadlock is when thread1 checks variable Sentinel, it happens to be false changed by thread2.
Anything wrong with my previous analysis? Please feel free to correct me.
regards,
George
|
|
|
|
|
Anything wrong with my previous analysis? Please feel free to correct me.
Yes, you're wrong in the following assumption:
George_George wrote: Sleep(0) will wait until there is a signal.
because MSDN http://msdn2.microsoft.com/en-us/library/ms686298.aspx[^] states:
Parameters
dwMilliseconds
The minimum time interval for which execution is to be suspended, in milliseconds.
A value of zero causes the thread to relinquish the remainder of its time slice to any other thread of equal priority that is ready to run. If there are no other threads of equal priority ready to run, the function returns immediately, and the thread continues execution.
i.e. Sleeps(0) , in absence of signals, doesn't wait forever.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
[my articles]
|
|
|
|