Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Error while calling VC# function in VC++

Error while calling VC# function in VC++

Scheduled Pinned Locked Moved Managed C++/CLI
csharpc++help
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andy Rama
    wrote on last edited by
    #1

    Hi to all, I have an 'Windows Form Control Library' "VideoWindow.dll" in VC#.Net 2008, having code as following, using DirectShowLib;//C# DirectShow Library public partial class VideoWindow : UserControl { public VideoWindow() { InitializeComponent(); } Label m_picVideoWindow = new Label(); public int SetPreview(IVideoWindow vwRenderer) { int hr = 0; if (m_picVideoWindow.Bounds.IsEmpty) return hr; try { hr = vwRenderer.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings); DsError.ThrowExceptionForHR(hr); hr = vwRenderer.put_Owner(m_picVideoWindow.Handle); DsError.ThrowExceptionForHR(hr); hr = vwRenderer.SetWindowPosition(0, 0, m_picVideoWindow.Width, m_picVideoWindow.Height); DsError.ThrowExceptionForHR(hr); hr = vwRenderer.put_Visible(OABool.True); DsError.ThrowExceptionForHR(hr); } catch (Exception ex) { } return hr; } } When I am calling SetPreview() from my VC++.Net 2008 MFC Application as follows, IVideoWindow *pWidnow;//C++ DirectShow Library CWinFormsControl<VideoWindow::VideoWindow> *a1 = new CWinFormsControl<VideoWindow::VideoWindow>(); (*a1)->SetPreview(pWidnow); It gives compile error as, error C2664: 'VideoWindow::VideoWindow::SetPreview' : cannot convert parameter 1 from 'IVideoWindow *' to 'DirectShowLib::IVideoWindow ^' Please help me to solve this error. Regards, Aniket A. Salunkhe

    L M G 3 Replies Last reply
    0
    • A Andy Rama

      Hi to all, I have an 'Windows Form Control Library' "VideoWindow.dll" in VC#.Net 2008, having code as following, using DirectShowLib;//C# DirectShow Library public partial class VideoWindow : UserControl { public VideoWindow() { InitializeComponent(); } Label m_picVideoWindow = new Label(); public int SetPreview(IVideoWindow vwRenderer) { int hr = 0; if (m_picVideoWindow.Bounds.IsEmpty) return hr; try { hr = vwRenderer.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings); DsError.ThrowExceptionForHR(hr); hr = vwRenderer.put_Owner(m_picVideoWindow.Handle); DsError.ThrowExceptionForHR(hr); hr = vwRenderer.SetWindowPosition(0, 0, m_picVideoWindow.Width, m_picVideoWindow.Height); DsError.ThrowExceptionForHR(hr); hr = vwRenderer.put_Visible(OABool.True); DsError.ThrowExceptionForHR(hr); } catch (Exception ex) { } return hr; } } When I am calling SetPreview() from my VC++.Net 2008 MFC Application as follows, IVideoWindow *pWidnow;//C++ DirectShow Library CWinFormsControl<VideoWindow::VideoWindow> *a1 = new CWinFormsControl<VideoWindow::VideoWindow>(); (*a1)->SetPreview(pWidnow); It gives compile error as, error C2664: 'VideoWindow::VideoWindow::SetPreview' : cannot convert parameter 1 from 'IVideoWindow *' to 'DirectShowLib::IVideoWindow ^' Please help me to solve this error. Regards, Aniket A. Salunkhe

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #2

      Aniket Salunkhe wrote:

      Please help me to solve this error.

      Well a Native C++ pointer

      Aniket Salunkhe wrote:

      IVideoWindow *pWidnow;

      Is not going to be convertible to a managed object.

      Aniket Salunkhe wrote:

      DirectShowLib::IVideoWindow ^

      If you don't know that, then you need to do some studying of C++/CLI basics and fundamentals. There is a series of CLI beginner articles here on Code Project.

      led mike

      1 Reply Last reply
      0
      • A Andy Rama

        Hi to all, I have an 'Windows Form Control Library' "VideoWindow.dll" in VC#.Net 2008, having code as following, using DirectShowLib;//C# DirectShow Library public partial class VideoWindow : UserControl { public VideoWindow() { InitializeComponent(); } Label m_picVideoWindow = new Label(); public int SetPreview(IVideoWindow vwRenderer) { int hr = 0; if (m_picVideoWindow.Bounds.IsEmpty) return hr; try { hr = vwRenderer.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings); DsError.ThrowExceptionForHR(hr); hr = vwRenderer.put_Owner(m_picVideoWindow.Handle); DsError.ThrowExceptionForHR(hr); hr = vwRenderer.SetWindowPosition(0, 0, m_picVideoWindow.Width, m_picVideoWindow.Height); DsError.ThrowExceptionForHR(hr); hr = vwRenderer.put_Visible(OABool.True); DsError.ThrowExceptionForHR(hr); } catch (Exception ex) { } return hr; } } When I am calling SetPreview() from my VC++.Net 2008 MFC Application as follows, IVideoWindow *pWidnow;//C++ DirectShow Library CWinFormsControl<VideoWindow::VideoWindow> *a1 = new CWinFormsControl<VideoWindow::VideoWindow>(); (*a1)->SetPreview(pWidnow); It gives compile error as, error C2664: 'VideoWindow::VideoWindow::SetPreview' : cannot convert parameter 1 from 'IVideoWindow *' to 'DirectShowLib::IVideoWindow ^' Please help me to solve this error. Regards, Aniket A. Salunkhe

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Aniket Salunkhe wrote:

        When I am calling SetPreview() from my VC++.Net 2008 MFC Application as follows, IVideoWindow *pWidnow;//C++ DirectShow Library CWinFormsControl *a1 = new CWinFormsControl();

        Handles to managed objects use ^, not * in C++. Also you use gcnew, not new, to allocate them on the managed heap.

        Aniket Salunkhe wrote:

        (*a1)->SetPreview(pWidnow);

        Huh?

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        G 1 Reply Last reply
        0
        • M Mark Salsbery

          Aniket Salunkhe wrote:

          When I am calling SetPreview() from my VC++.Net 2008 MFC Application as follows, IVideoWindow *pWidnow;//C++ DirectShow Library CWinFormsControl *a1 = new CWinFormsControl();

          Handles to managed objects use ^, not * in C++. Also you use gcnew, not new, to allocate them on the managed heap.

          Aniket Salunkhe wrote:

          (*a1)->SetPreview(pWidnow);

          Huh?

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          G Offline
          G Offline
          George L Jackson
          wrote on last edited by
          #4

          Mark, FYI, Aniket Salunkhe is trying to call managed code from native C++ according to this quote: "When I (Aniket Salunkhe) am calling SetPreview() from my VC++.Net 2008 MFC Application ...".

          "We make a living by what we get, we make a life by what we give." --Winston Churchill

          M 1 Reply Last reply
          0
          • G George L Jackson

            Mark, FYI, Aniket Salunkhe is trying to call managed code from native C++ according to this quote: "When I (Aniket Salunkhe) am calling SetPreview() from my VC++.Net 2008 MFC Application ...".

            "We make a living by what we get, we make a life by what we give." --Winston Churchill

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            That was pretty obvious from the error message as well :) I only commented about the syntax/language use. I suppose I could have mentioned that (s)he'll have to compile with /CLR. Cheers, Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            A 1 Reply Last reply
            0
            • A Andy Rama

              Hi to all, I have an 'Windows Form Control Library' "VideoWindow.dll" in VC#.Net 2008, having code as following, using DirectShowLib;//C# DirectShow Library public partial class VideoWindow : UserControl { public VideoWindow() { InitializeComponent(); } Label m_picVideoWindow = new Label(); public int SetPreview(IVideoWindow vwRenderer) { int hr = 0; if (m_picVideoWindow.Bounds.IsEmpty) return hr; try { hr = vwRenderer.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren | WindowStyle.ClipSiblings); DsError.ThrowExceptionForHR(hr); hr = vwRenderer.put_Owner(m_picVideoWindow.Handle); DsError.ThrowExceptionForHR(hr); hr = vwRenderer.SetWindowPosition(0, 0, m_picVideoWindow.Width, m_picVideoWindow.Height); DsError.ThrowExceptionForHR(hr); hr = vwRenderer.put_Visible(OABool.True); DsError.ThrowExceptionForHR(hr); } catch (Exception ex) { } return hr; } } When I am calling SetPreview() from my VC++.Net 2008 MFC Application as follows, IVideoWindow *pWidnow;//C++ DirectShow Library CWinFormsControl<VideoWindow::VideoWindow> *a1 = new CWinFormsControl<VideoWindow::VideoWindow>(); (*a1)->SetPreview(pWidnow); It gives compile error as, error C2664: 'VideoWindow::VideoWindow::SetPreview' : cannot convert parameter 1 from 'IVideoWindow *' to 'DirectShowLib::IVideoWindow ^' Please help me to solve this error. Regards, Aniket A. Salunkhe

              G Offline
              G Offline
              George L Jackson
              wrote on last edited by
              #6

              The C++ DirectShow Library's IVideoWindow and C#'s DirectShowLib::IVideoWindow^ are not the same interface (at least externally). SetPreview is looking for C#'s IVideoWindow; thus, you may need to use COM callable wrapper (CCW) of your DirectShowLib::IVideoWindow^.

              "We make a living by what we get, we make a life by what we give." --Winston Churchill

              modified on Wednesday, October 1, 2008 2:05 PM

              A 1 Reply Last reply
              0
              • M Mark Salsbery

                That was pretty obvious from the error message as well :) I only commented about the syntax/language use. I suppose I could have mentioned that (s)he'll have to compile with /CLR. Cheers, Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                A Offline
                A Offline
                Andy Rama
                wrote on last edited by
                #7

                Mark Salsbery wrote:

                he'll have to compile with /CLR.

                I am already using this flag (/CLR).

                M 1 Reply Last reply
                0
                • G George L Jackson

                  The C++ DirectShow Library's IVideoWindow and C#'s DirectShowLib::IVideoWindow^ are not the same interface (at least externally). SetPreview is looking for C#'s IVideoWindow; thus, you may need to use COM callable wrapper (CCW) of your DirectShowLib::IVideoWindow^.

                  "We make a living by what we get, we make a life by what we give." --Winston Churchill

                  modified on Wednesday, October 1, 2008 2:05 PM

                  A Offline
                  A Offline
                  Andy Rama
                  wrote on last edited by
                  #8

                  George L. Jackson wrote:

                  you may need to use COM callable wrapper (CCW) of your DirectShowLib::IVideoWindow^.

                  What is that?

                  1 Reply Last reply
                  0
                  • A Andy Rama

                    Mark Salsbery wrote:

                    he'll have to compile with /CLR.

                    I am already using this flag (/CLR).

                    M Offline
                    M Offline
                    Mark Salsbery
                    wrote on last edited by
                    #9

                    I knew that from the error message. You're using the wrong syntax for managed objects. The error message is fairly clear.

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups