积极答复者
如何在自己的程序中嵌入Windows Media Player(不使用MFC和ATL等)

问题
-
本人初次在程序中尝试使用COM组件,所以无所适从。
个人感觉WMP是基于COM的,那么在程序中是不是就可以采用纯COM的方式加入WMP呢?(我说的纯COM就是不使用任何被包装过的接口,比如从MFC或者ATL提供的接口调用)
我曾经试着在程序中嵌入IE浏览器,成功了,感觉过程不复杂,于是,用相似的方法嵌WMP,结果编译通过,但报了一个链接错误。
我把代码和错误提示列于下,恳请高手指点迷津!
#include <windows.h>
#include <tchar.h>
#include <wmp.h>
#include <objbase.h>int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR CmdLine, int CmdShow)
{
IWMPPlayer *pWmp = NULL;
HRESULT hr;if(CoInitialize(NULL) != S_OK)
return 1;
hr = CoCreateInstance(CLSID_WindowsMediaPlayer, NULL, CLSCTX_LOCAL_SERVER, IID_IWMPPlayer, (void **)&pWmp);
if(FAILED(hr))
return 1;
//瞎写的,想看看会出现什么效果,但现在链接还没通过呢
hr = pWmp->put_URL((BSTR) TEXT("E:\\Video\\123.avi"));
pWmp->Release();
CoUninitialize();
return 0;
}
链接错误如下:
1>Compiling...
1>main.cpp
1>Linking...
1>main.obj : error LNK2001: unresolved external symbol _CLSID_WindowsMediaPlayer
1>main.obj : error LNK2001: unresolved external symbol _IID_IWMPPlayer
1>H:\Users\LHL\Documents\Visual Studio 2008\Projects\test\Debug\test.exe : fatal error LNK1120: 2 unresolved externals
难道CLSID_WindowsMediaPlayer和IID_IWMPPlayer不能这么用?我怎么记得嵌IE浏览器的时候也类似这么写的就可以呢?
我没装SDK?也不是吧。MSDN上面全是ATL和MFC的示例代码,也没法参照。
LHL- 已编辑 lhlzhxh 2009年7月1日 16:04
答案
-
需要连接Windows Media Player SDK的库。你没写容器。IE、ADO这样的COM组件不需要容器,但是一些组件也是ActiveX,需要ActiveX容器。建议在写程序之前先看看Windows Media Player SDK。
Please mark the post answered your question as the answer, and mark other helpful posts as helpful. This posting is provided "AS IS" with no warranties, and confers no rights.
Visual C++ MVP- 已编辑 Sheng Jiang 蒋晟Moderator 2009年7月1日 17:08
- 已标记为答案 Tim Li 2009年7月6日 10:39
-
#import "C:\WINDOWS\system32\wmp.dll " raw_interfaces_only, raw_native_types, no_namespace, named_guids
Please mark the post answered your question as the answer, and mark other helpful posts as helpful. This posting is provided "AS IS" with no warranties, and confers no rights.
Visual C++ MVP- 已标记为答案 Tim Li 2009年7月6日 10:39
全部回复
-
需要连接Windows Media Player SDK的库。你没写容器。IE、ADO这样的COM组件不需要容器,但是一些组件也是ActiveX,需要ActiveX容器。建议在写程序之前先看看Windows Media Player SDK。
Please mark the post answered your question as the answer, and mark other helpful posts as helpful. This posting is provided "AS IS" with no warranties, and confers no rights.
Visual C++ MVP- 已编辑 Sheng Jiang 蒋晟Moderator 2009年7月1日 17:08
- 已标记为答案 Tim Li 2009年7月6日 10:39
-
#import "C:\WINDOWS\system32\wmp.dll " raw_interfaces_only, raw_native_types, no_namespace, named_guids
Please mark the post answered your question as the answer, and mark other helpful posts as helpful. This posting is provided "AS IS" with no warranties, and confers no rights.
Visual C++ MVP- 已标记为答案 Tim Li 2009年7月6日 10:39