Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Resource file

Resource file

Scheduled Pinned Locked Moved Visual Basic
tutorialquestionlearning
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mihei89
    wrote on last edited by
    #1

    How to play WAV file from resource ??? Mihei89

    G 1 Reply Last reply
    0
    • M mihei89

      How to play WAV file from resource ??? Mihei89

      G Offline
      G Offline
      ghost181
      wrote on last edited by
      #2

      Hi, you can try the code below using System; using System.Runtime.InteropServices; using System.Resources; using System.IO; namespace Win32 { public class Winmm { public const UInt32 SND_ASYNC = 1; public const UInt32 SND_MEMORY = 4; // these 2 overloads we dont need ... // [DllImport("Winmm.dll")] // public static extern bool PlaySound(IntPtr rsc, IntPtr hMod, UInt32 dwFlags); // [DllImport("Winmm.dll")] // public static extern bool PlaySound(string Sound, IntPtr hMod, UInt32 dwFlags); // this is the overload we want to play embedded resource... [DllImport("Winmm.dll")] public static extern bool PlaySound(byte[] data, IntPtr hMod, UInt32 dwFlags); public Winmm() { } public static void PlayWavResource(string wav) { // get the namespace string strNameSpace= System.Reflection.Assembly.GetExecutingAssembly().GetName().Name.ToString(); // get the resource into a stream Stream str = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream( strNameSpace +"."+ wav ); if ( str == null ) return; // bring stream into a byte array byte[] bStr = new Byte[str.Length]; str.Read(bStr, 0, (int)str.Length); // play the resource PlaySound(bStr, IntPtr.Zero, SND_ASYNC | SND_MEMORY); } } } ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::; To use the class, you can make the call as follows: private void button2_Click(object sender, System.EventArgs e) { Win32.Winmm.PlayWavResource("chimes.wav"); }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups