|
I think it all depends on what the current directory is.
And that all depends on how you run it....
Why not construct an explicit path to the file -- that way you can be sure.
use GetModuleFileName to determine the path of the exe...
split off the name and add "test.ini"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
How do I terminate my CWinThread from my main UI thread -- without blocking anything.
I was thinking I'd try something like:
PostThreadMessage( WM_QUIT, 0, 0 );
MSG msg;
while( PeekMessage(&msg, NULL, 0,0, PM_REMOVE ) )
{
if ( WaitForSingleObject(m_hThread,0) == WAIT_OBJECT_0 )
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
But that doesn't seem to work...
Any suggestions?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
or what about:
if I set m_bAutoDelete to FALSE
and:
PostThreadMessage( WM_QUIT, 0, 0 );
while ( PumpMessage() )
{
if ( WaitForSingleObject(m_hThread,0) == WAIT_OBJECT_0 )
break;
}
delete this;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
An example:
In your class which creates the thread:
private:
HANDLE m_StopThread;
HANDLE m_WaitThread;
static UINT ThreadFunction(LPVOID pvParam);
When you create your thread:
// Create events
m_StopThread = CreateEvent(0, TRUE, FALSE, 0);
m_WaitThread = CreateEvent(0, TRUE, FALSE, 0);
// Start thread
AfxBeginThread(ThreadFunction, this);
When you want to terminate the thread:
// Trigger thread to stop
::SetEvent(m_StopThread);
// Wait until thread finished
::WaitForSingleObject(m_WaitThread, INFINITE);
// Close handles
::CloseHandle(m_StopThread);
::CloseHandle(m_WaitThread);
//Your thread procedure
UINT CFoo::ThreadFunction(LPVOID* pvParam)
{
CFoo *pParent = static_cast<cfoo*>(pvParam);
while(true)
{
// Check event for stop thread
if(::WaitForSingleObject(pParent->m_StopThread, 0) == WAIT_OBJECT_0)
{
// Set event
::SetEvent(pParent->m_WaitThread);
return 0;
}
// Do your processing
}
}
Hope this helps you out!
|
|
|
|
|
That will only work if the thread has a message pump - i.e. is created as a UI thread. If it is a worker thread, I usually do the following (error checking removed for the sake of brevity):
in the main UI thread:
m_hTermEvent = CreateEvent (NULL, TRUE, FALSE, NULL);
m_pThread = AfxBeginThread (ThreadFunction, &m_hTermEvent);
SetEvent (m_hTermEvent);
WaitForSingleObject (m_pThread->m_hThread, INFINITE);
in the worker thread:
UINT __cdecl ThreadFunction( LPVOID pParam )
{
HANDLE hEvent;
hEvent = *((HANDLE *) pParam);
while (true)
{
if WaitForSingleObject (hEvent, 0) == WAIT_OBJECT_0)
break;
};
return 0;
}
Judy
|
|
|
|
|
That is NOT the case. This works as it should for worker threads!
Please, show me what in my code would not work!
|
|
|
|
|
pierre_ribery wrote: That is NOT the case. This works as it should for worker threads!
Please, show me what in my code would not work!
Calm down dude. No need to get snippy. I wasn't responding to your post, I was responding to the original poster. The presence of my post does not imply that yours is wrong. If you'll check the time stamp, we were posting at the same time. Your post didn't exist when I started mine.
Judy
|
|
|
|
|
Maybe I should go back to basic threading.
CWinThread is a UI thread in this case -- and has a message pump.
It seems that if I wait for it to terminate, then I am blocking my UI thread.
So, it seems I need to pump messages while I wait.
Or, do I have no clue?
More likely, I am just making this harder than it needs to be.
But, the goal is to wait for this thing to terminate completely.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
Are you terminating a UI thread from within itself as you're showing
in your code or do you want to terminate a thread from another
thread and wait?
For the latter, maybe something like this:
OtherCWinThread.PostThreadMessage(WM_QUIT, 0, 0);
while (1)
{
DWORD dwWaitRet = ::MsgWaitForMultipleObjects(1, &OtherCWinThread.m_hThread, FALSE, INFINITE, QS_ALLEVENTS);
if (dwWaitRet != WAIT_OBJECT_0 + 1)
break;
MSG msg;
while ( ::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
AfxGetApp()-> PumpMessage();
}
}
mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thank you! -- I knew someone would understand the question!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
ah! insight!
I never quite made the distinction.
Thanks!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
<A HREF="http://www.soonr.com">SoonR Inc -- PC Power delivered to your phone</A>
|
|
|
|
|
Attached below is the program... but it fails to execute!!
When i tried to execute: Cimg0Exception window pop up with the msg: CImg<unsined char="">::load_other():Failed to open image 'piggy.jpg". Check you have either the ImageMagick or GraphicsMagick package installed.
How do i install??(mine is Windows XP)
#include "CImg.h"
using namespace cimg_library;
int main() {
CImg<unsigned char=""> image("piggy.jpg"), visu(500,400,1,3,0);
const unsigned char red[] = { 255,0,0 }, green[] = { 0,255,0 }, blue[] = { 0,0,255 };
image.blur(2.5);
CImgDisplay main_disp(image,"Click a point"), draw_disp(visu,"Intensity profile");
while (!main_disp.is_closed && !draw_disp.is_closed) {
main_disp.wait();
if (main_disp.button && main_disp.mouse_y>=0) {
const int y = main_disp.mouse_y;
visu.fill(0).draw_graph(image.get_crop(0,y,0,0,image.dimx()-1,y,0,0),red,0,256,0);
visu.draw_graph(image.get_crop(0,y,0,1,image.dimx()-1,y,0,1),green,0,256,0);
visu.draw_graph(image.get_crop(0,y,0,2,image.dimx()-1,y,0,2),blue,0,256,0).display(draw_disp);
}
}
return 0;
}
|
|
|
|
|
purplee85 wrote: How do i install??(mine is Windows XP)
Please don't repost your questions. You can modify your original post to add the code. Of course in this case the code is irrelevant since you already told us you don't know how to install the library.
|
|
|
|
|
purplee85 wrote: CImg image("piggy.jpg"), visu(500,400,1,3,0);
Is it an absolute vs. relative path issue?
"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
|
|
|
|
|
purplee85 wrote: "Failed to open image 'piggy.jpg". Check you have either the ImageMagick or GraphicsMagick package installed."
How do i install??(mine is Windows XP)
Which part of
The Windows version of ImageMagick is self-installing. Simply click on the appropriate version below
and it will launch itself and ask you a few installation questions. is it you need help with?
Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all. Douglas Adams, "Dirk Gently's Holistic Detective Agency"
|
|
|
|
|
Hi.
I'm developing a library, and a function must display a form window with some controls. This form must be created based in a specification already written in some kind of file. I though in XML.
My question is, there is something already written that handle this kind of stuff? or I should start to warm my fingers and parse the XML file by my self?
Thank you and kind regards.
Demian.
"I have always wished that my computer would be as easy to use as my
telephone. My wish has come true. I no longer know how to use my telephone."
-Bjarne Stroustrup, computer science professor, designer of C++
programming language (1950- )
|
|
|
|
|
We are in the process of converting the Database of a, very large and process intensive, 14 yr old C++ MFC (V6) app from using MFC/DAO and MSJet to MS SQL Server. We want to do this in a way that will not loose any perfromance. In addition after this interim release is completed we will be re-writing and migrating the whole thing to .NET using a combination of C#/Managed C++.
My question is... What is the best way of accessing the SQL Db that has the best performance and will not set back development time too much and will also allow the data classes to be easily migrated to .NET. Should we use ADO, OLE DB etc ? I've heard ADO has performance issues and OLE DB is difficult to work with. I've looked into "Express OLE DB" but the download links to Sypram all seem to be broken and all email to the company is bouncing back.
Any suggestions would be appreciated.
Thanks
Steve Jacovino
ConEst Software Systems
|
|
|
|
|
Stevej wrote: In addition after this interim release is completed we will be re-writing and migrating the whole thing to .NET using a combination of C#/Managed C++.
Is there some requirement for migrating this twice?
Stevej wrote: My question is... What is the best way of accessing the SQL Db that has the best performance and will not set back development time too much and will also allow the data classes to be easily migrated to .NET.
1) What if you have competing criteria in there? Don't you think you need to prioritize?
2) What does "will not set back development time too much" mean? Set back how? Define "too much".
3) What does "easily migrated to .NET" mean, define "easily"?
I suggest you need to elevate the quality of your requirements before moving into making decisions.
|
|
|
|
|
Sorry, I guess it does sound like we are looking for the Grail.
Forget the other stuff, performance tops the list by a wide margin. Years ago a Microsoft engineer told us that Jet was their fastest database engine. Now we are looking for the best way (i.e. in terms of performance) to replace the DAO/Jet with MS SQL, still using VC++. We are looking for all the speed we can get while keeping with MS SQL.
Thanks
|
|
|
|
|
Stevej wrote: I guess it does sound like we are looking for the Grail.
Oh I wish I had thought of that!
Stevej wrote: performance tops the list by a wide margin.
Ok but you said you are migrating to SQL Server... from what? Access? If so you are likely to see a significant performance difference based soley on the DB engine completely exclusive of your DAL methods.
Also...
Stevej wrote: I've heard ADO has performance issues
I don't know about that but you might consider that ADO is designed to be used also from things like VB. When you use it from C++ you can use #import to generate ATL code that accesses the custom C++ ADO interfaces. This might out perform the automation interface used from VB by a significant amount.
Also check this out[^]
Last modified: 27mins after originally posted -- added MSDN article link
|
|
|
|
|
ADO is a layer on OLE DB. Unless you enjoy pain, I would not recommend programming the OLE DB directly. I'd be very surprised if there were any significant differences between ADO and OLE DB. Any real application is likely going to need the services ADO offers, and if you use OLE DB directly, you'll just end up reproducing many of those services yourself.
I've not done any performance testing, but I've seen all sorts of performance claims from all the technologies. It also depends strongly on the database one is connecting to: it has to be optimized for the connection technology. I believe IBM (DB2) recommends OLE DB, while Oracle gets better performance from ODBC (but don't quote me on that: I might be wrong). see http://www.datadirect.com/products/odbc/raisestd/index.ssp#1[^] for discussion of performance on one product.
Microsoft of course is going to push their latest technology, ADO.NET (I guess, unless they've changed it yet again; very frustrating to try to keep up with their constantly moving targets). Since they write the connection layers, they also optimize their database to talk to that layer. If performance is ultimate, stick with the latest Microsoft technology (and plan to spend $$$ upgrading it constantly). If you want portability, ODBC is probably king, and apparently pretty decent performance. ADO can also talk to ODBC but thru a layer, and maybe some performace hit.
david
|
|
|
|
|
When we right click on WinXP desktop and try to change display properties, we can change windows and buttons style to "Windows XP Style" ... and it makes a bunch of changes to the registry.
I want to know if its possible to make that property change through VC++ code ?
-Cage
|
|
|
|
|
cagespear wrote: I want to know if its possible to make that property change through VC++ code ?
Yes, it's possible. Just use the registry functions.
"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
|
|
|
|
|
|
I am looking for some examples or advice of really good data parsers. I am using a windows application and pulling data in via RS-232 ports. The data is typically one byte at a time and is complete data. It will have a header, a command, data, checksum, etc. I am looking for some smart parsers. I have some parsers that work, but I would like to make them more full proof.
Does anyone have any advice of ways to make sure it stays smart or places to find examples of parsers? For example, I had a parser that pulled two bytes of data in at a time. It worked well except for if the system was turned on at an odd byte. If the header was supposed to be in the higher byte, but was now in the lower byte, I had an issue. This problem has been fixed, but I want to see what other people have come across. Thanks for the help.
|
|
|
|
|