C - How can get file by window explorer (console) - c

I'm looking for function that open window explorer and get file the user selected. I knew how to open window explorer to this my question, but I was asking the wrong question. I want to enable read to the user selects a file.
While trying to search, I found OpenFileDialog(). But this function looks like need GUI. Am I right? (My program runs only console)
How can I open windows explorer on the console and get the file from the user?
I'm a beginner of C. So my question may seem ridiculously easy. But if you give me the answer I really appreciate it. Thanks :)

You are looking for the GetOpenFileName function. (OpenFileDialog is for .NET applications; if you are using C then you are not using .NET).
According to MSDN, this has been superseded by the Common Item Dialog system, but that system is much more complicated, requires COM and isn't necessary if you are only selecting files. GetOpenFileName will still work for the foreseeable future.

To open Windows explorer:
system("start \"\" \"c:\\program files\"");
To open a specific file:
system("start \"\" \"c:\\program files\\file.txt\"");

Related

Open file with my application

How can I handle automatically opening a file with my Windows Forms application? As in, I double-click the file and my application pops up and knows to open the file.
I'm assuming I somehow have to add an entry in the registry or something like this, and handle command line parameters, but I can't quite figure out the way to go about this.
Attached an image for clarity, it's pretty much what I want to achieve. (I'll be using my own file extension so I don't mess up other programs as well)
There's an answer in MSDN about how to associate your application with an extension. The information about shell file extension associations is stored in the registry.
Or, to set it interactively, make use of the "Open With" > "Choose default program..." feature.

Issue adding a Access File as a Data Source in Visual Studio

Good evening,
I seem to be having an issue with adding a Access Database as a Data Source in my Visual Studio project. When I launch the New Data Source wizard and go through the first two steps I land at the 'Choose Your Data Connection' window, where I have to choose 'New Connection...'. Once this window has opened I choose the first option which is 'Microsoft Access Database File' and this is where I'm having my issue. It seems the way that it is supposed to work, and how it works for everyone I know, is that it is supposed to open a New Connection window similar to this:
(This is a screenshot I grabbed off Google as I cannot actually get to this step, I realize it's an old photo but this is generally what I'm supposed to see)
First Screenshot
What I actually get is this:
Second Screenshot
And that's where I'm stuck. Any ideas?
Any help is appreciated. Thanks.
Andrew
If anyone else has this issue, running the Windows System File Checker tool seems to repair it. To run, open a command prompt as administrator and type:
sfc /scannow
Once that completes (it may take a while), reboot and you should be good to go.

ld.exe: cannot open output file ... : Permission denied

