|
I need to update a global variable that gets manipulated in InitInstance() and a wrapper function. The variable is initialized to FALSE in the main constructior but gets set to TRUE in the wrapper function. Both threads are reading the variable in InitInstance causing a race condition.
How can I grant priority to the thread that belongs to the wrapper class? I created a mutex in the main constructor for all threads to access. In the wrapper function, I have the following code:
STDMETHODIMP CWrapper::StartApplication(DataNotificationType notifyType, VARIANT data)
{
HANDLE openMutex;
openMutex = ::OpenMutex(0, FALSE, "notify");
DWORD dwMutexErr = GetLastError();
if (dwMutexErr == ERROR_FILE_NOT_FOUND)
AfxMessageBox("cannot open mutex");
else
{
WaitForSingleObject(mutex_handle,INFINITE);
variableToUpdate = TRUE;
}
....execute some program.exe....
ReleaseMutex(mutex_handle);
}
BOOL CMainApp::InitInstance()
{ .....
if (variableToUpdate)
{
....code...
}
}
Thanks!
|
|
|
|
|
elephantstar wrote:
How can I grant priority to the thread that belongs to the wrapper class
Maybe use an event instead of a mutex that blocks your low prio thread, and only set the event when the wrapper class thread is done ?
~RaGE();
|
|
|
|
|
I created a mutex to make sure only one instance of the app in running. The variable that needs to be updated determines whether or not to create the mutex. Right now, that variable is being set to TRUE in the wrapper class. Once it's set to TRUE, CreateProcess is called to run the app within the wrapper function at the same time the main app is also running and reading in the variable that was initially set to FALSE. How would I create an event in InitInstance to run the second thread that will call InitInstance via CreateProcess? I'm just a little confused how all this works. I didn't think about using events or a mutex for synchronizing the variable until I removed my AfxMessageBox code that was used for debugging purposes. I guess it put a delay in the thread causing it to read the desired variable value.
|
|
|
|
|
HI~~
i have a Q about analyse a string type of CString.
the string was <伯 YはY><夷 YいY><叔 YしゆY><斉 YせいY><餓 OウO K哀K>于<首 YしゆY><陽 YやうY>之<下 YもとY O二O K亜K M。M>
i want get the CStringList list;
list[0]=伯;
list[1]=夷;
list[2]=叔;
.....
code like this:
while(!ado.pRtr->adoEOF)
{
var=ado.pRtr->GetCollect("SHOMON_BUN");
m_Text=(LPCSTR)_bstr_t(var);
int len=m_Text.GetLength();
while(!len==0)
{
//i don't know how can i do
}
list.AddTail(m_Text);
ado.pRtr->MoveNext();
}
thanks in advance very much~~!
nothing
|
|
|
|
|
ebinaini wrote:
i have a Q about analyse a string type of CString.
the string was...
What is it that you are wanting to analyze?
ebinaini wrote:
while(!len==0)
What are you trying to check for here?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Just curious, but when would this occur?
I figure typically it would be caused by a faulty harddrive like a bad sector which hasn't been flagged as such by defrag or scandisk???
I am way off or dead on???
Just curious, thanks
It's frustrating being a genius and living the life of a moron!!!
|
|
|
|
|
You are off by a couple of light years.
_lseek() will fail if it has a bad file descriptor or you try to position the file pointer before the beginning of the file. (Note: this means that positioning the file pointer beyond the end of the file is perfectly ok)
fseek() behaves similarly, but there are caveats depending on the open mode.
|
|
|
|
|
Hockey wrote:
Just curious, but when would this occur?
I figure typically it would be caused by a faulty harddrive like a bad sector which hasn't been flagged as such by defrag or scandisk???
... or if somebody pulls out the floppy disk.
Seriously, network drives are not always reliable.
|
|
|
|
|
Hi
I'm new to MFC programming but i also managed to write a small program which i would like to use as a standalone exe.
When i tried to run the program on another computer i got an error that it does not have "MFC71.dll" but i found that it has the "MFC40.dll".
My program was built using Visual Studio 2003 and i ask how can i build the project within to support the older version of MFC?
Thanks a lot
Mamtz
|
|
|
|
|
mamtz wrote:
My program was built using Visual Studio 2003 and i ask how can i build the project within to support the older version of MFC?
It's not a question of "supporting an older version of MFC". An MFC app built with VS 2003 requires the presence of MFC71.dll unless it is statically linked with MFC, in which case the DLL isn't required.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
I bought a harddrive enclosure that has a button on it for one touch backup. The software that came with is sucks, so i wrote my own. How do i detect when the button it pressed. Would this be part of the device driver? Is it in the registery?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
That's not very easy.
You have to find a way to listen for messages coming from the device. A device driver is one possibility, but there may be also one for user-mode.
There are some programs on the internet which are watching the data sent through the USB port, maybe they can help you identifing the backup button message.
Don't try it, just do it!
|
|
|
|
|
Anybody have any idea how to capture and ultimately cancel when a user double clicks on the caption bar of a Frame. The Onsize is too late, OnLDoublClick doesn't get called. I don't want the user to be able to size the window, which I've accomplished by removing the WS_SYSMENU & WS_THICKFRAME from the window style. But by double clicking on the caption bar the window goes to a 'smaller' size. My app still needs the caption bar, so removing that isn't an option. Any Ideas, thanks
Larry
|
|
|
|
|
did you have a look at the "Nonclient-Area Message Handlers" ( OnNcLButtonDblClk in particular ) ?
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
What about:
WM_SIZING
WM_GETMINMAXINFO
WM_NCHITTEST
WM_WINDOWPOSCHANGING I see the last three in Spy++ so I'd look at them first.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
Try handling WM_SYSCOMMAND (specifically the case for SC_MAXIMIZE ).
Note: This will likely prevent the window from being maximized, regardless of how the maximize operation was requested (i.e. by double-clicking the caption bar, via the system menu, or by clicking the maximize icon at the window's top-R corner).
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Hello!
I have an optimization program that repeats simulations in a loop. It is quite time consuming, and therefore I display a dialog that shows the number of simulations that are left. In each iteration I call a member function in the dialog class that decrements the number of simulations left and updates the dialog. This works well as long as the dialog is on top but as soon as another window covers it the updating stops. Bringing it back on top does not restart the updating either. I have tried to put all the obvious calls in the updating function, like: Invalidate(), Redraw(), UpdateWindow(), ShowWindow(), etc. but I can not make it work. How do I do this?
Thank's in advance!
maladuk
|
|
|
|
|
You need to put the code for the "simulations in a loop" in another thread. That way, the GUI's message pump does not get bogged down and become unresponsive. See here for more.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
|
|
|
|
|
multi-threading is the most elegant way to handle this. but, there's always the bad-old Message Pump:
void MsgPump()
{
DWORD dwLen = 100;
MSG m_msgCur;
CWinApp *pWinApp = AfxGetApp();
DWORD dInitTime = GetTickCount();
while (::PeekMessage(&m_msgCur, NULL, NULL, NULL, PM_NOREMOVE) &&
(GetTickCount() - dInitTime < dwLen) )
{
pWinApp->PumpMessage();
}
}
call this somewhere in your loop. it's not necessary to call it every iteration, but just a few times each second will be enough to keep the UI alive.
of course, now you need to be able to handle things the user will do things with your buttons, menus, etc., while your loop is running. (i usually just disable all controls and watch out for WM_CLOSE and WM_QUIT).
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
|
I need to implement source control on a Windows project ASAP. I've been fighting VSS on and off again. Well, the other day, I dusted it off and went thundering into adding files, etc.... and I lost my network connection in the middle of this processing. Now, two of my projects are corrupt with:
file names.dat may be corrupt
and
Error reading from file
Using the analyze utility, it reports that there are no problems to fix, yet these errors remain. So, I'm about to just delete these projects and start again. However, my network bounces around considerably. I cannot afford my code repository being corrupted every time a command or operation is interrupted (has MS never heard of rollback?). Am I just being paranoid? Is this product actually stable enough? I'll give you another example - VSS still uses 8.3 names? Give me a break...
Charlie
C. Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
|
|
|
|
|
scrap VSS and use a better SSC, either CVS or SubVersion; I found that both of those products, while not beeing complety integrated in Visual Studio, are way better.
Source Code is the most important things that you ( and/or your company ) own; you should paranoid !!!
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
You won't have an argument from me - the source code and the ability to build products is the crown jewel of any software organization. I know there are other products out there. My situation is a bit more complicated in that I am an independent consultant within an organization that is mainly mechanical products - software is a tolerated evil. It is getting better, but they are still very new to the software world. In any event, I don't have the luxury of just picking anything I want to use (not yet anyway).
So, setting aside that there are better products out there, is VSS really this sensitive?
C. Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
|
|
|
|
|
CharlieG wrote:
is VSS really this sensitive?
Yep[^] (<edit: <a="" href="http://www.highprogrammer.com/alan/windev/sourcesafe.html" rel="nofollow">this[^] is the link i was originally looking for).
Here's a quote I once heard from someone who works at Microsoft:
"Visual SourceSafe? It would be safer to print out all your code,
run it through a shredder, and set it on fire."
I use Perforce which is excellent and free for up to two users. Otherwise, Subversion (which is the next incarnation of CVS and apparently fixes a number of serious issues) sounds good.
The two most common elements in the universe are Hydrogen and stupidity. - Harlan Ellison
Awasu 2.1.2 [^]: A free RSS reader with support for Code Project.
|
|
|
|
|
VSS is a terrible thing to use if you might lose your connection.
If you *need* it, then consider adding a remoting plug-in -- SourceOffSite. Uses the SourceSafe database, yet it's remote-safe.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.santacruznetworks.com">Santa Cruz Networks</A>
|
|
|
|