CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    2

    IWMPPlayer4 issues (COM)

    Hi all, I'm brand new to COM development and I'm trying to have a simple program control a WMP instance. In the following example, the code is supposed to launch WMP and load the specified streaming URL, wait for user input, mute the sound, wait for user input and then close WMP. However, what actually ends up happening is the player launches and loads the URL correctly, but the mute and close commands are ignored (even though put_mute returns 0/S_OK). Here is the code:
    Code:
    #include <iostream>
    #include <windows.h>
    #import "wmp.dll" no_namespace named_guids high_method_prefix( "I" )
    
    using namespace std;
    
    int main()
    {
    	IWMPPlayer4* player;
    	CoInitialize(NULL);
    	HRESULT res = CoCreateInstance(CLSID_WindowsMediaPlayer, NULL, CLSCTX_INPROC_SERVER, IID_IWMPPlayer4, (void**)&player);
    	if (SUCCEEDED(res))
    	{
    		player->IopenPlayer(L"http://38.99.208.186/cjcl");
    		system("pause");
    		IWMPSettings* settings;
    		player->get_settings(&settings);
    		cout << settings->put_mute(TRUE) << endl;
    	}
    	system("pause");
    	player->Iclose();
    	player->Release();
    	CoUninitialize();
    	return 0;
    }
    Does this have anything to do with the fact I'm trying to do this from within a console app? If so, what part of a Win32 app is needed for IWMPPlayer4 to work correctly (e.g. is it the message loop, etc)? Also, I am using VS2008 EE.

    Thanks in advance.
    Last edited by GeneR; March 1st, 2009 at 10:46 PM.

  2. #2
    Join Date
    Mar 2009
    Posts
    2

    Re: IWMPPlayer(4)/COM issues

    Indeed, my suspicions were correct -- I needed the message loop (but beyond that console apps seem to work fine). I just added the Get/Translate/Dispatch triplet at the end of the if condition and everything worked.
    Last edited by GeneR; March 2nd, 2009 at 01:22 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured