|
jerry1211a wrote:
If the values are floats I believe they cant be compared due to rounding.
You are correct.
jerry1211a wrote:
Is there a way to make a comparison between to real values?
Yes. You'll need to decide the level of precision, however. For example:
double dVal1 = 1.245, dVal2 = 1.249;
if (fabs(dVal1 - dVal2) < 0.01)
...
else
... The number of decimal places in the constant must be equal to the number of decimal places being compared in the other two numbers.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
How can you get Microsoft Visual C++ version 6.0 to display the time it takes to compile and build a project? I don’t mean the /Bt option, that displays the time taken to compile each individual source file. There’s a way of displaying the time for the whole build. I know there is because I used to do it, but I’ve just reinstalled Visual C++ 6.0 and I can’t remember how I did it before!
|
|
|
|
|
|
Thanks very much for your speedy reply. It didn't seem to work at first, but a web search showed that it's not a project option but an option for the shortcut to msdev.exe . Where did you get this useful information?
|
|
|
|
|
HI!
In my code, I create a document template in the following way:
pDocTemplate = new CMultiDocTemplate(IDR_PHYSEDIT,
RUNTIME_CLASS(CPhysEditDoc),
RUNTIME_CLASS(CPhysEditFrame),
RUNTIME_CLASS(CPhysEditView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
Everything works perfectly, but when the program exits I get
the following output:
e:\work\c++\project\utilities.cpp(117) : {58} client block at 0x003F4B40, subtype c0, 140 bytes long.
a CMultiDocTemplate object at $003F4B40, 140 bytes long
{56} normal block at 0x003F49F8, 78 bytes long.
Data: < 6 = = > D0 0D 36 10 3D 00 00 00 3D 00 00 00 01 00 00 00
My question is: How do I clean up the document template objects on exit? Shouldn't CWinApp do that?
øivind
|
|
|
|
|
dolph_loe wrote:
My question is: How do I clean up the document template objects on exit? Shouldn't CWinApp do that?
You don't. CYourApp will delete the doc template object in its destructor.
Can you set the breakpoint in your app destructor and step into CWinApp::~CWinApp from there?
Tomasz Sowinski -- http://www.shooltz.com
Alika masiaka!
|
|
|
|
|
tnx! had to add the following line
pDocTemplate->m_bAutoDelete = true;
øivind
|
|
|
|
|
Hi All,
I am spawning a process from a service. The spawned process hungs for various reasons, (corrupted data, deadlock). I am expecting the process has to complete the task with in the expected time limit, if it exceeds the limit I want to terminate the process (no mercy or graceful, just terminate the process).
The spawnng of the process, counting the time and termination of process all done in C++. Some time I am not able to terminate the process, the error message was "Access denied". I dont want this also happens. The program has to terminate the process even, the process in any state. How to do that? What security permissions I have to give?
Here is the code snippet of the teminate application,
=========================================================
static DWORD WINAPI TerminateApp( DWORD dwPID, DWORD dwTimeout )
{
HANDLE hProc ;
DWORD dwRet ;
// If we can't open the process with PROCESS_TERMINATE rights,
// then we give up immediately.
hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE,
dwPID);
if(hProc == NULL)
{
return TA_FAILED ;
}
// TerminateAppEnum() posts WM_CLOSE to all windows whose PID
// matches your process's.
EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM) dwPID) ;
// Wait on the handle. If it signals, great. If it times out,
// then you kill it.
if(WaitForSingleObject(hProc, dwTimeout)!=WAIT_OBJECT_0)
dwRet=(TerminateProcess(hProc,0)?TA_SUCCESS_KILL:TA_FAILED);
else
dwRet = TA_SUCCESS_CLEAN ;
CloseHandle(hProc) ;
return dwRet ;
}
static BOOL CALLBACK TerminateAppEnum( HWND hwnd, LPARAM lParam )
{
DWORD dwID ;
GetWindowThreadProcessId(hwnd, &dwID) ;
if(dwID == (DWORD)lParam)
{
PostMessage(hwnd, WM_CLOSE, 0, 0) ;
}
return TRUE ;
}
=========================================================
All suggestion appreciated.
Thanks
GTS
|
|
|
|
|
GTS2020 wrote:
What security permissions I have to give?
MSDN indicates that the handle must have PROCESS_TERMINATE access.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/terminateprocess.asp
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi David thanks for your reply.
It seems the process went in to a deadlock situation. When I tried with pskill it showed "Access denied" message. I have used the following security flag "PROCESS_ALL_ACCESS" while creating the handle. Even it was not able to terminate the process.
Is there any other way to terminate the process, even whatever state it is?
Thanks
GTS
|
|
|
|
|
GTS2020 wrote:
...the error message was "Access denied".
It's because the process you are trying to terminate is running under the Local System security account, which does not have "debugging" access. See this article for more.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hello,
How do I get the handle to the accelerator table loaded by the CFrameWnd ?
The problem is I need to translate hot key messages which occur in different parts of my app (in modeless dialog boxes; in a different thread; ...), but TranslateAccelerator needs an handle to the accelerator table and I don't know how to get it -- and I'm not that keen on overriding CFrameWnd's initialitions either.
Can someone help me out here?
Thanks a lot,
David
|
|
|
|
|
How about using LoadAccelerators()
Ant.
I'm hard, yet soft. I'm coloured, yet clear. I'm fruity and sweet. I'm jelly, what am I? Muse on it further, I shall return! - David Williams (Little Britain)
|
|
|
|
|
Compiler - VC6
I'm working on a project that is an activeX control, and that links to several DLL's. In one of the DLL's, I'm having a problem with CStrings - for some reason, I'm getting an access violation (C0000005) in MFC42D.DLL when I try to pass a CString from one class to another. Both classes are in the DLL I'm working in.
I've tried a number of methods for creating the CString in the calling function,but nothing seems to be working. Is there some sort of bizarre rule concerning CStrings that I'm not aware of?
If anyone can suggest something to check, I'd appreciate hearing about it.
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote:
Is there some sort of bizarre rule concerning CStrings that I'm not aware of?
I am aware of no such known restrictions.
John Simmons / outlaw programmer wrote:
If anyone can suggest something to check, I'd appreciate hearing about it.
Memory corruption can produce C0000005 access violation errors in blocks (objects) that are not related to the code responsible for the problem.
Is your CString object on the stack? If it is move the location significantly by placing a large block of memory on the stack right in front of it. Then test for the error again.
char buf[0xffff];
CSstring mystring;
"No matter where you go, there your are." - Buckaroo Banzai
-pete
|
|
|
|
|
i am definitely puzzled by this.
i have a small class hierarchy:
result - abstract base class
burnsResult - abstract, derived from result
002burnsResult - concrete, derived from burnsResult
003burnsResult - concrete, derived from burnsResult
textResult - concrete, derived from result
so far so good. the default copy constructor exists for class textResult, but it does not exist for 002burnsResult or 003burnsResult.
i am getting:
error C2582: 'operator =' function is unavailable in 'file'
the VS .NET 2003 help for this error is nice and clear, the only problem is that the word operator does not exist in any of the .h files defining these classes
so how come there is a default copy constructor for one class, but not the other two?
i don't really want to define my own copy constructor, since there should be no need. i am mainly a C programmer, so perhaps i have overlooked something obvious. anyone got any ideas on why this is happening?
|
|
|
|
|
feline_dracoform wrote:
i am getting:
error C2582: 'operator =' function is unavailable in 'file'
On what line of code?
feline_dracoform wrote:
i don't really want to define my own copy constructor, since there should be no need.
Just because you don't see the need does not mean one does not exist. Copy constructors are almost always a good idea. At the very least, they keep the compiler from making (incorrect) assumptions.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
DavidCrow wrote:
Copy constructors are almost always a good idea. At the very least, they keep the compiler from making (incorrect) assumptions.
i had made the assumption that using the default copy constructor was a good idea, since this made sure i wouldn't forget to copy one of the member variables of my class.
is this a bad assumption on my part?
|
|
|
|
|
Per MSDN:
If you do not supply any constructors, the compiler attempts to generate a default constructor. If you do not supply a copy constructor, the compiler attempts to generate one. A compiler-generated default constructor sets up the object (initializes vftables and vbtables), and it calls the default constructors for base classes and members, but it takes no other action.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
First a copy constructor is not the same thing as an assignment operator. That said the compiler will generate a default assignment operator much the same as it does for copy constructors, i.e., member wise.
So moving on...
feline_dracoform wrote:
error C2582: 'operator =' function is unavailable in 'file'
That message does not mean that the default assignment operator has not been generated by the compiler. It is completely dependent on what you are attempting to assign to what in the code that produces that error.
Without seeing some of the pertinent code we just can't tell what the problem is.
Hate is not a family value.
-pete
|
|
|
|
|
*oops*
yes, i discovered a copy constructor isn't the same as an assignment operator after quite a bit of reading yesterday. it is a few years since i have done much C++, and i had forgotten this.
the problem function was:
result *002burnsResult::cloneResult(ParentResult *newParent)
{
002burnsResult *newResult = new 002burnsResult;
*newResult = *this;
newResult->setParent(newParent);
return newResult;
}
feeling confused, i tried to compile the same class under UNIX. this also refused to work, but the compiler told me it was unable to construct a default copy constructor for the class i didn't even get as far as this function.
i think having a class member of type QValueVector<QString> is causing this problem, but i have no idea why. i am guessing Qt have done something strange in their classes.
writing a copy constructor, and switching to:
002burnsResult *newResult = new resultBurns(*this);<br />
works fine. the thing is, all i have done in my copy constructor is a list of a = rhs.a lines, one per class member.
at least this works, and i have re-learnt a bit of C++. i would still like to understand why this didn't work though.
|
|
|
|
|
Hi,
To disable and enable a submenu item on runtime in an MFC app, I have used the following
code but seen no change. What is the problem with it?
MSDN says m_bAutoMenuEnable should be set to FALSE in the constructor of CMainFrame (in CMenu::EnableMenuItem), but in CDialog class there doesn't seem to be such a variable, or is there?
If I have to use ON_UPDATE_COMMAND_UI, can you give me some information on what to do?
Thanks...
CMenu* pMenu, *subMenu;
pMenu = AfxGetMainWnd()->GetMenu();
subMenu = pMenu->GetSubMenu(1);
subMenu->EnableMenuItem(ID_SETTINGS_F, MF_BYPOSITION | MF_DISABLED | MF_GRAYED);
DrawMenuBar();
subMenu->EnableMenuItem(ID_SETTINGS_F, MF_BYPOSITION | MF_ENABLED);
|
|
|
|
|
i m trying to understand ur problem. if i m correct, u want to disble some submenu item on some event occuring. ur code seems to be perfectly OK. i guess u can remove the statement
DrawMenuBar();
i hope it will work. as it works in my application
|
|
|
|
|
Yes, i want to disable the submenu item on some event and enable it on some other event. However the code does not work with or without DrawMenuBar(); The menu does not get affected at all.
Should I do something with the UPDATE_COMMAND_UI?
|
|
|
|
|
Maybe something like this:
//add event handler to menu item.
void PbmFlexListViewer::OnUpdateYourMenuItem(CCmdUI *pCmdUI){<br />
pCmdUI->Enable(bEnable);<br />
}
good luck!
"If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix
|
|
|
|