?
Solved

Some C# to VC++ problem, urgent!

Posted on 2004-05-02
10
Medium Priority
?
974 Views
Last Modified: 2007-12-19
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
Comment
Question by:lordiano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
10 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 10974589
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
 

Author Comment

by:lordiano
ID: 10974620
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 10974961
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!

 

Author Comment

by:lordiano
ID: 10976047
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
 
LVL 48

Expert Comment

by:AlexFM
ID: 10976132
What reference should I add to make it working?
0
 

Author Comment

by:lordiano
ID: 10976163
Interop.QuartzTypeLib.dll

Do you want me to email it to you?
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 1500 total points
ID: 10977921
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question