|
I am currently writing an application using C++ and MFC. As you might expect in the method InitInstance, I call new to create an instance of the main window class. I assign this pointer to m_pMainWnd. However, I am never freeing the object being created there. I feel this is a problem.
I plan to delete the object in the routine ExitInstance. I would think this would be standard practice but I have not seen any examples in my MFC books that do this. I am wondering why. Could it be that these authors do not do this because they feel it is does not matter since the application will terminate anyway? I kind of feel that they should.
Please comment.
Thanks
Bob
|
|
|
|
|
BobInNJ wrote: I plan to delete the object in the routine ExitInstance
Seems reasonable.
BobInNJ wrote: I would think this would be standard practice but I have not seen any examples in my MFC books that do this. I am wondering why. Could it be that these authors do not do this because they feel it is does not matter since the application will terminate anyway?
Probsbly.
Personally, I use smart pointers[^] to hold pointers. For this case, I might well use a boost::scoped_ptr , which would deallocate the memory in the CWinApp destructor.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Your question is a good one.
But I'll save you the suspense. You'll find an equivalent to the following:
CMDIFrameWnd::OnDestroy ()
{
...
if (m_bSelfDelete)
delete this;
}
This is a the last (or near enough, it might be OnNcDestroy) message a window handles, so it will tidy up after itself.
LoadFrame will set the self delete.
Apologies if there's the odd error in here, this is from memory - but it gets the essence.]
Iain.
In the process of moving to Sweden for love (awwww).
If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
|
|
|
|
|
Yeah - what Iain said. I'd forgotten all about that stuff. In an SDI app, the view deletes itself in its PostNcDestroy method.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
I am fetching the data from rtd server in using excel file .I want to store the data in database .Is there any way to to call the data in MFC application so that I can insert into the database.
Trioum
|
|
|
|
|
trioum wrote: Is there any way to to call the data in MFC application so that I can insert into the database.
Yes there is a way. Now can you explain what your sentence means? I mean because "call the data in MFC application" doesn't mean anything to me.
|
|
|
|
|
actually I want to store the data in my database by getting it from rtd server by calling the rtd function in MFC , in similar way excel call it .
Trioum
|
|
|
|
|
trioum wrote: by calling the rtd function
Really? "the" rtd function? You believe that provides us with specific information from which we can help you? Or maybe you are reading from a new Monty Python script?
|
|
|
|
|
led mike wrote: Yes there is a way. Now can you explain what your sentence means?
Welcome again in the CP's Memorable Quotes [^] (plus a plethora of led-points gained back).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
trioum wrote: I am fetching the data from rtd server...
Real Time Data?
Database storage aside, are you able to retrieve the data from the server?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
yes I am able to retrieve data from the server in excel file .
Trioum
|
|
|
|
|
So are retrieving an Excel file or a stream of data from the server?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
It is actually third party rtd server .I linked to it via excel and getting the data in excel file .
data is updating within milliseconds .I see the rtd formula on the cell. I donot know it is excel file or stream of data . please suggest the solution for both condition .My AIM is to store every updated data in the database .
Trioum
|
|
|
|
|
I'm curious. You don't seem to have any idea what you are doing so how did you end up being the developer of this little project?
|
|
|
|
|
Actually the strategic plan designate:
- Him as the software requirements' author.
- You as the developer.
Good luck to the Dream-Team!
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hello !
Hai in my application i have to display time taken for execution, at present i am using GetTickCount (), this function gives time in milliseconds, i need more detailed result i.e in microseconds, is there any similiar function?
thanks!
|
|
|
|
|
Well, you could either divide multiply that result by 1000, or resolve to the notion that unless you have a RTOS, you aren't going to get any better than 15ms resolution.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
modified on Thursday, April 2, 2009 9:34 AM
|
|
|
|
|
|
Ahh, what's a few decimal places going to matter?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
You're right, moreover most digits are zeroes...Who cares?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
It doesn't, but I made that same suggestion to some chap a long time ago and he said it was what he needed. I guess three more zeros made all the difference.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
QueryPerformanceFrequency [^] / QueryPerformanceCounter [^] pair maybe interesting.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I have a HWND pointing to the window in question. Is there any way I can close down my program when the HWND is closed?
Thanks in advance
|
|
|
|
|
Use IsWindow() . If it returns 0 , close your program.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
The program while loop looks like this:
while ( GetMessage(&msg, NULL, 0, 0) ) {
if (IsWindow(hWnd) == 0) {
}
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
So, IsWindow is not called until a message is received.
|
|
|
|