|
i have a thread that is going to keep attention to a variable, once something is changed in the variable it has to respond to it. So this is how my code looks now:
<br />
BOOL SomeVariable;<br />
<br />
UINT WatchThread(LPVOID param)<br />
{<br />
while (TRUE)<br />
{<br />
if (SomeVariable)<br />
{<br />
break;<br />
}<br />
}<br />
}<br />
<br />
.....<br />
<br />
AfxBeginThread(WatchThread, (LPVOID *)this, THREAD_PRIORITY_NORMAL);<br />
<br />
.....<br />
if i run this my program will need 100% processor usage. how can i prevent this? Make a Blocking function of "SomeVariable"? and how?
[]D [] []D []
|
|
|
|
|
I think you should perhaps insert a Sleep command inside your thread for not to consume so much processor power. Beside that, I don't know whether your thread-solution is the most practible one when waiting for a variable to change. Perhaps you could work with events and one of the wait functions (like WaitForSingleObject), setting the event when your computations have finished (take care: in that case your computation should be placed inside the thread because the wait function is blocking)
|
|
|
|
|
Spinning in a tight loop waiting for a variable to change is not the proper way to notify a thread to begin doing something. Read up on thread synchronization techniques; events and semaphores and the method WaitForSingleObject. If you must do it the way you've described, put a tiny sleep (Sleep(10)) in your while loop.
Ron Ward
|
|
|
|
|
the reason why i want it to be a blocking process is because i want to recreate the windows messaging device, so make my own messagelist. this list will be read by a procedure for the control of a database. i wanted to make the function that reads the messagelist like the function recv (for network communication), the function recv lockes up the while loop until it has received information.
i hope that something like this is possible...
[]D [] []D []
|
|
|
|
|
i don't really get what ur doing but maybe this is sort of what u are looking for?
UINT WatchThread(LPVOID param)
{
while(1){
myclass* pthis = (myclass*)param;
int nmsg = pthis->getMsg();
// do something here
}
}
int cmyclass::getMsg(){
::WaitForSingleObject( _event, INFINITE);
return _msgNumber;
}
void myclass::setMsg( int nmsg)
{
// lock a critical section or use whatever synchronization needed
_msgNumber = nmsg;
SetEvent( _event);
// unlock the critical section or whatever
}
"No matter where you go, there your are..." - Buckaoo Banzi
-pete
|
|
|
|
|
There are several solutions. One solution is an event kernel object and WaitForSingleObject(). Use ::SetEvent() and ::ResetEvent() to signal the object.
Kuphryn
|
|
|
|
|
I would like to do a drag and drop from a file to my dialog window to have the path and the name of the file. How can I do that as simply as possible?
Thanks!
Beginner developer
|
|
|
|
|
Call DragAcceptFiles() in OnInitDialog.
Then implement OnDropFiles - to handle WM_DROPFILES messages - making calls to DragQueryFile and DragFinish as documented.
rechi
|
|
|
|
|
Thanks!
Do you have an example?
Thank you again!
|
|
|
|
|
Modify the header file:
afx_msg void OnDropFiles( HDROP hDropInfo );
DECLARE_MESSAGE_MAP()
And the .cpp here:
ON_WM_DROPFILES()
and here
void CDialogDlg::OnDropFiles( HDROP hDropInfo )
{
char sz[MAX_PATH];
CString szMan;
UINT nFiles=DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
for (int i=0; i<nFiles; i++)
{
DragQueryFile(hDropInfo, i, sz, MAX_PATH);
szMan+=(CString(sz)+"\n");
}
DragFinish(hDropInfo);
AfxMessageBox(szMan);
}
rechi
|
|
|
|
|
How can I prevent my application from showing in the taskbar - I mean when running in a normal window (or maximized), I don't want it to appear in the taskbar area.
|
|
|
|
|
Hello, maters please help me.
In my VC++ code, in a dll, I defined a function which looks somewhat like
void *comport_read()
{
BYTE *pData;
....
pData = new BYTE[size];
....
return pData
}
Now func() gets called from a client.
void handler()
{
BYTE *pData;
pData = (BYTE *) func();
...
delete[] pData;
}
When both the DLL and the client are of debug version, errors seem latent.
But when I create them as release verions, memory exception shows up.
The apparently same symptom can be generated such as in the following lines:
BYTE *pData = new BYTE[100];
delete[] pData;
delete[] pData;
So I suspected I could have deleted[] the same pointer to dynamically
allocate memory twice but never find any wrong. Of course the same symptom
doesn't mean the same cause.
I need at least how to tackle this sort of bugging memory problems if
not the exact sotution avaliable.
|
|
|
|
|
Do your client and the DLL make use of the same heap manager? If not, then when it comes to the delete call the manager used to delete the pointer doesn't recognise it and has big problems. Try writing a delete function in the DLL and pass the pointer back into that for the call to delete. If thast solves the problem then you have a heap clash problem.
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
Thank you so much. I tried what you suggested and succeeded.
I made a separate DLL where GlobalMemAlloc() and GlobalMemFree() were defined as
void *GlobalMemAlloc(size_t bytes)
{
// AFX_STATE_...
return new BYTE[bytes];
}
void GlobalMemFree(void *p)
{
delete[] p;
}
These functions are now used throughout the entire project files and functioning well.
Could you please give answers to two more questions?
Is there a way other than in the above solution?
what are/makes the differences between debug version and release version of ::new and ::delete?
Again thank you very much.
|
|
|
|
|
Is it possible that even though my contrastPos variable always has a value in it , some error could happen that when I do a successful
resSlider = RegSetValueEx(keyHandle3, "Contrast",
0, REG_DWORD, (BYTE*)&contrastPos, sizeof(DWORD));
if(resSlider != ERROR_SUCCESS)AfxMessageBox("Contrast setting not saved");
it could go and put a blank in the registry instead of the value of contrastPos?
Appreciate your help,
ns
|
|
|
|
|
Possibly a stupid question, but is contrastPos actually a DWORD ?
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Ulp! I declared it as an int contrastPos - I get it from
void CSView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
contrastPos = nPos
How do I need to modify my RegSetValueEx? The sample I saw did things with DWORDS and I havent seen anything else. I do see that if I use the retrieved value that I declared as a DWORD, as an int, things seem to work okay....
On the same lines, say I want to retrieve an int from the registry.....I am trying:
DWORD valType;
DWORD valSize = sizeof(DWORD);
RegQueryValueEx(keyHandle3, "Number of Display Windows",
0, (LPDWORD) &valType, (LPBYTE) &m_numberOfBoxesSaved,
(LPDWORD) &valSize);
where I have int m_numberOfBoxesSaved
Appreciate your help,
ns
|
|
|
|
|
Hello *.*!
I have to code a little program that determines the fan speed, the CPU temp. and the voltages on the mainboard. I searched CP for a long time but I actually didn't find anything concerning reading BIOS values!
The next task is to write some C(++) code running under Linux to do the same!
Thanks in advance,
greetings, Jan.
|
|
|
|
|
You can't do this from RING3 (user-mode) code. You need to create a device driver to get hardware access.
|
|
|
|
|
Do you know if there's a driver with api I can use?
I don't even know how to code such a hw-driver on my own!
Greetings, Jan
|
|
|
|
|
I was created Toolbar by using CToolBarCtrl. I was Implemented in MDI App.
I was implemented Enable the Toolbar once if Textbox is Selected.(ON_UPDATE_UI)How to set the disable state Even if there is no child windows in MDI App?
|
|
|
|
|
is there something like CDM_GETFOLDERPATH but in SET version?
t!
|
|
|
|
|
My visual studio is messing me about. Every time I try and switch to a different file in the IDE, the system hangs for about 8-12 seconds before switching over to it. It also sometimes happens when I go to modify the file.
I have Visual Sourcesafe running for the porject in question with the DB on our server. I don't think its a problem at that end as all the other developers in the office are not having the same problem.
Anybody got any ideas on what could be the problem?
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
VC++ 6.0 ?
This may happen if you have many breakpoints in your project.
Edit->Breakpoints->Remove All and press OK.
may solve your problem.
|
|
|
|
|
You know, I read that and I thought, No way! But I checked and there was a breakpoint problem. Somehow VS had got confused and the same breakpoint was listed about 300 times!.
I removed them all and it seems to be going much faster.
Thanks!
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|