2

I have an old application written in C++ 6.0. This application manages some sound for alarming purpose in a manufacturing environment.

Now I would like to make some modifications and use Windows Media Player. My knowledge of C++ limited. Kind of lost in the pointers...

This is what I managed to do so far:

Used the class wizard to add the wrapper classes to wmplib.dll and included "wmp.h". in the .cpp file.

IWMPPlayer *player = new IWMPPlayer();
//player.SetUrl("http://streampoint.radioio.com/streams/57/45ec8c85a2a8a/listen.pls");
player->SetEnabled(true);
player->SetUrl("C:\\tada.wav");

IWMPControls *pControls = new IWMPControls();
*pControls = player->GetControls();

pControls->play();  

Any suggestions?

Thanks

Prix
  • 19,417
  • 15
  • 73
  • 132
pmaltais
  • 75
  • 1
  • 2
  • 6
  • You should be careful when storing the result of `new` in a plain pointer because making sure by hand that `delete` gets called even when an exception occurs in your function needs some attention. See http://stackoverflow.com/questions/106508/what-is-a-smart-pointer-and-when-should-i-use-one for details, or look what "Resource Acquisition Is Initialization" aka RAII is. But I don't really understand what your question is. Do you get any errors or are you asking how you can do a specific task? – mars Aug 10 '13 at 14:57
  • Thanks for the advice. What I need is just open the player and play a sound (eventually a stream from the internet). But I get the warning "Warning: attempt to call Invoke with NULL m_lpDispatch!" when executing SetEnabled() and SetUrl(). GetControls() causes an Access Violation. – pmaltais Aug 10 '13 at 15:15
  • What is C++ 6.0? I guess you mean MS Visual C++ 6, aka Visual Studio 98. I would strongly advise against its use in any current C++ development, including learning to program in C++. – Ulrich Eckhardt Aug 10 '13 at 15:55
  • Yes I really mean MS Visual Studio C++ 6. In fact I prefer developing in C# but the program I'm working on is in MSVC++6 and migration to C# is not possible, short term speaking. – pmaltais Aug 10 '13 at 16:14

1 Answers1

0

I Finally found a way.

At first, I wanted to do it without having to include the WMP ActiveX in the View. So I ended up adding it and then use ClassWizard to create the associated Member variable in the View.

The created member variable is of type CWNDPlayer4.

Here is the code I used:

m_BackgroundPlayer.SetUrl(m_Url);
m_BackgroundPlayer.GetSettings().SetVolume(100);
m_BackgroundPlayer.GetControls().play();

m_Url is the member variable associated with a text box in which the user types the URL.

I used Windows Media Player 10.00.00.4081 and my environment was Windows XP Pro SP3.

pmaltais
  • 75
  • 1
  • 2
  • 6