Is there a better way to Save the files in Visual Studio? - c++

After making some changes in xyz.cpp file, when I am trying to save the whole project it asks to save files in the directory and ultimately it didn't get saved and an error message comes as
The Process cannot access the files "c:\ml/src.cpp" because it is being used by another process.
Usually to get rid of this error I use to open another .cpp file and make some chnages in that and then try to save so that other unsaved files gets save with this and sometimes it didn't work well.
was wondering if there is any better way of handling it?

You should:
Download ProcessExplorer
Go to Find -> Find Handle or DLL
Navigate to your file path:
ProcessExplorer will tell you wich process are using/blocking your file.

Related

How can I get the path of a file I am trying to open using file explorer's "open with" dialog box

So I have a very specific question that I realize is a bit stupid, however regardless of how I search for it, nothing really shows up.
I am aware that I can use system() to execute commands in cmd, and I am so done with writing
g++ <filename.cpp> & a.exe & del a.exe
every time I want to compile, build and then delete the exe of a c++ app. Therefore I plan on making a simple handling software using c++ to open other c++ apps. It will just take the name of the app I am trying to run and do all of the things said in the above code. My problem is, when using cmd I can write the name of the file I am running, however how can I get the name of the file if I double click?
Example would be to always open cpp files with the program I am making. Upon double click, it will open a cmd console, type the code for me and execute the program. Then when I close the program, the cmd will close. I am aware how to do all of that, except how to get the file name of the file I am opening using the program.
I have tried using different libraries and have not found anything similar or at least nothing that states of this use. I am not expecting the whole program nor do I want it, I realize it is a simple project, however I am struggling with this one part and am unable to find a solution.
I simply want to make my own starting script. Then in file explorer I right click on any .cpp file, click open with and the dialog box shows up. I click the program I have created and there I compile the .cpp file with the script of my choice, however I do not understand how to get the path from right click, open with, and using my own program. This is all withing file explorer, not within the software I am making.

Unable to open SAS EG Project

I can't open my SAS EG Project with the error message :
"Unable to open file ...abc.egp as valid project file"
This is happen because when my hard disk is full and I was trying to save the project, so it wouldn't let EG to finish writing the project changes.
I've tried to clear the history but no luck.
Thanks
I suspect your SAS EG file might be irreversibly corrupt, so the focus is then on recovery of the file or its content.
If your disk drive is NTFS based, you might be able to recover the file. Check for previous versions in the file properties.
Also, what was the structure of your file inside? If it was a code driven program, then you can make a copy of the file, change extension to "zip" and then unzip the file or look inside for its contents. SAS EG projects are just ZIP archives with XML maps and related SAS code.
The last option is to see if you have logging enabled in your SAS EG. If you do, then all the code you run on that date would be available in your logs, so you can recover the code from the logs.
Regards,
Vasilij

Saving AVI files in C++ after creating

I'm using Wischik's example code for creating AVI files, however after I run the code and it exits successfully no AVI file is created. I looked through the code and cannot find where it writes/saves/creates an AVI file on your computer. Does anyone know where the code saves AVI file or if it doesn't, a way to make it save the AVI file created to your computer? Thanks
link to source code here
Wischik source code
You should find test.avi in the project directory. Since you know it's name, you could also use Windows explorer to search for it.
To examine further, (assuming you are using VC++), goto
Tools > Options > Projects and Solutions > VC++ Directories,
and Show Directories for Include files.
That will tell you where the headers are.
Alternatively, set a break point at the line where AVIFileOpen is called, and follow the execution path to see what it does.

WxWidgets - Unable to load images

