0

I'v tried to use this code to open a text file in my program, but nothing is happening.

ShellExecute(NULL, "open", filename, NULL, NULL, SW_SHOW);

Note that system.start() is not working either.

kdopen
  • 8,032
  • 7
  • 44
  • 52
Nick Spot
  • 257
  • 2
  • 4
  • 12
  • possible duplicate of [What is the correct way to use ShellExecute() in C to open a .txt](http://stackoverflow.com/questions/11007537/what-is-the-correct-way-to-use-shellexecute-in-c-to-open-a-txt) – Barmar May 09 '13 at 00:42
  • Are you sure filename contains the full path to the file? And what's the return value of this call? – fvu May 09 '13 at 00:45
  • yes. But, as suggested by @Barmar with that post, the path doesn't include double //. maybe thats the problem – Nick Spot May 09 '13 at 00:47
  • if you need a literal \ in a C string you have to escape it, `"c:\testfile"` and `"c:\\testfile"` look totally different in code, and only the latter is correct. – fvu May 09 '13 at 00:49
  • well, i have used that same string with fopen and it works. should work here too as well dont it? – Nick Spot May 09 '13 at 00:50
  • Not necessarily, eg fopen can find a file when you just give it a filename if the file happens to be in the current working directory it's running in, but ShellExecute won't. Can you add the EXACT content of filename to your question? – fvu May 09 '13 at 00:53
  • You need to do some basic debugging here. For example, what's the return value from ShellExecute()? Does it indicate success (read the API docs for ShellExecute) or a specific failure? – jarmod May 09 '13 at 01:00
  • Check out what says return value of `ShellExecute()` and/or `GetLastError()` functions. Also,Where/how is `system.start()` defined? – Jack May 09 '13 at 01:17
  • i printed the output as an int and it returns 2, i dont know the meaning and neither doc explains it – Nick Spot May 09 '13 at 01:51
  • well, it turned out to be an error in the syntax of execute shell. that post solved my problem. ty – Nick Spot May 09 '13 at 01:58

0 Answers0