|
Hi,
thanks for replying.
cheers
kannan
|
|
|
|
|
WindowsNT 4.0, 2 CPU system, Visual C++ 6.0
I have a timer in a view going off every 5 seconds, and it removes items from a CObList and processes them one at a time.
Meanwhile, I have a worker thread (thread 2) which is creating the objects to be put in the CObList. After it creates a new object, it does a PostMessage back to the view with a pointer to the newly created object. Back in the view (thread 1), the message handler for this message takes the new object and adds it to the CObList. Then when the timer goes off, it removes this new object from the CObList and processes it (as stated earlier).
Since the timer function is adding objects to the same list that the message handler function is removing them from, I set a lock flag before adding/removing and remove it after the add/removal is completed.
The problem is that after several of these objects have been processed (but it's not a fixed number of times), in the middle of the timer function the program execution jumps to the message handler function. Since the lock for the timer function has been set, the message function is unable to obtain the lock and so it can't properly process the message. If I try to resend the message (do another PostMessage with the received message) then the program immediately handles the new message without returning to the timer function, effectively just spinning over and over in the message function.
I have tried posting the message to the mainframe instead of the view, and the same thing happens. I have verified using GetCurrentThreadId() that the timer function and message handler function are in the same thread, and that the thread that does the PostMessage is in a different thread.
I have verified that the timer function gets preempted by adding TRACE statements, and also by setting a member variable to different values at different points in the program.
How is it possible that in the middle of a function, the program execution jumps to a message handler? I thought that this wasn't supposed to happen, and can't figure out what to do about it. Help! Thanks.
|
|
|
|
|
> ... I set a lock flag before adding/removing
Is this a simple boolean variable? If so, this mechanism is error prone as thread1 may set it to true after the view thread has read it as false.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
I have verified using GetCurrentThreadId() that the timer function and message handler function are in the same thread
OK - this leaves only one possibility. One of statements in the timer function causes some messages to be sent to window, and handler fires. Put the breakpoint in message handler and check the stack when it happens - probably you'll see timer function somewhere below.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
I posted the original problem.
Thanks to everyone who had suggestions, after struggling with this for two days, of course I finally figured it out shortly after I posted this message to the board.
In my timer function I had an assert similar to this:
ASSERT(pointer1 == pointer2);
when this assertion fails (as it does only sometimes), the program execution jumps from the timer function to the message handler function, and does this before it notifies me of a failed assertion. I don't really understand that, but by fixing the problem that was causing the ASSERT failure, I stopped my original problem from happening any more. Something about the ASSERT must allow it to go read the message queue.
Thanks again.
|
|
|
|
|
I'm moving some 16-bit Windows code over to 32-bit and one function that is giving me problems is a function that determines if a given filename is executing. More specifically, this program updates executables and DLLs from the network and before it performs a file copy, it calls a function called ProgramRunning(szFileName). Using TASKENTRY (which doesn't exist in 32-bit land) they enumerate the running processes and see if the filename passed in is in the tasklist.
Is there anyway to do something like this in 32-bit? It's easy if you have a process handle, but all I have is a damn filename.
Thanks,
Bill
http://www.ratebeer.com
|
|
|
|
|
AFAIK, There's no solution for all 32-bit Windows versions. On Win9x and 2K you can use Process32First/Next. If you need to support NT4, you'll probably have to use EnumProcesses (which is also available on 2K, but not on 9x).
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
Process32First/Next were exactly what I was looking for. I'm about 99% certain that we'll never be running on NT4 (it's an inhouse application) so this should work perfectly.
Thanks so much!
Bill
http://www.ratebeer.com
|
|
|
|
|
HOWTO: Enumerate Applications in Win32
KB: Q175030
I think that will answer your question(s).
|
|
|
|
|
Hi, All!
========
Does anyone know how can I change the caption of my API console application ?
Thanks.
BTW: come to #CodeProject on DalNet (mIRC)
|
|
|
|
|
|
I posted earlier this week about a problem I had where I could delete files but not remove a directory. Someone mentioned they once had a similar problem which was due to a shortcut existing that referenced the directory. As it happened I had three on my Desktop which were to be deleted in the next step of the program.
I have changed to order to delete the shortcuts from the Desktop. This is successful. Now when I try to delete the files with ::DeleteFile() or CFile::Remove() it fails. The return value from ::GetLastError() after ::DeleteFile() is ACCESS_DENIED. This is strange as earlier this week I could delete these files.
I am running Windows 2000 Professional SP2 VC++ 6 SP5. The files I am trying to delete were added by me to a directory that I created. They are icons and batch files that are (I am positive) not in use.
Anyone have any idea what the problem could be.
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
"Don't belong. Never join. Think for yourself. Peace"
- Victor Stone
|
|
|
|
|
Did you try SHFileOperation? You could delete directory with files in one step.
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|
|
No I haven't. Will give it a go in the morning.
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
"Don't belong. Never join. Think for yourself. Peace"
- Victor Stone
|
|
|
|
|
I would like to get the physical drive characteristics of the floppy drive in Win32. I am familiar with the diskinfo_t structure that was used for old DOS programs, but I am unfamiliar with how to do this in Windows. Does anyone have any idea on how to do this?
Thanks...
Brigg Thorp
Software Engineer
Timex Corporation
|
|
|
|
|
See MSDN:
Platform SDK\WIndows base services\hardware\device input and output\
using device input and output control\
That contains all the info you need.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
I'm writing an application using MFC, and i'm planning on using DAO for the main data source and serialisation for all the options etc. I was wondering if it would be possible to get the application to work on any machine? Could the MS Jet engine (i'm assuming DAO uses the jet engine) be installed on a machine that doesn't have it? Or could the neccesary functions be packed into the exe?
Thanks guys.
|
|
|
|
|
Just install MDAC, and you can use DAO or ADO. There is an extra download for Jet, I'm not sure if it's needed now or not.
Christian
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
Hi ,
The MS Jet Engine has to be installed.(Although
most systems have it, it may not be the exact version
u need) They cannot be packed with ur exe. But since
the installation package 'mdac_type.exe' is freely
distrubutable, u can have it packaged as a secondary
installation package along with our own installation.
Best of Luck.
Kumar
|
|
|
|
|
Thanks for the advice guys! I'll package the MDAC setup with my application.
|
|
|
|
|
If you are using the installshield, you only need to inlude the DAO Object, but in other case you need to add the following files to your seup.
dao360.dll depends of the version
AsyFilt.dll
msjint40.dll depends of the version
msjter40.dll depends of the version
msvcrt.dll
msvcrt40.dll
stdole2.tlb
comcat.dll
oleaut32.dll
olepro32.dll
Note: if you are using the 3.5 version these are the files
dao35.dll
dao2535.tlb
msjint35.dll
msjter35.dll
+ the rest of the files of the previuos list.
only I need to add that some files must be register, but that is your homework...
-I can say you...
SSShhhh bob!!!
Cheers!!!!
Carlos Antollini.
|
|
|
|
|
I am using a std::vector object to contain data that I need when creating
and displaying a graph. Initially the std::vector object is empty when
created. As information is retrieved it is push_back() onto the std::vector.
The std::vector object is declared in a CDocument object. When a CScrollView
is displayed the information is retrieved from the std::vector object. On
closure of the CScrollView the std::vector object is erased in
CDocument::CanCloseFrame().
The problem lies in reusing the std::vector object after it is erase(). An
error occurs when trying to perform a push_back().
The code is as follows:
In CDocument -
std::vector<edge> m_graphedge;
In CDocument::CanCloseFrame() -
m_graphedge.erase(m_graphedge.begin(), m_graphedge.end());
In CDocument::CreateGraph() -
m_graphedge.push_back(anedge); //works for the first time before it is
erased in CanCloseFrame();
//but doesn't work
after m_graphedge.erase() is called.
//HELP ???
Anybody with a solution?
Thank you
Franz Klein
|
|
|
|
|
I'm not sure why this would compile - erase is supposed to take an iterator or an iterator pair. Are you sure you don't want to call m_graphedge.clear() ?
Christian
This space for rent.
|
|
|
|
|
m_graphedge.begin() and m_graphedge.end() both return iterators. I get an access violation error. The same problem occurs when I use m_graphedge.clear().
Franz
|
|
|
|
|
In fact, vector::clear is implemented in terms of erase. Can you check your vector with debugger when crash happens (or just before)? Does it look to contain bogus bits?
Tomasz Sowinski -- http://www.shooltz.com
|
|
|
|