|
Obi Wan 2 wrote: The more I think on it, the more I think there is no difference, but that solution 1 is more aesthetic.
I agree.
|
|
|
|
|
I have a Win32 console-based program which does this:
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
...
if( something failed )
{
nRetCode = 1;
}
return nRetCode;
} My customer is telling me that they are always getting errorlevel 0, and never getting errorlevel 1 upon failure.
I'm wondering, is return the proper way to return an errorlevel??? Or should I be using some other method? I seem to recall some sort of exit() function a million years ago from the old DOS days.
Thanks for any assistance!
|
|
|
|
|
chimera967 wrote: always getting errorlevel 0, and never getting errorlevel 1 upon failure
Are they sure the failure condition is ever being executed?
|
|
|
|
|
Maybe it's never failing!
AFAIK, you'll need to use exit() to work with ERRORLEVEL.
void _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nExitCode = EXIT_SUCCESS;
...
if( something failed )
{
nExitCode = EXIT_FAILURE;
}
exit(nExitCode);
}
|
|
|
|
|
That looks ok, the return value of main() is used as the process's exit code.
|
|
|
|
|
Well, im making a game, its great... except for this error, with this line:
Angle = asin((From->DestX - (Current->xPos /*Add offset*/))/SwingDistance);
In short that is:
Angle = asin((50 - 100)/65);
The numbers are just examples but you get the idea. Anyway, sometimes, it works perfectly, and its absolutley fine. Others, the angle gets set to -1#IND0 and my x,y co-ords get set to 0,0 as a result.
I debug it, check the values, put it into a calculator, and it works just fine.
So are there any ideas on this, has it come up before?
|
|
|
|
|
Wait, no, my foolish error with the calculator, it doesn't work.
Im just gonna put this down to inaccuracies when calculating the next position. I've sinced changed the method slightly, and all is good now.
|
|
|
|
|
I have to support French for an application.
All the resources of my application are stored in a DLL for French. when select default language, main resource is loaded and if select french, french dll of resource is loaded. Everything is fine as long as no custom controls are used.
I get a problem with custom control when load resource dll:
In old version, there is a control which managed by ActiveX Control, when i load resource dll (french) -> DONE:
CONTROL "",IDC_PREF_DIALOG_HIST,
"{E41EAFC4-F536-11CF-93A1-0000C0A61E5A}",WS_TABSTOP,7,7,
397,114
But in new version, this control is edit to Custom Control and manage by a new class (CHistogramCtl). when I use default language (English) => OK. But when I use french language (resource DLL), I could not load dialog which contain this control.
CONTROL "Custom2",IDC_PREF_DIALOG_HIST,"Histogram_Ctrl_Class",
WS_TABSTOP,7,7,397,118,WS_EX_CLIENTEDGE
Any suggestion will be helpful.
Thanks in advance,
Papais
Papais
|
|
|
|
|
How u create resources in French Language in VC++.
Thanks
Atool
Atool
|
|
|
|
|
I am using Visual C++ 6.0 MFC. I have gotten my secondary thread to work using AfxBeginThread(TestThread, this); but I don't want to use TerminateThread() based upon what I have been reading. When the secondary thread is spawned it may take 20 minutes for it to complete. I have a button on the tab page that spawned the thread that I want to use to 'Cancel Test' but I am confused as how to go about telling the thread to terminate itself cleanly. The psuedo code is as follows -
UINT C65602::TestThread(LPVOID Param)
{
C65602* device_type = (C65602*)Param;
device_type->TestThread();
return 0;
}
void C65602::TestThread()
{
HRESULT hr = CoInitialize(NULL);
pTests->pOutput->OpenExcelWorksheet();
pTests->RunTest(); // This may take 20 minutes
CoUninitialize();
AfxEndThread(0, TRUE);
}
void C65602::OnButtonBeginTest()
{
AfxBeginThread(TestThread, this);
}
void C65602::OnButtonCancelTest()
{
// I beleive this is where I want to tell the thread to terminate itself.
pTests->pGPIB->TurnOffDevice();
pTests->pOutput->SaveAndQuitExcel();
// or does it need to be here because of the Excel Automation im using?
AfxMessageBox("Test Canceled", MB_ICONINFORMATION);
CTabPage::OnCancel();
}
If anyone can push me in the right direction, throw me off the cliff.
Buck
|
|
|
|
|
You may find this[^] article (specifically the section "Pausing a Thread and Thread Shutdown") helpful.
/ravi
|
|
|
|
|
Unfortunately there is a documented bug having to do with the enum { Error, Running, Shutdown, Timeout } and the workarounds don't work.
Buck
|
|
|
|
|
Yep - Ravi's given you likely the best info you'll find, thanks also of course to 'The Flounder' - you must have logic within your thread that detects some sort of signal from the outside world and then acts on the signal, rather than trusting the OS to terminate the thread for you..
'g'
|
|
|
|
|
Unfortunately there is a documented bug having to do with the enum { Error, Running, Shutdown, Timeout } causing a fatal compiler error C1001 and the workarounds don't work.
Buck
|
|
|
|
|
The worker thread runs in your app's address space so a down-n-dirty method is to have it
periodically check a flag (maybe a bool variable somewhere) and if the flag is set stop doing
the worker thread stuff and exit. Set the flag false at the start, set it to true when the
user clicks cancel.
More elegant and thread safe is using an event. Pretty much the same as a flag except you'd
use WaitForSingleObject() (with a timeout == 0ms) periodically to check if the event has been
set. Create the event reset (non-signalled) at the start and set it when the user clicks
cancel.
Mark
|
|
|
|
|
You haven't given enough information. The pTests->RunTest(); // This may take 20 minutes line calls the function RunTest which is not shown. This code needs to be altered so it's interruptible.
Steve
|
|
|
|
|
Im in a property page and am trying to get a pointer
to the document. For some reason, it keeps giving me
a null pointer. I tried this:
CFrameWnd *pWndParentFrame = GetParentFrame();
CMultiScreenDoc *pDoc = NULL;
if( pWndParentFrame != NULL )
{
pDoc = (CMultiScreenDoc *)pWndParentFrame->GetActiveDocument();
}
and it doesnt work inside the property page. Any other
ideas any one else has will be greatly appreciated.
Sincerely,
Danielle Brina
|
|
|
|
|
If you do a quickwatch on pWndParentFrame in the debugger, is it pointing to the frame window you
are expecting (check its class )? Maybe you're not traversing up the window heirarchy far
enough...
Mark
|
|
|
|
|
|
What does GetMainWnd() return? It should give you a pointer to the main window, which you can then use to call GetActiveDocument() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I have an SDI application, with a form view, which has a few property sheets displayed.
When I click on "Open" button from the tool bar, to my surprise, CMyDocument::Serialize(CArchive& ar) is not called, and the title is updated by my selected file name.
How can this happen?!
TIA!
|
|
|
|
|
lucy wrote: How can this happen?!
Probably by writing broken code... like the code you posted yesterday.
led mike
|
|
|
|
|
I don't think I posted any code yesterday.
and I didn't make any changes to CMyDocument, only updated the
CMyDocument::Serialize (),
added code to serialize my member variables to &ar.
|
|
|
|
|
lucy wrote: I don't think I posted any code yesterday.
You are correct. My bad, I confused you with someone else.
lucy wrote: updated the
CMyDocument::Serialize (),
added code to serialize my member variables to &ar.
can you post your ::Serialize() code?
led mike
|
|
|
|
|
sure, I will.
I am not at work today. Caught a cold. I will post the code tomorrow.
Thank you very much!
|
|
|
|