用directshow开发wince下mp3播放器
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
用directshow开发wince下mp3播放器
这是用evc写的一段代码:
#include <windows.h>
#include <streams.h>
#define CLASSNAME _T("VideoWindow")
IGraphBuilder *pGraph = NULL;
IMediaControl *pMediaControl = NULL;
IVideoWindow *pVidWin = NULL;
HWND g_hwnd;
void PlayFile(void)
{
// Create the filter graph manager.
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IGraphBuilder, (void **)&pGraph);
pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl); pGraph->QueryInterface(IID_IVideoWindow, (void **)&pVidWin);
// Build the graph.
pGraph->RenderFile(L"Test.avi", NULL);
//Set the video window.
pVidWin->put_Owner((OAHWND)g_hwnd);
pVidWin->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);
RECT grc;
GetClientRect(g_hwnd, &grc);
pVidWin->SetWindowPosition(0, 0, grc.right, grc.bottom);
// Run the graph.
pMediaControl->Run();
}
void CleanUp(void)
{
pVidWin->put_Visible(OAFALSE);
pVidWin->put_Owner(NULL);
pMediaControl->Release();
pVidWin->Release();
pGraph->Release();
}
// Message handler
long FAR PASCAL WindowProc( HWND hwnd, UINT msg, UINT wParam, LONG lParam) {
switch (msg)
{
case WM_DESTROY:
CleanUp();
PostQuitMessage(0);
break;
default:
return (DefWindowProc(hwnd, msg, wParam, lParam));
}
return(NULL);
}
// Main
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
WNDCLASS wc;
CoInitialize(NULL);
ZeroMemory(&wc, sizeof wc);
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
// wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
wc.lpszMenuName = NULL;
wc.lpszClassName = CLASSNAME;
RegisterClass( &wc );
g_hwnd = CreateWindow(
CLASSNAME,
_T("DirectShow Sample"),
NULL,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow( g_hwnd, nCmdShow );
UpdateWindow( g_hwnd );
PlayFile();
while( GetMessage( &msg, NULL, 0, 0 ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
CoUninitialize();
return msg.wParam;
}
编译后出现:
player.obj : error LNK2001: unresolved external symbol _IID_IVideoWindow
player.obj : error LNK2001: unresolved external symbol _IID_IMediaControl
player.obj : error LNK2019: unresolved external symbol __imp__CoCreateInstance referenced in function "void __cdecl PlayFile(void)" (?PlayFile@@YAXXZ)
player.obj : error LNK2001: unresolved external symbol _CLSID_FilterGraph
player.obj : error LNK2001: unresolved external symbol _IID_IGraphBuilder
player.obj : error LNK2019: unresolved external symbol __imp__CoUninitialize referenced in function _WinMain
player.obj : error LNK2019: unresolved external symbol __imp__CoInitializeEx referenced in function _WinMain
emulatorDbg/player.exe : fatal error LNK1120: 7 unresolved externals
不知道如何解决,各位大虾,麻烦帮我看看,给点提示,谢谢!
-----------------------------------------------------------------
出现的问题参考下贴: (代码用上面的代码好。
)
我定制了一个的sdk,MEDIAR42.加入了directshow.
在sdk的帮助中有个directshow的例子,如下:
#include <streams.h>
void __cdecl main(void)
{
IGraphBuilder *pGraph;
IMediaControl *pMediaControl;
CoInitialize(NULL);
// Create the filter graph manager.
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IGraphBuilder, (void **)&pGraph);
pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);
// Build the graph. (IMPORTANT: Change string to a file on your system.) pGraph->RenderFile(L"\\Hello_World.avi", NULL);
// Run the graph.
pMediaControl->Run();
// Block until the user clicks the OK button.
// The filter graph runs on a separate thread.
MessageBox(NULL, _T("Click me to end playback."), _T("DirectShow"), MB_OK);
// Clean up.
pMediaControl->Release();
pGraph->Release();
CoUninitialize();
}
然后我在pb4.2中建了一个console application,但编译出错,见下:
--------------------Configuration: MEDIAR42 - EMULATOR: X86 Win32 (WCE emulator) D ebug--------------------
Platform header files are up-to-date...
MEDIAR42 - 0 error(s), 0 warning(s)
--------------------Configuration: 1 - EMULA TOR: X86 Win32 (WCE emulator) Debug--------------------
Compiling...
1.cpp
Linking...
1.obj : error LNK2019: unresolved external symbol __imp__CoUninitialize referenced in function _main
1.obj : error LNK2001: unresolved external symbol _IID_IMediaControl
1.obj : error LNK2019: unresolved external symbol __imp__CoCreateInstance referenced in function _main
1.obj : error LNK2001: unresolved external symbol _CLSID_FilterGraph
1.obj : error LNK2001: unresolved external symbol _IID_IGraphBuilder
1.obj : error LNK2019: unresolved external symbol __imp__CoInitializeEx referenced in function _main
EMULA TOR__X86Dbg/1.exe : fatal error LNK1120: 6 unresolved externals Error PB2505: Error executing link.exe.
1.exe - 8 error(s), 0 warning(s)
请问是什么原因?谢了.
谢了,问题解决了。
LNK2001的错误在于少加了strmbase.lib,Strmiids.lib.
LNK2019的错误在于ole32.lib(在sdk的help里没有这个错误的回答)
但在com和directshow的相关内容中提到过,不过小弟误为quartz.lib了,所以一直在发呆。