Richard - the fe content only becomes important if the open call fails. Note the weirdness, it's returning true yet with an invalid handle. In the debugger, I can see that the content of the file exception structure is "no error".
<italic>You're going to tell me what I want to know, or I'm going to beat you to death in your own house.
"Where liberty dwells, there is my country." B. Franklin, 1783
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
I suspect there is a lot more going on in that code than meets the eye. You cannot open a file successfully and then immediately find that the handle is bad; it implies a serious bug in the Win32 SDK which would affect just about every system on the planet. The reality is that there is a bug in your code that has, as yet, gone undetected, but without a lot more information we cannot begin to guess where it is.
One of these days I'm going to think of a really clever signature.
Lose all the casting. The cast to CString is implicit; it's not needed and is ugly. The cast from CString to LPCTSTR is in the same boat. As to your problem, I didn't look, I was distracted by all the unsavoury casting.
First off, I'm still new to coding in C++ and so I hope this is the right forum for my question...
I'm coding a very small utility for a niche need we've got where I work. Right now I've got things coded so that it uses CreateProcess to fire off another program we run. What I need to do is then have this utility stay open and running (the program that it kicks off can terminate the original program once it's done doing its thing - and I can't just wait for a return code because the program that gets kicked off may kick off others, and one of those might be the final item to run).
Right now it launches our program and then, since it's done doing all the code, it finishes up and quits. Is there any way to tell the thing to stay open and running? Kind of like a service (but not a service because I don't want to install anything).
What if the program remains open for an hour or three (I hope they close it sooner, but I have to think of the "what ifs")? Is the Sleep command going to be the right way to go, or am I going to create a problem when using it over an extended period of time?
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
Thanks, Wes. I was able to resolve the problem by installing Visual Studio 2012 Express and recommended components, removing the offending line from the Microsoft.Cpp.Platform.targets file (double-clicked error message), and compiling as Release.
It might depend on the implementation of the multimap. I checked it long ago but if I remember right your erase() call sets back the allocation to a minimum, identical to the allocation performed by the default ctor of multimap (at least in the SGI stl implementation of Visual C++ I used at the time). Note that even newly created empty std containers have a small piece of memory preallocated and some containers (like std::vector) dont shrink the size of the allocated memory area (capacity) even if you erase items.
A trick that seems to reset the allocated memory of any std containers regardless of stl implementation and container type is the following:
typedef std::multimap<int,int> MyMap;
// We create a new map instance and we swap its contents with the other "big" container instance.
// This swap operation replaces the pointers inside the two containers so after the swap() the
// global_map contains the small newly allocated blocks, and empty_map contains the big mem blocks
// previously owned by global_map. Note: when empty_map runs out of scope it releases the big block.
// This trick works with other stl container types too.
Why mix std::strings and MFC CStrings? And yes, the memory used to store the map's contents is freed since the map will handle destructing its contents and the contents don't require any manual cleanup.