|
You could get the size of the map using std::map::size() , sizeof(std::map::key_type) and sizeof(std::map::value_type) and then assert on memory leaks more than that size.
You could also call std::map::clean() before doing this.
|
|
|
|
|
Checking the size of the leak is a good idea but I have no clue how to get the amount of memory leaked in code. _CrtDumpMemoryLeaks() just throws a wobbler when memory is leaked, it doesn't give any information on how much memory has been leaked, at least not until it shows up in the output window (60 bytes every time).
I assume you mean std::map::clear() (not clean). I already tried it to no avail.
After a lot of reading I think I am just going to go with a static map pointer instead of a static map. That way I can nuke the new'd map memory myself and make sure it is dead and gone before the program ends and memory leaks are checked for.
Thx anyway though.
|
|
|
|
|
Draemstars wrote: Checking the size of the leak is a good idea but I have no clue how to get the amount of memory leaked in code.
Take a look at _CrtMemCheckpoint[^] and _CrtMemDifference[^].
Draemstars wrote: I assume you mean std::map::clear() (not clean).
Yup. Typo.
Draemstars wrote: After a lot of reading I think I am just going to go with a static map pointer instead of a static map.
I wouldn't recommend it. Especially to support some code that is not going to run in the production build.
|
|
|
|
|
Define
_CrtMemState mem_s1, mem_s2, mem_s3; and at some point in your application, after the static map is created, "checkpoint" the memory usage with
_CrtMemCheckpoint(&mem_s1); and near the end, when you want to check for leaks get a 2nd checkpoint and "diff" them
_CrtMemCheckpoint(&mem_s2);
if (_CrtMemDifference(&mem_s3, &mem_s1, &mem_s2))
{
TRACE("....................Detected Memory Leak in Main Loop\n");
_CrtMemDumpAllObjectsSince(&mem_s1);
TRACE("....................End of Memory Dump\n");
} And if you have an iterative process, these two steps work well at the beginning and end of an interation to catch the "incremental" memory leak.
|
|
|
|
|
Cheers, _CrtMemDifference() worked like a charm.
No more incorrect warnings about leaking memory for me.
Thx guys.
|
|
|
|
|
I !
My problem is that : i don't succeed to write on the "Edit" control of a child dialogbox (i wish i want to write on the "Edit" control conteined in the dialogbox "type of character", accessible by the 'notepad.exe' main menu), because (with my code) the clipboard write her content on the 'main window' (and not where i
expect).
The code :
---------------------------------------------------------------------------
#include <condefs.h>;
#include <windows.h>;
#include <stdio.h>;
int main(int argc, char **argv)
{
HANDLE parentWindow, childWindow;
parentWindow=FindWindow(NULL, "Notepad");
if (parentWindow == NULL) { //notepad.exe doesn't running
printf("Notepad is NOT running !\n");
system("PAUSE");
return(0);
}
childWindow=FindWindowEx(parentWindow, NULL, "Edit", NULL);
if (childWindow == NULL) {
printf("I don't know the handle of 'Edit' control !\n");
system("PAUSE");
return(1);
}
SendMessage(childWindow, WM_PASTE, 0, 0); //i write the clipboard in the Edit control
system("PAUSE");
return(0);
}
------------------------------------------------------
I'm too sure that i mess up with the parameters of 'FindWindowEx' function, but where? If you haven't patience or competence to help me, can you suggest me some very good paper (include example in C) about the 'FindWindowEx' function? (or similar functions used to navigate trough 'handle' and external 'window')
I'm using 'Borland C++ 3' IDE, and i'm a very very newbie on C programming under Windows !
Very tnx to all the helper,
Ismaele-junior
|
|
|
|
|
Ismaele.Jr wrote: parentWindow=FindWindow(NULL, "Notepad");
Shouldn't this be:
parentWindow = FindWindow(NULL, "Untitled - Notepad"); In any case, this is not a good idea.
"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
|
|
|
|
|
Sorry DavidCrow,
i did digit the code BAD.
The true code is like you digit : parentWindow=FindWindow(NULL, "Untitled - Notepad");
But now, how can i do? Can you suggest me some solution or paper?
Very tnx
|
|
|
|
|
Ismaele.Jr wrote: But now, how can i do? Can you suggest me some solution or paper?
Does the clipboard contain data in CF_TEXT format? Does SendMessage() return anything (WM_PASTE doesn't)?
"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
|
|
|
|
|
Mister,
i think that i did explain bad :
My problem isn't HOW send message to objects with a handle, BUT find the 'exactly handle' of the "Edit" control of dialogbox of notepad.exe with the 'FindWindowEx' function.
It's only my fault : i'm some donkey in english language (unfortunately i'm italian !)
If you have other patience and charity for reply again, very very tnx !
|
|
|
|
|
Try edit in upper case.
childWindow=FindWindowEx(parentWindow, NULL, "EDIT", NULL);
|
|
|
|
|
Tnx but nothing,
the clipboard write again on the "Edit" control of mainwindow...not on the "Edit" control of the child dialogbox.
I'm crazyng ! 
|
|
|
|
|
So you have a dialog box open in notepad and you want to write to an edit box in that dialog?
If so, you need to get the handle to the dialog after you get the handle to notepad and then get the handle to the edit box.
HANDLE notepad = FindWindow(0, _T("Untitled - Notepad"));
HANDLE dialog = FindWindowEx(notepad, 0, 0, _T("Open"));
HANDLE edit = FindWindowEx(dialog, 0, _T("EDIT"), 0);
::SetWindowText(edit, _T("ABRACADABRA"));
|
|
|
|
|
Good morning Superman ! (or Supercoder !!!)
Very, you centred my objective.
Very tnx for the code that yuo posted me, but he doesn't compile with "Borland C++ Builder 3" under Windows XP : why?
I disclose that i admire your knowlege in C/C++ ! It's enviable
The code after your suggestion :
//---------------------------------------------------------------------------
#include <condefs.h>
#include <windows.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char **argv)
{
HANDLE notepad = FindWindow(0, _T("Untitled - Notepad"));
HANDLE dialog = FindWindowEx(notepad, 0, 0, _T("Open"));
HANDLE edit = FindWindowEx(dialog, 0, _T("EDIT"), 0);
::SetWindowText(edit, _T("ABRACADABRA"));
return(0);
}
//---------------------------------------------------------------------------
The compiler write me that : [C++Error] provaIndiano.cpp(11): Call to undefined function '_T'.
|
|
|
|
|
_T is a macro to support both UNICODE and NON-UNICODE builds.
Try without that.
int main(int argc, char **argv)
{
HANDLE notepad = FindWindow(0, "Untitled - Notepad");
HANDLE dialog = FindWindowEx(notepad, 0, 0, "Open");
HANDLE edit = FindWindowEx(dialog, 0, "EDIT", 0);
::SetWindowText(edit, "ABRACADABRA");
return 0;
}
|
|
|
|
|
something with _T being unicode or something. I read about it somewhere, but i'm not too uber leet with coding. All I know is that you must replace _T with Text("")
so it should be this...
int main(int argc, char **argv;
{
HANDLE notepad = FindWindow(0, Text("Untitled - Notepad"));
HANDLE dialog = FindWindowEx(notepad, 0, 0, Text("Open"));
HANDLE edit = FindWindowEx(dialog, 0, Text("EDIT"), 0);
::SetWindowText(edit, Text("ABRACADABRA"));
return(0);
}
That should fix your problem. I also know that if you can define _T, then it will work, but try to read up somewhere else. Sorry I don't know much, but that should get you moving.
|
|
|
|
|
Not according to Spy++.
"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
|
|
|
|
|
|
Ismaele.Jr wrote: i wish i want to write on the "Edit" control conteined in the dialogbox "type of character", accessible by the 'notepad.exe' main menu
Hi Ismaele,
I don't see this menu option when I open Notepad. Can you show me how you are opening this child dialog?
Best Wishes,
-David Delaune
|
|
|
|
|
Adam,
if you want to help me, please read :
http://www.codeproject.com/Messages/3244725/Re-FindWindowEx-handle-and-notepad-exe.aspx
and next
http://www.codeproject.com/Messages/3244045/Re-FindWindowEx-handle-and-notepad-exe.aspx
I'm disabled and too often i wrong in writing english : excuse me !
|
|
|
|
|
i hope you want to automate the a scenario where
you copy file name in clipboard and want to open that file in notepad wthout human interaction.
is it your requirement.
if so reply so that i can help you.
Величие не Бога может быть недооценена.
|
|
|
|
|
Yes,
it is like you described !
Superman posted me this code (after the last include) :
------------------------------------
#include <condefs.h>;
#include <windows.h>;
#include <stdio.h>;
#include <string.h>;
int main(int argc, char **argv)
{
HANDLE notepad = FindWindow(0, _T("Untitled - Notepad"));
HANDLE dialog = FindWindowEx(notepad, 0, 0, _T("Open"));
HANDLE edit = FindWindowEx(dialog, 0, _T("EDIT"), 0);
::SetWindowText(edit, _T("ABRACADABRA"));
return(0);
}
------------------------------------
but the compiler show me this error : [C++Error] provaIndiano.cpp(11): Call to undefined function '_T'.
|
|
|
|
|
i think above steps may be not enough for your requirements, if you have the same requirements as i mentioned above reply then following steps are enough for your goal.
1. FindWindowEx to find the notepad mentioned above.
2. Use SetCursor and mouse_event APIs to create a automated click on the menu File.
3. Generate anotherClick to get open from the menu.
4. GetWindowFromPoint API to get the handle of the open Window.
5. Get the handle of open window, from which you can find Edit for file input.
6. Get the handle of the edit as mentioned above code and set text to the edit as mentioned above code.
Величие не Бога может быть недооценена.
modified on Thursday, October 22, 2009 7:04 AM
|
|
|
|
|
Adam Roderick J 09 wrote: 2. Use SetCursor and mouse_event APIs to create a automated click on the menu File.
Using what coordinates?
"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
|
|
|
|
|
Coordinates are the offset from Notepad's ( top , left ) till Menu "File". Which is a fixed value for all the notepad's.
Величие не Бога может быть недооценена.
|
|
|
|
|