(The Question was updated)
Am trying to play the video in c#.
I have the dll which is containing the function to play the video. The only thing i need is that the video has to play in the picture box when i call the Renderfile function by giving the video path name in c#.
Here is the c++ code which was created the dll:
#include "stdafx.h"
#include "RenderVideoFile.h"
void RenderFile(WCHAR *strFilename,HWND hwnd)
{
IGraphBuilder *pGraph = NULL;
IMediaControl *pControl = NULL;
IMediaEvent *pEvent = NULL;
IVMRWindowlessControl *pWc=NULL;
HRESULT hr=S_OK; if (FAILED(hr))
{
printf("ERROR - Could not initialize COM library");
return;
}
hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&pGraph);
if (FAILED(hr))
{
printf("ERROR - Could not create the Filter Graph Manager.");
return;
}
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
hr = InitWindowlessVMR(hwnd, pGraph, &pWc);
hr = pGraph->RenderFile(strFilename, NULL);
long lWidth, lHeight;
hr = pWc->GetNativeVideoSize(&lWidth, &lHeight, NULL, NULL);
if (SUCCEEDED(hr))
{
RECT rcSrc, rcDest;
SetRect(&rcSrc, 0, 0, lWidth, lHeight);
GetClientRect(hwnd,&rcDest);
SetRect(&rcDest, 0, 0, rcDest.right, rcDest.bottom);
hr = pWc->SetVideoPosition(&rcSrc, &rcDest);
}
if (SUCCEEDED(hr))
{
hr = pControl->Run();
if (SUCCEEDED(hr))
{
long evCode;
pEvent->WaitForCompletion(INFINITE, &evCode);
}
}
pWc->Release();
pControl->Release();
pEvent->Release();
pGraph->Release();
}
This is the C# code:
namespace CSharpTest
{
public partial class Form1 : Form
{
[DllImport("C:\\RenderVideoFile.dll",CharSet=CharSet.Unicode)]
public static extern void RenderFile(string strFilename,IntPtr hwnd);
RenderFile("C:\\123.avi",pictureBox1.Handle);
}
}
I imported the function of renderfile in c# from the dll. It was executed without any error but the video was not played. What i have to correct!?