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. C#
  4. Invalid argument (Converted from VB.Net)

Invalid argument (Converted from VB.Net)

Scheduled Pinned Locked Moved C#
csharphelpquestion
4 Posts 3 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.
  • M Offline
    M Offline
    Midnight Ahri
    wrote on last edited by
    #1

    i'm new in C#, i converted some code from my previous project and i have an error here. i've put arrows between the code, i believe AppBarSettings type is APPBARDATA, but why it's still error? :confused: TBAppBar class below,

    public class TBAppBar
    {
    [DllImport("shell32", EntryPoint = "SHAppBarMessage", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
    private static extern int GetAppBarMessage(int dwMessage, ref APPBARDATA pData);
    [DllImport("shell32", EntryPoint = "SHAppBarMessage", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
    private static extern int SetAppBarMessage(int dwMessage, ref APPBARDATA pData);

            //Get Message Sent By App Bar
    
            //Send Message To App BAr
    
            private struct APPBARDATA
            {
                //AppBar Structure
                public int cbSize;
                public int hwnd;
                public int uCallbackMessage;
                public int uEdge;
                public Rectangle rc;
                public int lParam;
            }
    
            //Get Current State
            private const Int32 ABM\_GETSTATE = 0x4;
            //Get TaskBar Position
            private const Int32 ABM\_GETTASKBARPOS = 0x5;
            //Apply Setting(s)
            private const Int32 ABM\_SETSTATE = 0xa;
            //Autohide
            private const Int32 ABS\_AUTOHIDE = 0x1;
            //Always on Top
            private const Int32 ABS\_ALWAYSONTOP = 0x2;
    
            private bool TBAppBAutoHide;
    
            private bool TBAppBarAlwaysOnTop;
            public TBAppBar()
            {
                this.GetState();
                //Get Current State
            }
    
    
            private void GetState()
            {
                APPBARDATA AppBarSetting = new APPBARDATA();
                //What Setting?
    
                AppBarSetting.cbSize = Marshal.SizeOf(AppBarSetting);
                //Initialise
    
          --->  Int32 AppBarState = GetAppBarMessage(ABM\_GETSTATE, AppBarSetting); <---
                //Get Current State
    
                switch (AppBarState)
                {
                    case 0:
                        //Nothing Set
                        TBAppBAutoHide = false;
                        TBAppBarAlwaysOnTop = false;
    
                        break;
                    case ABS\_ALWAYSONTOP:
                        //Always On Top
    
    L 1 Reply Last reply
    0
    • M Midnight Ahri

      i'm new in C#, i converted some code from my previous project and i have an error here. i've put arrows between the code, i believe AppBarSettings type is APPBARDATA, but why it's still error? :confused: TBAppBar class below,

      public class TBAppBar
      {
      [DllImport("shell32", EntryPoint = "SHAppBarMessage", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
      private static extern int GetAppBarMessage(int dwMessage, ref APPBARDATA pData);
      [DllImport("shell32", EntryPoint = "SHAppBarMessage", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
      private static extern int SetAppBarMessage(int dwMessage, ref APPBARDATA pData);

              //Get Message Sent By App Bar
      
              //Send Message To App BAr
      
              private struct APPBARDATA
              {
                  //AppBar Structure
                  public int cbSize;
                  public int hwnd;
                  public int uCallbackMessage;
                  public int uEdge;
                  public Rectangle rc;
                  public int lParam;
              }
      
              //Get Current State
              private const Int32 ABM\_GETSTATE = 0x4;
              //Get TaskBar Position
              private const Int32 ABM\_GETTASKBARPOS = 0x5;
              //Apply Setting(s)
              private const Int32 ABM\_SETSTATE = 0xa;
              //Autohide
              private const Int32 ABS\_AUTOHIDE = 0x1;
              //Always on Top
              private const Int32 ABS\_ALWAYSONTOP = 0x2;
      
              private bool TBAppBAutoHide;
      
              private bool TBAppBarAlwaysOnTop;
              public TBAppBar()
              {
                  this.GetState();
                  //Get Current State
              }
      
      
              private void GetState()
              {
                  APPBARDATA AppBarSetting = new APPBARDATA();
                  //What Setting?
      
                  AppBarSetting.cbSize = Marshal.SizeOf(AppBarSetting);
                  //Initialise
      
            --->  Int32 AppBarState = GetAppBarMessage(ABM\_GETSTATE, AppBarSetting); <---
                  //Get Current State
      
                  switch (AppBarState)
                  {
                      case 0:
                          //Nothing Set
                          TBAppBAutoHide = false;
                          TBAppBarAlwaysOnTop = false;
      
                          break;
                      case ABS\_ALWAYSONTOP:
                          //Always On Top
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Midnight Ahri wrote:

      error here.

      Are we supposed to guess what the error is? Probably should be: Int32 AppBarState = GetAppBarMessage(ABM_GETSTATE, ref AppBarSetting);

      Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Please stand in front of my pistol, smile and wait for the flash - JSOP 2012

      M D 2 Replies Last reply
      0
      • L Lost User

        Midnight Ahri wrote:

        error here.

        Are we supposed to guess what the error is? Probably should be: Int32 AppBarState = GetAppBarMessage(ABM_GETSTATE, ref AppBarSetting);

        Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Please stand in front of my pistol, smile and wait for the flash - JSOP 2012

        M Offline
        M Offline
        Midnight Ahri
        wrote on last edited by
        #3

        well, it works sweetly. i thought using Option Strict ON will make it easy to convert to C#. but even C# is more strict than VB.Net. thank you very much, i've got to learn more about C#. :)

        1 Reply Last reply
        0
        • L Lost User

          Midnight Ahri wrote:

          error here.

          Are we supposed to guess what the error is? Probably should be: Int32 AppBarState = GetAppBarMessage(ABM_GETSTATE, ref AppBarSetting);

          Why is common sense not common? Never argue with an idiot. They will drag you down to their level where they are an expert. Sometimes it takes a lot of work to be lazy Please stand in front of my pistol, smile and wait for the flash - JSOP 2012

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Good guess! :)

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          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