I know how to read/write files and how to create browse dialog, but I can't figure out how to connect these two.
I want browse dialog to assign path (of a file that user has selected) to a variable, how would I do that?
do you know how to get the selected filename(include path) from your browse dialog?
if you know, just read/write the file.
if you do not know, please tell me how you create your browse dialog
I know now, I figured I should create a variable that gives CString type value instead of default "Control" variable.
But I have one other problem: whenever I use "browse control" and then exit the application, VS 2010 outputs
Detected memory leaks!
Dumping objects ->
{447} client block at 0x003BF490, subtype c0, 212 bytes long.
a CMFCVisualManager object at $003BF490, 212 bytes long
Object dump complete.
The program '[5004] MFC read write.exe: Native' has exited with code 2 (0x2).
The program exits with code 0x0 if I press premade "OK" button instead of X button, so I think that last line isn't related to the rest.
I noticed these memory leaks before. They always appear whenever user opens browse dialog even if I just create browse control via Toolbox and do nothing else.
EDIT: Same thing happens even if user doesn't open browse dialog. Just adding browse control from Toolbox in Visual Studio 2010 to fresh MFC project, then debugging application and closing it, produces the same thing.
You have probably allocated an array from the heap, and it was not de allocated. Check the memory address 0x003BF490 at Visual Studio and it will probably give you a hinch of what is going wrong.
Once you have a CFileDialog instance, you can call its GetPathName() method that retrieves a CString. With this CString you can use C or C++ functions for file handling or directly use Windows APIs. The point to bind the dialog to the file is the GetPathName() method.
Perhaps if you have dynamically allocated CFieDialog, you will have to de allocated it.