• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 983
  • Last Modified:

Some C# to VC++ problem, urgent!

Hi guys, I have some problem converting some codes from C# to VC++.net
 
The first one is that I am using Interop.QuartzTypeLib.dll
I put them in reference in VC++ and do a:
using namespace QuartzTypeLib;

then when it comes to this line
in C#
m_objFilterGraph = new FilgraphManager(); ---> Fine

in VC++
m_objFilterGraph = new FilgraphManager(); --->ERROR! QuartzTypeLib::FilgraphManager' : you cannot create an instance of an interface...??????

I checked that the C# treats FilegraphManager as an Abstract Interface, whereas VC++ treats it as Interface.
Is that the reaosn why? or I simply canno tuse QuartzTypeLib in VC++


Is there a way to convert:
in C#
m_objBasicAudio = m_objFilterGraph as IBasicAudio;

to VC++.net (managed)
???

Thanks all
0
lordiano
Asked:
lordiano
  • 4
  • 3
1 Solution
 
AlexFMCommented:
If FilgraphManager is interface, what is non-interface class which implements it? Create instance of this class and cast it to FilgraphManager.

m_objBasicAudio = m_objFilterGraph as IBasicAudio;

Without knowing these classes I give you example using .NET classes.

C#

IEnumerable p;
p = new Hashtable() as IEnumerable;

C++

IEnumerable* p;
Hashtable* h;

h = new Hashtable();
p = h;


0
 
lordianoAuthor Commented:
Hi AlexFM,
i checked the DLL and found that the FilgraphManager is the class that implements it..

This is what i have :
FilgraphManager  *m_objFilterGraph;

then i try to do
m_objFilterGraph = new FilgraphManager();  error...

public class FilgraphManager
    Member of QuartzTypeLib
    Associated COM class is QuartzTypeLib.FilgraphManagerClass


0
 
AlexFMCommented:
It is difficult to say what happens. Do you have C# code working with this class? Or some documentation about this library?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
lordianoAuthor Commented:
Yep i have C# code working with this class.....
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

using QuartzTypeLib;

namespace DirectShow
{
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.ToolBar toolBar1;
        private System.Windows.Forms.ToolBarButton toolBarButton1;
        private System.Windows.Forms.ToolBarButton toolBarButton2;
        private System.Windows.Forms.ToolBarButton toolBarButton3;
        private System.Windows.Forms.Panel panel1;
        private System.ComponentModel.IContainer components;

        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;
        private System.Windows.Forms.MenuItem menuItem5;

        enum MediaStatus { None, Stopped, Paused, Running };

        private MediaStatus m_CurrentStatus = MediaStatus.None;
            private System.Windows.Forms.Button button3;
            private System.Windows.Forms.Button button4;
            private System.Windows.Forms.Button PlayButton;
            static private String current_path;
        public Form1()
        {
                   InitializeComponent();
                  current_path = null;
             
        }

            public Form1(String filename)
            {
                  InitializeComponent();
                  current_path = filename;
                  manualplay();
            }

          protected override void Dispose( bool disposing )
        {
            CleanUp();
           
            if( disposing )
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

            #region Windows Form Designer generated code
             private void InitializeComponent()
        {
                  this.toolBar1 = new System.Windows.Forms.ToolBar();
                  this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
                  this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
                  this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
                  this.panel1 = new System.Windows.Forms.Panel();
                  this.PlayButton = new System.Windows.Forms.Button();
                  this.button3 = new System.Windows.Forms.Button();
                  this.button4 = new System.Windows.Forms.Button();
                  this.SuspendLayout();
                  //
                  // toolBar1
                  //
                  this.toolBar1.DropDownArrows = true;
                  this.toolBar1.Location = new System.Drawing.Point(0, 0);
                  this.toolBar1.Name = "toolBar1";
                  this.toolBar1.ShowToolTips = true;
                  this.toolBar1.Size = new System.Drawing.Size(368, 42);
                  this.toolBar1.TabIndex = 4;
                  //
                  // panel1
                  //
                  this.panel1.BackColor = System.Drawing.Color.Black;
                  this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
                  this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
                  this.panel1.Location = new System.Drawing.Point(0, 42);
                  this.panel1.Name = "panel1";
                  this.panel1.Size = new System.Drawing.Size(368, 341);
                  this.panel1.TabIndex = 3;
                  //
                  // PlayButton
                  //
                  this.PlayButton.Location = new System.Drawing.Point(8, 8);
                  this.PlayButton.Name = "PlayButton";
                  this.PlayButton.Size = new System.Drawing.Size(56, 24);
                  this.PlayButton.TabIndex = 6;
                  this.PlayButton.Text = "Play";
                  this.PlayButton.Click += new System.EventHandler(this.button2_Click);
                  //
                  // button3
                  //
                  this.button3.Location = new System.Drawing.Point(88, 8);
                  this.button3.Name = "button3";
                  this.button3.Size = new System.Drawing.Size(56, 24);
                  this.button3.TabIndex = 7;
                  this.button3.Text = "Pause";
                  this.button3.Click += new System.EventHandler(this.button3_Click);
                  //
                  // button4
                  //
                  this.button4.Location = new System.Drawing.Point(168, 8);
                  this.button4.Name = "button4";
                  this.button4.Size = new System.Drawing.Size(56, 24);
                  this.button4.TabIndex = 8;
                  this.button4.Text = "Stop";
                  this.button4.Click += new System.EventHandler(this.button4_Click);
                  //
                  // Form1
                  //
                  this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
                  this.ClientSize = new System.Drawing.Size(368, 383);
                  this.Controls.Add(this.button4);
                  this.Controls.Add(this.button3);
                  this.Controls.Add(this.PlayButton);
                  this.Controls.Add(this.panel1);
                  this.Controls.Add(this.toolBar1);
                  this.Name = "Form1";
                  this.Text = "MoviePlayer-CSCI576b";
                  this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);
                  this.Load += new System.EventHandler(this.Form1_Load);
                  this.ResumeLayout(false);

            }
            #endregion

