Hello there!

I need to open PDF files from a C program. So, initially I have this solution:

ShellExecute(GetDesktopWindow(), "open", "c:\somefolder\myFile.pdf", NULL, NULL, SW_SHOWNORMAL);

However, this code has its limitations:

1. It works, but a shell window comes up and closes when opening the PDF file. Is there a way to avoid this? Maybe using another programming language?

2. This is Windows specific - I'd like to be able to do it in Linux as well.

3. What is the advantage of using this to using this one?

system("start c:\\somefolder\\myFile.pdf");

Thanks very much for any help!

[]s
Marcos

Recommended Answers

All 4 Replies

1. It DOES NOT work because you forgot to double backslashes in the file name string literal (see point #3 example in your snippet).
2. ? No platform-independent solution.
3. ShellExecute is a direct way to do the same job...

1. It DOES NOT work because you forgot to double backslashes in the file name string literal (see point #3 example in your snippet).

You're right. Actually my original file did have different letters after the slash ahd DID work. Anyway thanks for the tip.

2. ? No platform-independent solution.

I will ask this in a different way. Forget Windows. How do I get the same results in a) Linux and b) Mac?

And the first question, how to avoid the shell window, is actually the most important right now. I know there is a solution,... Any hints? :)

Thanks

[]s
Marcos

There should be an option to not create a console window for a "console" program. There is in Dev-C++ (with gcc).

Great! Actually, there is:

Toos->Compiler Options->Settings->Links->Do not create a console windows->Yes.

Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.