Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

custom controls and dll's

Status
Not open for further replies.

sodiumpaul

Programmer
Jun 30, 2007
17
GB
I've created a custom panel control in c# that uses the quartz DLL (using QuartzTypeLib;). I have a form that allows you to set the location and size of the panel/panels within the form which then plays a video with in this panel. This all works well ( I have 4 panels that are all playing videos without any problems). Here comes the "However". However, when I dispose of one of the panels, the dll that the panel is using remains active. I know this because if I dispose of the panel during a video playback, the audio continues and the thread usage does not drop. How do remove the DLL references crated by a particular panel. I think I'm going to hate the answer but will be pleased to recieve any advice.

Thanks in advance, to those that spend the time helping me and other with such issues. I'm still a newbie and would be lost without the help offered in forums such as these.
 
can you post some code?

Does the quartz dll have any stop() or dispose() methods or something of the like to force any resources to be dropped?
 
private void button3_Click(object sender, EventArgs e)
{
panel1.Media_File = textBox1.Text;
panel1.LoadMedia();
}

private void button4_Click(object sender, EventArgs e)
{
panel1.Dispose();
}
 
using System;
using System.ComponentModel;
using System.Windows.Forms;

using QuartzTypeLib;

namespace CustomPanel
{

public partial class ResizablePanel : Panel
{

private const int WM_APP = 0x8000;
private const int WM_GRAPHNOTIFY = WM_APP + 1;
private const int EC_COMPLETE = 0x01;
private const int WS_CHILD = 0x40000000;
private const int WS_CLIPCHILDREN = 0x2000000;

private FilgraphManager m_objFilterGraph = null;
private IBasicAudio m_objBasicAudio = null;
private IVideoWindow m_objVideoWindow = null;
private IMediaEvent m_objMediaEvent = null;
private IMediaEventEx m_objMediaEventEx = null;
private IMediaPosition m_objMediaPosition = null;

private IMediaControl m_objMediaControl = null;
public string fileloc;

public string Media_File;

protected override void OnMouseDown(MouseEventArgs e)
{
LoadMedia();
}


public void LoadMedia()
{

//Required! Get rid of unused threads, set all back to null

CleanUp();
GC.Collect();
CleanUp();

m_objFilterGraph = new FilgraphManager();
m_objFilterGraph.RenderFile(Media_File);

try
{
// m_objBasicAudio = (IBasicAudio)m_objBasicAudio;
m_objVideoWindow = (IVideoWindow)m_objFilterGraph;
m_objVideoWindow.Owner = (int)this.Handle;
m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
m_objVideoWindow.SetWindowPosition(this.ClientRectangle.Left +2,
this.ClientRectangle.Top +2,
this.ClientRectangle.Width -5,
this.ClientRectangle.Height - 5);

}
catch (Exception)
{
m_objVideoWindow = null;
}

m_objMediaEvent = (IMediaEvent)m_objFilterGraph;
m_objMediaEventEx = (IMediaEventEx)m_objFilterGraph;
m_objMediaEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0);
m_objMediaPosition = (IMediaPosition)m_objFilterGraph;
m_objMediaControl = (IMediaControl)m_objFilterGraph;
m_objMediaControl.Run();
}
protected override void WndProc(ref Message m)
{

if (m.Msg == WM_GRAPHNOTIFY)
{
int lEventCode;
int lParam1, lParam2;

while (true)
{
try
{
m_objMediaEventEx.GetEvent(out lEventCode,
out lParam1,
out lParam2,
0);

m_objMediaEventEx.FreeEventParams(lEventCode, lParam1, lParam2);

if (lEventCode == EC_COMPLETE)
{

m_objMediaControl.Stop();

m_objMediaPosition.CurrentPosition = 0;
}
}
catch (Exception)
{
break;
}
}
}

base.WndProc(ref m);
}


private void CleanUp()
{
if (m_objMediaControl != null)
{
m_objMediaControl.Stop();
m_objMediaPosition.CurrentPosition = 0;
}
if (m_objMediaEventEx != null) m_objMediaEventEx.SetNotifyWindow(0, 0, 0);

if (m_objVideoWindow != null)
{
m_objVideoWindow.Visible = 0;
m_objVideoWindow.Owner = 0;
}

if (m_objMediaControl != null) m_objMediaControl = null;
if (m_objMediaPosition != null) m_objMediaPosition = null;
if (m_objMediaEventEx != null) m_objMediaEventEx = null;
if (m_objMediaEvent != null) m_objMediaEvent = null;
if (m_objVideoWindow != null) m_objVideoWindow = null;
if (m_objBasicAudio != null) m_objBasicAudio = null;
if (m_objFilterGraph != null) m_objFilterGraph = null;
}
}

}
 
there's some junk in this code, for example CleanUP() appears twice, and some unneeded declarations.
 
I've deleted a CleanUp() statement just after -> m_objMediaPosition.CurrentPosition = 0; in CleanUP().

But this is not the problem.

The bit I find of most interest, is that the audio carries on until the end of the media even after you've disposed of the panel. I get the feeling I'm being really stupid and missing the obvious!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top