Error while calling VC# function in VC++
-
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 -
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. SalunkheAniket 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
-
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. SalunkheAniket 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:
-
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:
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
-
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
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:
-
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. SalunkheThe 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
-
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:
-
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
-
Mark Salsbery wrote:
he'll have to compile with /CLR.
I am already using this flag (/CLR).
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: