none
The name ‘Marshal’ does not exist in the current context

    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.

    Saturday, July 03, 2010 12:44 PM

Answers

  • Hi,

    To fix error #1 and #2, you need to include the System.Runtime.InteropServices namespace at the top of your code file.

    To fix the other errors, you need to actually implement methods for each of your other errors. So for example the Form1_ResizeMove you need to declare as such...

    private void Form1_ResizeMove(object sender, EventArgs e)
    {
      // Your event handling here...
    }

    Hope this helps,

    Kev

    • Marked as answer by btap0644 Saturday, July 03, 2010 1:57 PM
    Saturday, July 03, 2010 1:12 PM

All replies

  • Hello,

    Have you checked your project references/namespaces ?

    For the 'Marshal' class add the following namespace 'System.Runtime.InteropServices'.

    For the event handlers you probably want to define these methods, or copy/paste them from the original source code if they are available.

     

     


    Eyal, Regards.

    blog.eyalsh.net
    Saturday, July 03, 2010 1:11 PM
    Moderator
  • Hi,

    To fix error #1 and #2, you need to include the System.Runtime.InteropServices namespace at the top of your code file.

    To fix the other errors, you need to actually implement methods for each of your other errors. So for example the Form1_ResizeMove you need to declare as such...

    private void Form1_ResizeMove(object sender, EventArgs e)
    {
      // Your event handling here...
    }

    Hope this helps,

    Kev

    • Marked as answer by btap0644 Saturday, July 03, 2010 1:57 PM
    Saturday, July 03, 2010 1:12 PM
  • yo dude thks man i mean it it worked i missed the code
    Saturday, July 03, 2010 1:57 PM
  • thks it worked
    Saturday, July 03, 2010 1:58 PM