I recently started working with WxWidgets (2.9.4) and was working through a tutorial I found, but it seems that I'm unable to load any images. I've already properly used the handler (for PNG) and the problem happens at run-time. Below is an image of the popup that is displayed when attempting to run the program.
Here is the code:
wxPNGHandler *handler = new wxPNGHandler;
wxImage::AddHandler(handler);
wxBitmap exit;
exit.LoadFile(wxT("exit.png"), wxBITMAP_TYPE_PNG);
wxToolBar *toolbar = CreateToolBar();
toolbar->AddTool(wxID_EXIT, exit, wxT("Exit"));
toolbar->Realize();
Connect(wxID_EXIT, wxEVT_COMMAND_TOOL_CLICKED, wxCommandEventHandler(mainWindow::exitProg));
Any help is appreciated.
EDIT: I forgot to mention that when I click Cancel, this happens:
I placed the exit.png file in the build directory (/Debug or /Release) as well as the source code directory, but it still has yet to see it.
What is your working directory?
If you are using visual studio and running using the interface ( F5 or ctrl-F5 or the little run button in the toolbar ) then your working directory is the folder containing the project file. So try copying your image file there.
Or open a command window, cd to one of your build directories, and run your app from the command line.
In general, to avoid this sort of problem, I alter the project properties so that the executable is NOT stored in one of the build folders, but in a new folder ( which I usually call 'bin' - my unix roots are showing! ) and also alter the debugging properties so that the working directory is the bin folder.
There are a couple of advantages to this technique:
Both the release and trhe debug version use the same folder, so you only need one copy of any extra file, like your image file.
It is easy to see the executable and extra files in the working directory without being distracted by all the .obj files that end up in the build folders
IMHO this is well worth the little extra trouble in maintaining non default project properties.
First of all, to avoid problems deep inside wxToolBar, always check the return code of LoadFile() or, alternatively, use wxBitmap::IsOk() to check that the bitmap was successfully loaded.
Second, while adding the handler explicitly as you did is perfectly fine, I'd recommend to just call wxInitAllImageHandlers() as it's simpler and has no real drawbacks unless you are looking to create the smallest program possible.
Finally, to address your real problem, the file clearly doesn't exist at the path you're loading it from. You can, of course, solve this by being careful not to change your working directly (or restore it after changing it) in your program and by placing the file in the correct place. But this is, as you discovered, error-prone, so a better idea is to always use full paths to your resources. To construct them, you will find wxStandardPaths useful, in particular its GetResourcesDir() method.

Open file to display content in C++

I have 2 questions to ask regarding opening files (any kind of files) using C++. I am currently working on a GUI program and I want to add a changelog in txt form. Also I want a menu in my program to open that changelog.txt with the default text editor every user has installed or to simply put it to open that text file. Please keep in mind that I want to open the file for display NOT in the program for input/output.I know I can do that using
system("notepad.exe filepath.txt");
or to open them with the preset program:
system("filepath.txt");
The problem is that both of those open a command line behind the notepad. I know there is another command to open files using Win32 API called CreateProccess() but my compiler doesn't recognise that command (OpenWatcom W32).
So here are my questions:
1) Is there any other command to open files or is there a way to stop the command line from opening when using system command?
2) How do you define in Windows that the text file is in the current program folder? I mean instead of giving the entire filepath which will change from user to user is there any way to "tell" the program that the file is always on the current folder that the program is in?
I am sorry for any errors, if you want any clarification please let me know.
CreateProcess would be the wrong function to use here. That would require you to decide which process to run. The user may prefer to use a text editor other than Notepad, I know I do! The right way to do this on Windows is to ask the shell to open the file with whatever program the user has associated with the file. The ShellExecute function does this.
Call it like this:
ShellExecute(
MainWindowHandle,
"open",
FullyQualifiedTextFileName,
NULL,
NULL,
SW_SHOWNORMAL
);
You will need to include the Shellapi.h header file and link to the Shell32.lib library. If your compiler does not include these files, and I would be surprised if that was the case, then you can get them from the Platform SDK. That said, if you are serious about programming on Windows you should get hold of a tool that gives you access to the Windows API.
I do recommend that you use a fully qualified path for a task like this. Since your text file is located in the same directory as the executable you should simply join that directory to your text file's name. Get hold of the full path to the executable by calling GetModuleFileName passing NULL for the hModule parameter.