|
|
|
Chris Losinger wrote: probably won't fix the crash, but main should be declared as:
int main(int argc, char *argv[])
or
int main(int argc, char **argv)
Microsoft's compiler allows you to define main in any of the following ways (all completely acceptable):
int main()
int main(int argc, char** argv)
int main(int argc, char** argv, char** env)
void main()
void main(int argc, char** argv)
void main(int argc, char** argv, char** env)
While the 3-parameter version and the void versions are not portable, they are fine for Win32 Console programming.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: Microsoft's compiler allows you to define main ...
oh, i know. and like i said, it probably wouldn't help fix the crash. just thought i'd point out a style issue.
|
|
|
|
|
Chris Losinger wrote: just thought i'd point out a style issue.
No problem. Of course, his entire problem goes away if the suggested changes for the new standard are approved with regard to string , where the following code would actually work:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string input;
cin >> input;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi, i want to create an SDI application without Frame And Menu bars.
And in this SDI application ,i split the window into 3 views.
How can i close all the views at a time by clicking one button in the top view?
|
|
|
|
|
Hello
I have written an application which is using the msflexigrid. The problem I am seeing is with a fast PC. Intel 3GHz P4 using Hyperthreading.
The problem is the cells do not always update. Below is a sample of code which updates a cell depending of the outcome of the function.
if(!(CTESTINTERFACE::SetupTxVcoTop()))
{
if(!(CTESTINTERFACE::SetupTxVcoTop()))
{
m_vco_parameter_grid.SetRow(2);
m_vco_parameter_grid.SetCol(3);
m_vco_parameter_grid.SetCellForeColor(RGB(255,0,0));
m_vco_parameter_grid.SetText("Failed");
UpdateWindow();
if(OnTestFailed("TxVcoTop") == FALSE)
return;
}
else
{
m_vco_parameter_grid.SetRow(2);
m_vco_parameter_grid.SetCol(3);
m_vco_parameter_grid.SetCellForeColor(RGB(0,255,0));
m_vco_parameter_grid.SetText("Passed");
UpdateWindow();
CMEASUREMENT::strPASS_FAIL.ialign_pass_count++;
}
}
else
{
m_vco_parameter_grid.SetRow(2);
m_vco_parameter_grid.SetCol(3);
m_vco_parameter_grid.SetCellForeColor(RGB(0,255,0));
m_vco_parameter_grid.SetText("Passed");
UpdateWindow();
CMEASUREMENT::strPASS_FAIL.ialign_pass_count++;
}
I have tried replacing UpdateWindow() with Refresh(),RedrawWindow(),Invalidate(), and calls directly to OnPaint();
The problem is randam. Some times it runs flowlessly.
Any idears would be appreciated.
Regards Desmond Mardle
|
|
|
|
|
I have a program that reads text input form users and echo it in a textbox, similiar to chat. When I compile it using debug configuration everything works fine and great, but when I switched to release configuration the program crashes and generates an application error after the 1st line of text is echoed to screen. I have some TRACE statement in the code but as far as I know the TRACE statement does nothing in release configuration.
Is there anything else that I should check for might be the cause of this? I know the release configuration does some optimization but I'm not sure why it works in debug configuration but not release?
Any suggestion is welcome!
|
|
|
|
|
|
Hi All
I'm newbe to multithreading. Readings info on MSDN for MFC classes it seems that doesn't exist a function, like the pThread libraries, to wait that a Thread started with AfxBeginThread to its return. Do you know if there is some existing function instead of waiting time using Sleep( n )?
I would like to use an MFC function instead of the Win32 ones.
Also pThread libs got a proper function to retrieve the result of a thread; MFC use the pointer provided as argunet when the thread is started. Is this the correct approach?
Thanks everybody
bye Manu
|
|
|
|
|
::WaitForSingleObject is the method you are looking for. MFC didn't wrap this method (mainly because there was no need to), so you have to use the Win32 API here.
The last question you had ... are you talking about the return value of the thread or what is returned from AfxBeginThread?
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi Zac,
thanks for your reply!
I mean the return value of the thread; the value of the function returned with 'return' at the end of its execution. When we start the thread we pass a LPVOID as argument of the function to execute in the thread.
Can I use this argument retrieve this value from the calling thread? In pThread there is a function dedicated.
Manu
|
|
|
|
|
The LPVOID argument allows you to pass in any data you might want to use within the thread. Do NOT use it to pass back a return value. Use ::GetExitCodeThread to get the return value for the thread.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac,
this means that I need to pass the hanlde returned by WinThread to WaitForSingleObject?
I read in MSDN that user should be careful when mixing MFC threading with the WIN32 one.
Manu
|
|
|
|
|
manustone wrote: I read in MSDN that user should be careful when mixing MFC threading with the WIN32 one.
MFC IS Win32. It is nothing but a thin wrapper around the Win32 API. What you have to be careful of is mixing _beginthread(ex) and CreateThread. Typically, you want to use one or the other for an entire application. WaitForSingleObject takes a handle parameter. You will pass in whatever thread handle you have and it will return when either the timeout value you specify has expired (in which case the return value is WAIT_TIMEOUT) or the object has been signaled (for threads, that means exited/returned/stopped), in which case the return value is WAIT_OBJECT_0.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
If you mean pthread_create() function returns an int for checking, AfxBeginThread() returns a CWinThread* pointer for checking. They are pretty much equivalent.
Could you be more specific about "waiting time using Sleep(n)"? Don't know what you meant.
Best,
Jun
|
|
|
|
|
I know that in pThread it does exist a function that stops the creating thread until the thread called ends its job.
Zac just told me that there is a Win32 (not MFC) that does it. My intention was to wait an amount of time calling Sleep and stopping for a while the calling thread.
Do you know the best way to retrieve the value returned by a thread preferred using MFC classes instead of Win32?
|
|
|
|
|
manustone wrote: Zac just told me that there is a Win32 (not MFC) that does it. My intention was to wait an amount of time calling Sleep and stopping for a while the calling thread.
A couple things here: First, anytime you are calling Sleep, you really should rethink your design. That is one function that should almost never be called; especially as a thread synchronization technique. Second, you really should pick up "Programming Windows" by Charles Petzold and "Programming Windows with MFC" by Jeff Prosise. You are apparently under the impression that MFC is different than Win32 when in fact, MFC is nothing more than a thin wrapper around the Win32 API.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Thank you very much for the advice!
|
|
|
|
|
Woops!
Jun..I forgot to really thank you for the help!!!
bye MANU
|
|
|
|
|
You're welcome. Hope you got all the information you were asking for.
Best,
Jun
|
|
|
|
|
Problem 1: Optimization
A C++ class has the following member:
int status_[75];
During performance analysis it was found out that the class (its object) was performing unsatisfactorily
making it a necessary candidate for optimization.
The following additional information was also found out
*) Each element of the status_ array assumes only the following 4 values: -1, 0, 1, 2
*) The bulk of the time was spent in loops like:
for(size_t i=0; i != 75; ++i)
{
if(status_[i] == 1)
{
// do something...
}
}
*) The set of elements of the status_ array that assume a particular value is sparse making the above loop
inefficient.
Assume that 0 is the default value.
*) The status_ array is updated at places scattered throughout the code making it difficult to rewrite. However, a
particular element is updated only through a statement like
status[i] = -1;
Task: Your task is to optimize the class, considering the above
information.
The optimization should introduce the least bugs possible, i.e. it must
have
minimal changes and those changes that have lesser chance of
introducing bugs.
Never Ending Probloem
|
|
|
|
|
read this[^] before asking what you do
|
|
|
|
|
Again, asking people to answer these questions for you does not help you, and does not help the company that is interviewing you get a proper evaluation of your skill level.
At the very least, you should make an attempt prior to asking for help!
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Indian Idol wrote: Your task...
Not ours.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|