How do I get the path to a file added to a Windows Mobile app?
I have added a wav file to my Windows Mobile application and I want to use MobilePlaySound in CoreDll.dll to play it.
FileName is one of its parameters:
MobilePlaySound(fileName, IntPtr.Zero, (int)(Flags.SND_ASYNC | Flags.SND_FILENAME));
I create a new "sound" folder, add "start.wav" to the project and set its "Build Action" property to "Embedded Resources".
Then I set filename:
fileName = "\\Program Files\\myApp\\sound\\start.wav";
But the sound doesn't play at all. What is the correct filepat?
a source to share
By setting the build action to "Embedded Resource", the file will be compiled into your assembly as a resource. This means that the wav file will be embedded in your .exe or DLL file and it will not appear in the file system. Because of this, you cannot pass the filename for the wav for some method that it needs.
There are two ways to solve this problem: if you really want the wav file inline, you have to extract the resource and write it to a file on the filesystem at runtime. Then you can pass the name of this file to the MobilePlaySound method. I personally would not choose this solution in this case.
Another solution is not to embed the wav file as a resource, but to let it live as its own file on the filesystem. To do this, set the build action to "Content" and set the "Copy to Output Directory" option to "Copy Always" or "Copy if New". This will force the compiler to include the file in the output file. In this case, your guess about where the file is located is correct.
In short:
- Build Action = "Content"
- Copy to output directory = "Copy always" or "Copy if new"
a source to share