|
Just as an example, you can add the following to a .reg file and merge it into your registry. Then from Explorer, right-click on your CD drive containing an audio CD and you'll see the newly added option.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\AudioCD\shell\calc]
@="&Calc"
[HKEY_CLASSES_ROOT\AudioCD\shell\calc\command]
@="calc.exe" For non-audio CDs, a minor change:
[HKEY_CLASSES_ROOT\Drive\shell\paint]
@="&Paint"
[HKEY_CLASSES_ROOT\Drive\shell\paint\command]
@="mspaint.exe"
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
i simply typed following in file and named it with .reg extention.and i runed it. it showed an error.
why?
what is format for registry file?
i maked entry directly in registry in following path.
[HKEY_CLASSES_ROOT\Drive\shell\paint]@="&Paint" [HKEY_CLASSES_ROOT\Drive\shell\paint\command]@="mspaint.exe
but the menu also appears when right click a drive ( for example c . i want only in cd-rom's context menu.
|
|
|
|
|
anandforu wrote:
i simply typed following in file and named it with .reg extention.and i runed it. it showed an error.
why?
what is format for registry file?
You missed the following at the top of the file:
Windows Registry Editor Version 5.00
anandforu wrote:
but the menu also appears when right click a drive ( for example c. i want only in cd-rom's context menu.
I currently do not know of a solution for this. Perhaps Michael Dunn can help.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
i want to add windows media player activex control in vc++.
how to do it?
i added the windows media player activex control.But when i calling a method in it ,an runtime error occurs.No details in that error.
please help me .very urgent.
Anand
|
|
|
|
|
I am launching off a console app (by pressing a button )using CreateProcess. I save the handle to this process and when I press the button again, I want to terminate the process if its already running and relaunch it. I put in debugging statements and indeed I get the expected correct output, but the console window is nowhere to be seen this second time around!
if(m_serverProcessInfo.hProcess)
{
TerminateProcess(m_serverProcessInfo.hProcess, 0);
if(fpLog)fprintf(fpLog, "Terminated server\n");
m_serverProcessInfo.hProcess = 0;
}
int res = StartServer();
and
int CPMA2000Dlg::StartServer()
{
int res = 0;
STARTUPINFO StartupInfo;
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof StartupInfo ;
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow = SW_SHOW;
if(CreateProcess( m_sPath + "fileserver.exe", NULL,
NULL,NULL,FALSE,0,NULL,
NULL,&StartupInfo,&m_serverProcessInfo))
{
if(fpLog)fprintf(fpLog, "Started server\n");
}
My logs:
Started server<br />
Terminated server<br />
Started server<br />
The first time I do see the console window (server.exe) but the second time though CreateProcess() succeeds again, I dont see the console window which disappeared at the TerminateProcess().
How shall I proceed to figure out the problem?
Thanks,
sb
|
|
|
|
|
Are you doing this in order to have a single instance of the application?
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
No. I need a fresh copy of the server each time the button is pressed.
When the button is pressed, two apps are launched: server.exe and my.exe. my.exe depends on socket info from server.exe. When my.exe ends, the user closes the my.exe window, but not the server window. Then when he presses the button again, i want the server.exe to exit and relaunch itself. I dont really want to instruct the user to close both the server.exe and my.exe before pressing the button again. BTW I just modified my app and had the main app send a socket message to the server.exe (if its still running) which tells it to exit. Then it launches it again. However once again, my server listens to and follows the instruction to exit,exits, says its restarted (logfile) but doesnt show up (and my.exe gets unhappy claiming its not running).
Thanks for looking into this,
sb
|
|
|
|
|
Have you checked the return code for the CreateProcess the second time round?
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
Yes. It returns true the second time around too.
|
|
|
|
|
It may be a race condition. Try stepping through the code and ensure that the server has gone away before moving to the code to launch it again.
If this is the case and all works when you slow it down you will have to wait for the process to terminate before trying to start it again.
I hope this helps
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
I neglected to mention that when I step through theres no problem. So with your insight I did Sleep(1000) and it works. Now I nervous about whether the time is enough from computer to computer. On mine its adequate without being noticeably slow. Is there some way to be certain of this barring a statistical survey?
Thanks,
sb
|
|
|
|
|
Um, a single Sleep is not ideal for this sort of problem. As you rightly say it may not be the same on all machines.
I suggest that you send the close, wait a while then check that the process has gone away before continuing. If it hasn't wait a while again then check again. Repeat this a maximum number of times before issuing an error message saying that the server has stopped responding for instance (as it is possible that the server may not close for some reason).
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
|
Does this help Application desktop toolbars[^] ?
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
|
Um, Interseting. If I come across some other examples I will let you know. Good luck with that.
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
I now how can I make a VC++ program that using Access table but I want to create a program that can save data in database mode and dont use Access by reading data from a textsource please help me.
Thank you alot
|
|
|
|
|
|
Hello,
In my project, I have to check if a particular condition is satisfied and take some action accordingly. Hence I have started a thread which continously checks for the condition as shown below:
UINT ThreadProc(LPVOID lp)
{
while(TRUE)
{
DWORD dwWaitResult = WaitForSingleObject(MonitorEvent,INFINITE);
switch (dwWaitResult)
{
case WAIT_OBJECT_0:
//do the required action and ...reset event
ResetEvent(MonitorEvent);
break;
}
}
MonitorEvent will be set in the part of the code where the required condition is met. Once the the event is fired, ThreadProc acts and does the required task and again has to wait till the event is fired again. This has to continue till application exists.
The result of the above code is that CPU time is getting consumed 100%.
Can anyone please suggest a better solution?
Thanks in anticipation of information.
madhavi.
|
|
|
|
|
I had a similar problem with a ISDN Monitor. I had to wait for messages from the driver of the ISDN controller signaling an incoming call. The situation was exactly the same, a workerthread with a while loop resulting in 100% CPU usage. Adding a
Sleep(200);
in the while loop solved the problem for me. If some mseconds of "absence" doesn't affect your application it could also work for you.
MS
|
|
|
|
|
Had I been at your place, I would have used a different approach and that is to use SendMessage.
Write a class of your own, and write a message handler for your own defined message. In that message handler write the code which you have written above in thread in case of MonitorEvent being successful. From the class where Monitor event is fired, use SendMessage, this will send the Message to the other class and MFC will handle the rest.
I hope that is a better and more efficient solution.
Regards,
Imagine that you are creating a fabric of human destiny with the object of making men happy in the end, giving them peace and rest at last, but that it was essential and inevitable to torture to death only one tiny creature..and to found that edifice on its unavenged tears, would you consent to be the architect on those conditions? Tell me, and tell me the truth!
-Fyodor Dostoevsky, The Brothers Karamazov
|
|
|
|
|
And anywhere your application might be enhanced and then encounter a MsgWaitforMultipleObjects, your 'synchronization' scheme would be broken.
You REALLY need to wait on events or on other waitable objects in a properly desiged multithreaded application. Waiting for sendmessages is the old, and not thread safe, style of Windows programming
The fact that your CPU was at 100% means something else was wrong.
For example, you might have created an event that was Manual Reset type, and after your thread got signaled, and executed, you forgot to call ResetEvent before waiting for it again...
|
|
|
|
|
Hi Blake Miller,
Thanks for your inputs.
I have declared my monitor event as below first.
volatile HANDLE m_MonitorEvent;
m_MonitorEvent = CreateEvent(NULL, TRUE, TRUE, NULL);
ResetEvent(m_MonitorEvent);
//This event is set in the part of code which triggers this event.
SetEvent(m_MonitorEvent);
//Thread function
BOOL b_EventRunning = TRUE;
UINT ThreadProc(LPVOID lpVoid)
{
while(b_EventRunning == TRUE)
{
DWORD dwWaitResult = WaitForSingleObject(m_MonitorEvent, INFINITE);
switch (dwWaitResult)
{
case WAIT_OBJECT_0:
//Do the work
ResetEvent(m_MonitorEvent);
break;
default:
Sleep(1);
break;
}
}//end of while
}//end of ThraedProc
I used INFINITE in WaitForSingleObject because my this thraed has to run till the application is exited.
When this thread is doing the job, the CPU usage is shown as 100%. Please let me know if I'm missing out something here which is making my CPU consume 100%?
Thanks
Madhavi
|
|
|
|
|
ledallam wrote:
The result of the above code is that CPU time is getting consumed 100%.
Does that mean that WaitForSingleObject() is returning something other than WAIT_OBJECT_0 ?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Could you show how you declare and create MonitorEvent ? WaitForSingleObject can return WAIT_FAILED . For your example it means it is something wrong with MonitorEvent . Also add TRACE("dwWaitResult(%d)\n",dwWaitResult) to check the return value from WaitForSingleObject .
|
|
|
|