            [STAThread]
            static void Main(string[] args)
            {
                  Application.Run(new Form1(args[0]));
            }

            private void manualplay()
            {
                  if(current_path == null)
                  {
                        Console.WriteLine("dfkajldkfjlkadj");
                        return;
                  }
                  CleanUp();
                  m_objFilterGraph = new FilgraphManager();
                  
                  m_objFilterGraph.RenderFile(current_path);
                  m_objBasicAudio = m_objFilterGraph as IBasicAudio;
               
                  try
                  {
                        m_objVideoWindow = m_objFilterGraph as IVideoWindow;
                        m_objVideoWindow.Owner = (int) panel1.Handle;
                        m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
                        m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left,
                              panel1.ClientRectangle.Top,
                              panel1.ClientRectangle.Width,
                              panel1.ClientRectangle.Height);
                  }
                  catch (Exception)
                  {
                        m_objVideoWindow = null;
                  }

                  m_objMediaEvent = m_objFilterGraph as IMediaEvent;

                  m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
                  m_objMediaEventEx.SetNotifyWindow((int) this.Handle,WM_GRAPHNOTIFY, 0);

                  m_objMediaPosition = m_objFilterGraph as IMediaPosition;

                  m_objMediaControl = m_objFilterGraph as IMediaControl;

                  this.Text = "MoviePlayer-CSCI576b - [" + current_path + "]";

                  m_objMediaControl.Run();
                  m_CurrentStatus = MediaStatus.Running;

                  
            }
        private void CleanUp()
        {
            if (m_objMediaControl != null)
                m_objMediaControl.Stop();

            m_CurrentStatus = MediaStatus.Stopped;

            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;
        }

        private void menuItem4_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        private void Form1_SizeChanged(object sender, System.EventArgs e)
        {
            if (m_objVideoWindow != null)
            {
                m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left,
                    panel1.ClientRectangle.Top,
                    panel1.ClientRectangle.Width,
                    panel1.ClientRectangle.Height);
            }
        }

        private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
        {
            switch(toolBar1.Buttons.IndexOf(e.Button))
            {
                case 0: m_objMediaControl.Run();
                        m_CurrentStatus = MediaStatus.Running;
                        break;

                case 1: m_objMediaControl.Pause();
                        m_CurrentStatus = MediaStatus.Paused;
                        break;

                case 2: m_objMediaControl.Stop();
                        m_objMediaPosition.CurrentPosition = 0;
                        m_CurrentStatus = MediaStatus.Stopped;
                        break;
            }
                 
        }

        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;
                            m_CurrentStatus = MediaStatus.Stopped;

                        }
                    }
                    catch (Exception)
                    {
                        break;
                    }
                }
            }

            base.WndProc(ref m);
        }

            private void button1_Click(object sender, System.EventArgs e)
            {
                  OpenFileDialog openFileDialog = new OpenFileDialog();

                  openFileDialog.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*";

                  if (DialogResult.OK == openFileDialog.ShowDialog())
                  {
                        CleanUp();

                        m_objFilterGraph = new FilgraphManager();
                        m_objFilterGraph.RenderFile(openFileDialog.FileName);

                        m_objBasicAudio = m_objFilterGraph as IBasicAudio;
               
                        try
                        {
                              m_objVideoWindow = m_objFilterGraph as IVideoWindow;
                              m_objVideoWindow.Owner = (int) panel1.Handle;
                              m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN;
                              m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left,
                                    panel1.ClientRectangle.Top,
                                    panel1.ClientRectangle.Width,
                                    panel1.ClientRectangle.Height);
                        }
                        catch (Exception)
                        {
                              m_objVideoWindow = null;
                        }

                        m_objMediaEvent = m_objFilterGraph as IMediaEvent;

                        m_objMediaEventEx = m_objFilterGraph as IMediaEventEx;
                        m_objMediaEventEx.SetNotifyWindow((int) this.Handle,WM_GRAPHNOTIFY, 0);

                        m_objMediaPosition = m_objFilterGraph as IMediaPosition;

                        m_objMediaControl = m_objFilterGraph as IMediaControl;

                        this.Text = "DirectShow - [" + openFileDialog.FileName + "]";

                        m_objMediaControl.Run();
                        m_CurrentStatus = MediaStatus.Running;

                  }
            }

            private void Form1_Load(object sender, System.EventArgs e)
            {
                  
            }

            private void button3_Click(object sender, System.EventArgs e)
            {
                  m_objMediaControl.Pause();
                  m_CurrentStatus = MediaStatus.Paused;
            }

            private void button2_Click(object sender, System.EventArgs e)
            {
                  m_objMediaControl.Run();
                  m_CurrentStatus = MediaStatus.Running;
            }

            private void button4_Click(object sender, System.EventArgs e)
            {
                  m_objMediaControl.Stop();
                  m_objMediaPosition.CurrentPosition = 0;
                  m_CurrentStatus = MediaStatus.Stopped;
            }

     
    }
}
0
 
AlexFMCommented:
What reference should I add to make it working?
0
 
lordianoAuthor Commented:
Interop.QuartzTypeLib.dll

Do you want me to email it to you?
0
 
AlexFMCommented:
C# application doesn't work, it gives exception immidiately when starts. However, now I have QuartzTypeLib.dll, so I can do something with it. Please create console C++ application (minimum code) which shows your problem, and post here. I will try to do something.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now