The name 'Marshal' does not exist in the current context
-
02-10-2019 - |
Question
I got the code below from the bitmapmixer sample (DirectShow.NET) and i tried to reimplement it. The original sample works fine. In my version when I try to compile i get errors.
private void AddHandlers()
{
// Add handlers for VMR purpose
this.Paint += new PaintEventHandler(Form1_Paint); // for WM_PAINT
this.Resize += new EventHandler(Form1_ResizeMove); // for WM_SIZE
this.Move += new EventHandler(Form1_ResizeMove); // for WM_MOVE
SystemEvents.DisplaySettingsChanged += new EventHandler(SystemEvents_DisplaySettingsChanged); // for WM_DISPLAYCHANGE
handlersAdded = true;
}
private void RemoveHandlers()
{
// remove handlers when they are no more needed
handlersAdded = false;
this.Paint -= new PaintEventHandler(Form1_Paint);
this.Resize -= new EventHandler(Form1_ResizeMove);
this.Move -= new EventHandler(Form1_ResizeMove);
SystemEvents.DisplaySettingsChanged -= new EventHandler(SystemEvents_DisplaySettingsChanged);
}
ERRORs
Error 1 The name 'Marshal' does not exist in the current context Form1.cs
Error 2 The name 'Marshal' does not exist in the current context Form1.cs
Error 3 The name 'Form1_ResizeMove' does not exist in the current context Form1.cs
Error 4 The name 'Form1_Paint' does not exist in the current context Form1.cs
Error 5 The name 'Form1_ResizeMove' does not exist in the current context Form1.cs
Error 6 The name 'Form1_ResizeMove' does not exist in the current context Form1.cs
Error 7 The name 'SystemEvents_DisplaySettingsChanged' does not exist in the current context Form1.cs
Error 10 The name 'Form1_ResizeMove' does not exist in the current context Form1.cs
Error 11 The name 'SystemEvents_DisplaySettingsChanged' does not exist in the current context Form1.cs
Any help is appreciated.
Thanks.
Solution
The Marshal
class is in the System.Runtime.InteropServices
namespace. Do you have an appropriate using
directive?
using System.Runtime.InteropServices;
As for the other errors - do you have those methods in your class? If not, remove the lines which are trying to subscribe event handlers for them...
OTHER TIPS
public static class Marshal is a Member of System.Runtime.InteropServices
you just have to add:
using System.Runtime.InteropServices; in that .cs file