Results 1 to 4 of 4

Thread: Creating a DLL in VB.NET

  1. #1
    Join Date
    Nov 2009
    Posts
    42

    Creating a DLL in VB.NET

    I program in VB.NET, I created a small program for Windows CE. It works well. But my problem is that I must find a way to hide the taskbar in Windows. After having made my research, the only thing I find is tengible the following code in C# (I think):
    Code:
    public const int SWP_ASYNCWINDOWPOS = 0x4000;
    		public const int SWP_DEFERERASE = 0x2000;
    		public const int SWP_DRAWFRAME = 0x0020;
    		public const int SWP_FRAMECHANGED = 0x0020;
    		public const int SWP_HIDEWINDOW = 0x0080;
    		public const int SWP_NOACTIVATE = 0x0010;
    		public const int SWP_NOCOPYBITS = 0x0100;
    		public const int SWP_NOMOVE = 0x0002;
    		public const int SWP_NOOWNERZORDER = 0x0200;
    		public const int SWP_NOREDRAW = 0x0008;
    		public const int SWP_NOREPOSITION = 0x0200;
    		public const int SWP_NOSENDCHANGING = 0x0400;
    		public const int SWP_NOSIZE = 0x0001;
    		public const int SWP_NOZORDER = 0x0004;
    		public const int SWP_SHOWWINDOW = 0x0040;
     
    		public const int HWND_TOP = 0;
    		public const int HWND_BOTTOM = 1;
    		public const int HWND_TOPMOST = -1;
    		public const int HWND_NOTOPMOST = -2;
     
    		[DllImport("coredll.dll", SetLastError = true)]
    		[return: MarshalAs(UnmanagedType.Bool)]
    		public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
     
    		[DllImport("coredll.dll", EntryPoint = "FindWindowW", SetLastError = true)]
    		public static extern IntPtr FindWindowW(string lpClassName, string lpWindowName);
    
    	public static void HideStartBar()
    		{
    			IntPtr handle;
    			try
    			{
    				handle = FindWindowW("HHTaskBar", null);
    				if (handle != IntPtr.Zero)
    				{
    					SetWindowPos((IntPtr)handle, (IntPtr)0, 0, 0, 0, 0, SWP_HIDEWINDOW);
    				}
    			}
    			catch
    			{
    				MessageBox.Show("Unable to hide the status bar.");
    			}
    		}
     
    		public static void ShowStartBar()
    		{
    			IntPtr handle;
     
    			try
    			{
    				handle = FindWindowW("HHTaskBar", null);
    				if (handle != IntPtr.Zero)
    				{
    					SetWindowPos(handle, (IntPtr)0, 0, 0, LARGERSCREENPDA , 26, SWP_SHOWWINDOW);
    				}
    			}
    			catch
    			{
    				MessageBox.Show("Unable to display the status bar");
    			}
    		}
    So I wanted to create a DLL that I can use in my application.

    So I create a new solution, add a library project class. and I simply copy and paste this code in the class.

    But I am pointed out several errors:

    Code:
    [DllImport("coredll.dll", SetLastError = true)]
    The type or namespace not found

    Code:
    [return: MarshalAs(UnmanagedType.Bool)]
    The type or namespace not found

    Code:
    SetWindowPos(handle, (IntPtr)0, 0, 0, LARGERSCREENPDA, 26, SWP_SHOWWINDOW);
    The name does not exist in the current context.

    As I do not know much about C#, being a beginner in creating DLL, if someone could give me a helping hand to resolve this error messages.

  2. #2
    Join Date
    Nov 2008
    Posts
    1,192

    Re: Creating a DLL in VB.NET

    The type or namespace could not be found:
    This means that the namespace must be added to your class (using the top of the file), if you pass your mouse gently on class "DllImport" VisualStudio you should mark the end of the word, you click on this thing and it should offer you automatically import the good using!

    This process works in your references if you have the right libs obviously!

  3. #3
    Join Date
    Nov 2008
    Posts
    1,054

    Re: Creating a DLL in VB.NET

    Begin your code by including the following namespace:

    Code:
    using System.Runtime.InteropServices;

  4. #4
    Join Date
    Nov 2009
    Posts
    42

    Re: Creating a DLL in VB.NET

    Thank you very much!

    In fact it works very well. I create my dll and everything is fine! For LARGERSCREENPDA error (I was stupid to not understand that it was replaced by the value.

    After importing all goes well. Alas, I did not put the right value in SetWindowPos (to reset the bar). So it is only reappeared after a bar in the top left.

    So I also remember that this snippet was for a Windows Mobile 6, which has a taskbar at the top. But Windows CE is down ...

    So I do my experiments and found good values.

    I'll get what to put, if someone has an idea ...

    Here's the code:

    Code:
    using System;
    //using System.Collections.Generic;
    //using System.Linq;
    //using System.Text;
    using System.Runtime.InteropServices;
    
    namespace HideBarre
    {
        public class HideBarre
        {
            public const int SWP_ASYNCWINDOWPOS = 0x4000;
            public const int SWP_DEFERERASE = 0x2000;
            public const int SWP_DRAWFRAME = 0x0020;
            public const int SWP_FRAMECHANGED = 0x0020;
            public const int SWP_HIDEWINDOW = 0x0080;
            public const int SWP_NOACTIVATE = 0x0010;
            public const int SWP_NOCOPYBITS = 0x0100;
            public const int SWP_NOMOVE = 0x0002;
            public const int SWP_NOOWNERZORDER = 0x0200;
            public const int SWP_NOREDRAW = 0x0008;
            public const int SWP_NOREPOSITION = 0x0200;
            public const int SWP_NOSENDCHANGING = 0x0400;
            public const int SWP_NOSIZE = 0x0001;
            public const int SWP_NOZORDER = 0x0004;
            public const int SWP_SHOWWINDOW = 0x0040;
     
            public const int HWND_TOP = 0;
            public const int HWND_BOTTOM = 1;
            public const int HWND_TOPMOST = -1;
            public const int HWND_NOTOPMOST = -2;
     
            [DllImport("coredll.dll", SetLastError = true)]
            [return: MarshalAs(UnmanagedType.Bool)]
            public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
     
            [DllImport("coredll.dll", EntryPoint = "FindWindowW", SetLastError = true)]
            public static extern IntPtr FindWindowW(string lpClassName, string lpWindowName);
            public static void HideStartBar()
            {
                IntPtr handle;
                try
                {
                    handle = FindWindowW("HHTaskBar", null);
                    if (handle != IntPtr.Zero)
                    {
                        SetWindowPos((IntPtr)handle, (IntPtr)0, 0, 0, 0, 0, SWP_HIDEWINDOW);
                    }
                }
                catch
                {
                    //MessageBox.Show("Unable to display the status bar");
                }
            }
            public static void ShowStartBar()
            {
                IntPtr handle;
                try
                {
                    handle = FindWindowW("HHTaskBar", null);
                    if (handle != IntPtr.Zero)
                    {
                        SetWindowPos(handle, (IntPtr)0, 0,294, 240,26, SWP_SHOWWINDOW);
                    }
                }
                catch
                {
                    //MessageBox.Show("Unable to display the status bar");
                }
            }
        }
    }

Similar Threads

  1. Creating a LAN network
    By AAID in forum Networking & Security
    Replies: 4
    Last Post: 23-08-2010, 10:54 PM
  2. Creating GIF from a webcam.
    By Itronix in forum Tips & Tweaks
    Replies: 1
    Last Post: 05-03-2010, 06:52 AM
  3. Creating an Ad-Hoc Network?
    By Ashish Goenkar in forum Windows Vista Network
    Replies: 4
    Last Post: 30-09-2009, 12:18 AM
  4. Creating a 3D logo
    By Nadeem in forum Customize Desktop
    Replies: 3
    Last Post: 27-04-2009, 09:11 PM
  5. Creating a Web 2.0 logo
    By need Tos in forum Customize Desktop
    Replies: 6
    Last Post: 10-03-2009, 10:39 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,965,138.69216 seconds with 17 queries