I recently installed CodeBlocks with mingw32 on Windows 7 Ultimate 32bit in order to dust off my c skills, but this problem has me somewhat stumped.
I decided to fire off a short Fibonacci generator to make sure my setup was working, but I ran into a hurdle.
The program compiles, links and whatnot like a charm and I get a corresponding executable which runs as expected.
The problems occur if I try to compile again, then I get the following:
c:/codeblocks/mingw/bin/../lib/gcc/mingw32/4.4.1/../../../../mingw32/bin/ld.exe: cannot open output file bin\Debug\Fibonacci.exe: Permission denied
I can't even edit the permissions of the generated executable.
I've checked the usual suspects:
Executable is verily not running.
Path to executable is read/writable to mingw32 (otherwise it wouldn't be able to build in the first place)
I'm not running cygwin in any shape or form.
And now for the funny bit: Usually after a few minutes, any executables generated by mingw32 which are displaying this Access Denied behaviour will automatically vanish without any intervention from me.
I've googled this somewhat, but most of the other results were either vague or inapplicable.
I wonder whether there is some Windows 7 security setting playing havoc with my .exe's, but I'm not that knowledgeable about Win 7 as to know where to begin searching.
Any one have any ideas?
I had exactly the same problem right after switching off some (in my opinion unneccessary) Windows services. It turned out that when I switched ON again the "Application Experience" everything resumed working fine.
May be you simply have to turn on this service? To switch ON Application Experience:
Click the Windows start buttonn.
In the box labeled "Search programs and files" type services.msc and click the search button. A new window with title "Services" opens.
Right click on "Application Experience" line and select "Properties" from popup menu.
Change Startup type to "Automatic (delayed start)".
Restart computer.
Application Experiences should prevent the problem in the future.
Your program is still running. You have to kill it by closing the command line window.
If you press control alt delete, task manager, process`s (kill the ones that match your filename).
If you think the executable is locked by a process, try Process Explorer from SysInternals. In the File/handle, enter Fibonacci.exe and you should see who holds the file.
If it is not enough, you can use Process Monitor (from SysInternals, again) to follow the activity of all processes on your system on Fibonacci.exe.
With a little bit of analysis (call stacks), you'll may find out why the access to the file is denied and what make it disappear.
Problem Cause :
The process of the current program is still running without interuption.
(This is the reason why you haven't got this issue after a restart)
The fix is simple :
Go to cmd and type the command taskkill -im process_name.exe -f
Eg:
taskkill -im demo.exe -f
here,
demo - is my program name
The Best solution is go to console in eclipse IDE and click the red button to terminate the program.
You will see the your program is running and output can be seen there. :) !!
I had the same behaviour, and fixed it by running Code::Blocks as administrator.
Open task manager -> Processes -> Click on .exe (Fibonacci.exe) -> End Process
if it doesn't work
Close eclipse IDE (or whatever IDE you use) and repeat step 1.
I had a similar problem. Using a freeware utility called Unlocker (version 1.9.2), I found that my antivirus software (Panda free) had left a hanging lock on the executable file even though it didn't detect any threat. Unlocker was able to unlock it.
Got the same issue. Read this. Disabled the antivirus software (mcaffee). Et voila
Confirmed by the antivirus log:
Blocked by Access Protection rule d:\mingw64\x86_64-w64-mingw32\bin\ld.exe d:\workspace\cpp\bar\foo.exe User-defined Rules:ctx3 Action blocked : Create
It may be your Antivirus Software.
In my case Malwarebytes was holding a handle on my program's executable:
Using Process Explorer to close the handle, or just disabling antivirus for a bit work just fine.
i experienced a similar issue. Bitdefender automatically quarantined each exe-file i created by MinGW g++. Instead of the full exe-file i found a file with a weird extension 'qzquar'
testAutoPtr1.exe.48352.gzquar
When i opened quarantined items in Bitdefender i found my exe-file quarantined there.
I got this error when using the Atom editor and mingw (through a package called gpp-compiler) for C++. Closing the open console window fixed my issue.

Opening a file with the default viewer on Linux

I am working at an OS independent file manager (mostly Windows and Linux), and I am wondering if there is a Linux way to open a file in its default viewer. For example, open a html file with Firefox, an .avi with vlc, and so on.
On Windows, there is a function ShellExecute() that does that, but my understanding is that on Linux it is not that simple, and each desktop environment has a specific way.
I would appreciate any help with this.
You could use xdg-open(1). It works on all freedesktop compliant desktops.
The default programs for different mime-types are defined in /etc/mailcap and $HOME/.mailcap, indexed by file type and action (display, edit, print). The command line interface is run-mailcap. See also the manpages run-mailcap(1) and mailcap(5).
It depends what desktop environment you're using in Linux. Gnome for example has a MIME database you can use to find out what to launch for a given file.
Sahil Muthoo has given you good advice. I will just give further examples.
If xdg-open is not available you can also use "gnome-open" for GNOME and "kfmclient" for KDE.

What does explorer use to open a file?

I am attempting to hook into whatever explorer calls when a file is opened (double-click, context menu open, etc.), however I can't figure out which function that is.
Originally, I thought it was ShellExecute, as that does the same thing as far as I can tell, but after hooking into it I learned that it's only used when a new explorer window is opened.
Any ideas which function I should be hooking?
It sounds like the AppInit_DLLs registry key should be good enough.
Make a simple DLL and call the GetCommandLine() in your DllMain function to get the full command line to the application being executed.
There are the ShellExecute hooks, but now (after XP) are deprecated because everybody used them for the strangest purposes. Have a look at this for some more detail, and at this for some documentation.
If you want to intercept these things, just register yourself as the default verb for shell items. Here are some samples.
If you just want to know if someone has change some files you are interested in, you should register for change notifications via FindFirstChangeNotification() and related APIs.
Much simpler than writing a device driver ( but much less amusing ) is the MS research tool detours. Have fun!

Resources