Question

I am studying the Windows programming by using the book

Programming.Windows.5th.Edition(Charles Petzold).

When I doing the Figure 3-1. The HELLOWIN program,I find that when I use the hotkey ctrl+F5 to run the exe,I can hear the sound(Hello windows 98),but when I run the exe in the directory Debug,no sound could be heard.After putting the exe together with HelloWin.wav,everything is OK.How could this happen?I am using the win7(simplified Chinese Edition) and Visual Studio 6(Enterprise Edition.)

enter image description here

Was it helpful?

Solution

Presumably this is an issue of relative paths. My guess is that you refer to the .wav file using a relative path and just name it "HelloWin.wav". This is relative to the current directory.

When you double click the .exe the current directory is the exe directory and the .wav is not found. When you press Ctrl+F5 from the IDE, the IDE sets the current directory to be the project directory and thus the file is found.

OTHER TIPS

It's all to do with current directories. When executing it from Visual Studio, it will use the project directory as the current directory and so your program will find the wav file in that directory.

When you run the exe directly, it will use the Debug directory as the current directory and ,since the wav file is not in there, not find the sound file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top