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. C / C++ / MFC
  4. Playing Sound with Managed C++ .NET

Playing Sound with Managed C++ .NET

Scheduled Pinned Locked Moved C / C++ / MFC
csharpc++question
18 Posts 5 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.
  • C Christian Graus

    allenmpcx wrote: I understand .NET MC++ easier than the others I have tried. I've heard C# is easier and it looks exactly like C++ to me. Thanks for the information though, maybe I'll investigate MFC. I don't know what you've tried, but MFC apps are pretty simple, if you know a bit of C++. The framework is not perfect, but it's a huge improvement on Win32. C# looks a lot like C++, so it's easy to move, and it's definately a much easier way to get to WinForms than MC++ is. I'd investigate C# and MFC as good alternatives. DirectX is available in both, but it's a ton easier in C#, because C# handles all the COM pointer stuff for you. Christian Graus - Microsoft MVP - C++

    A Offline
    A Offline
    allenmpcx
    wrote on last edited by
    #9

    Now I'm extremely intrigued. Most of my application was written in MC++ and if I were to transfer it over to C#, would .NET still create the .exe file, and would I get that Resource Editor GUI that is provided? If so, I'd switch my application to C# right now. Mike - I love to program!

    C 1 Reply Last reply
    0
    • A allenmpcx

      Now I'm extremely intrigued. Most of my application was written in MC++ and if I were to transfer it over to C#, would .NET still create the .exe file, and would I get that Resource Editor GUI that is provided? If so, I'd switch my application to C# right now. Mike - I love to program!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #10

      allenmpcx wrote: Most of my application was written in MC++ and if I were to transfer it over to C#, There's no automatic conversion, but you could certainly put your existing non GUI code in a dll and call it from C#. allenmpcx wrote: would I get that Resource Editor GUI that is provided? I believe the resource editor in C# is better than the C++ one, unless MC++ gives you the same one. Christian Graus - Microsoft MVP - C++

      A 1 Reply Last reply
      0
      • C Christian Graus

        allenmpcx wrote: Most of my application was written in MC++ and if I were to transfer it over to C#, There's no automatic conversion, but you could certainly put your existing non GUI code in a dll and call it from C#. allenmpcx wrote: would I get that Resource Editor GUI that is provided? I believe the resource editor in C# is better than the C++ one, unless MC++ gives you the same one. Christian Graus - Microsoft MVP - C++

        A Offline
        A Offline
        allenmpcx
        wrote on last edited by
        #11

        Not to prolong this, but how would I put all my code inside of a .dll and call it from C#? If its too complicated, or takes too long, I might just re-write everything to make it more efficient and learn C#. As long as I can have the .exe and the Resource Editor, I'll be fine. Thanks for the information, I love programming epiphanies. Mike - I love to program!

        C 1 Reply Last reply
        0
        • A allenmpcx

          Not to prolong this, but how would I put all my code inside of a .dll and call it from C#? If its too complicated, or takes too long, I might just re-write everything to make it more efficient and learn C#. As long as I can have the .exe and the Resource Editor, I'll be fine. Thanks for the information, I love programming epiphanies. Mike - I love to program!

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #12

          Well, you'd basically create a managed C++ dll and move the code into it. Your current project would be set up to create an exe. If the code can be easily ported to c#, I'd do that instead, the cross language thing could be a pain later. Christian Graus - Microsoft MVP - C++

          A 1 Reply Last reply
          0
          • C Christian Graus

            Well, you'd basically create a managed C++ dll and move the code into it. Your current project would be set up to create an exe. If the code can be easily ported to c#, I'd do that instead, the cross language thing could be a pain later. Christian Graus - Microsoft MVP - C++

            A Offline
            A Offline
            allenmpcx
            wrote on last edited by
            #13

            How would I create a C# Forms application using Microsoft Visual Studio .NET? Mike - I love to program!

            C 1 Reply Last reply
            0
            • A allenmpcx

              How would I create a C# Forms application using Microsoft Visual Studio .NET? Mike - I love to program!

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #14

              new/project/c#/windows application. Something like that. Christian Graus - Microsoft MVP - C++

              A 1 Reply Last reply
              0
              • C Christian Graus

                new/project/c#/windows application. Something like that. Christian Graus - Microsoft MVP - C++

                A Offline
                A Offline
                allenmpcx
                wrote on last edited by
                #15

                One last question, then I'm all done, and I greatly appreciate the information: Would you happen to know how to add a double buffer to a Panel? In C++ I did this: Panel->SetStyle(ControlStyles::UserPaint, true); Panel->SetStyle(ControlStyles::AllPaintingInWmPaint, true); Panel->SetStyle(ControlStyles::DoubleBuffer, true); However I got errors about accessing SetStyles when it is of type Panel. However, I paint everything on the panel. Is there a way to add a double buffer? Mike - I love to program!

                C 1 Reply Last reply
                0
                • A allenmpcx

                  One last question, then I'm all done, and I greatly appreciate the information: Would you happen to know how to add a double buffer to a Panel? In C++ I did this: Panel->SetStyle(ControlStyles::UserPaint, true); Panel->SetStyle(ControlStyles::AllPaintingInWmPaint, true); Panel->SetStyle(ControlStyles::DoubleBuffer, true); However I got errors about accessing SetStyles when it is of type Panel. However, I paint everything on the panel. Is there a way to add a double buffer? Mike - I love to program!

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #16

                  I use those same calls to make my app double buffer. I wonder why you can't do it to a control. I draw all my images myself, and if you do that, you can certainly set double buffering up like that in your main window. Christian Graus - Microsoft MVP - C++

                  1 Reply Last reply
                  0
                  • A allenmpcx

                    In all honesty, I have only been programming for about two years, and most of it has been basic console programs with C++. I was going to be an architect. This is all very new to me, and I have tried other languages, but it doesn't mean I'm not open to others. I understand .NET MC++ easier than the others I have tried. I've heard C# is easier and it looks exactly like C++ to me. Thanks for the information though, maybe I'll investigate MFC. Mike - I love to program!

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #17

                    A piece of advice - the MVP next to Christian's name means "Microsoft Valued Partner" and there are about 70 for C++ on the planet so you have one of the top guys around helping you out. I would suggest MFC too, the DirectX SDK comes with lots of examples including ones on playing sound. Basically you put individual sounds into secondary buffers and they are combined into the output buffer which goes to the output device. For samples under 1MB you can just read them into the secondary buffers, above that it is reccomended you use streaming into the secondary buffers. I hope this helps. Elaine :rose: The tigress is here :-D

                    1 Reply Last reply
                    0
                    • A allenmpcx

                      Hello, is there a way to play multiple sounds (.wav files) using managed C++ in .NET for my application? I am a newbie so I need details. Mike - I love to program!

                      G Offline
                      G Offline
                      GKarRacer
                      wrote on last edited by
                      #18

                      To answer the original question (at least for C++): If all you want to do is play wave files, then you can simply call the PlaySound function. If you need to anything more sophisticated like mixing sound files together, etc. then you'll probably need DirectX. But for basic wave files, the PlaySound function is very easy. From regular C++ (someone else will have to help with proper imports for the managed environment):

                      #include "mmsystem.h"
                      #pragma comment( lib, "winnmm.lib" )

                      void SomeFunction()
                      {
                      PlaySound( szSoundFileName, NULL, SND_FILENAME | SND_ASYNC | SND_NOWAIT );
                      }

                      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