简体   繁体   中英

File path of embedded resource?

I've got some code which plays a WAV file via a DLL. It was playing it by pointing to a directory path, but I would like to include it in my EXE. So, I've put it as a resource. Problem is, how do I point to it correctly?

UInt32 stream = BASS.BASS_StreamCreateFile(Properties.Resources.MYWAVFILE, 0, 0, BASSFlag.BASS_DEFAULT | BASSFlag.BASS_SAMPLE_LOOP);

The original code had this:

UInt32 stream = BASS.BASS_StreamCreateFile(@"C:\MYWAVFILE.WAV", 0, 0, BASSFlag.BASS_DEFAULT | BASSFlag.BASS_SAMPLE_LOOP);

You can see the first argument is where I need to put it. However, the compiler complains with this error:

Severity Code Description Project File Line Suppression State Error CS1503 Argument 1: cannot convert from 'System.IO.UnmanagedMemoryStream' to 'string' MyProgram C:\\Users\\LOLCATS\\Documents\\Visual Studio 2015\\Projects\\MyProgram\\MyProgram\\Form1.cs 30 Active

Thanks.

Properties.Resources.MYWAVFILE is not a path string. It's a representation of the file stored in memory, hence it's System.IO.UnmanagedMemoryStream .

Either find a overloaded function that takes in streams instead of file paths in string form or copy the embedded resource to disk and use it :

using (var fileStream = File.Create("C:\\Path\\To\\File"))
{
  Properties.Resources.MYWAVFILE.CopyTo(fileStream);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM