Native.cs :  » GIS » GMap.NET » GMap » NET » Internals » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GIS » GMap.NET 
GMap.NET » GMap » NET » Internals » Native.cs

namespace GMap.NET.Internals{
   using System;
   using System.Runtime.InteropServices;

   public class Native
   {
      static readonly IntPtr INVALID_HANDLE_VALUE = (IntPtr) (-1);

      // The CharSet must match the CharSet of the corresponding PInvoke signature
      [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
      struct WIN32_FIND_DATA
      {
         public int dwFileAttributes;
         public FILETIME ftCreationTime;
         public FILETIME ftLastAccessTime;
         public FILETIME ftLastWriteTime;
         public int nFileSizeHigh;
         public int nFileSizeLow;
         public int dwOID;
         [MarshalAs(UnmanagedType.ByValTStr, SizeConst=260)]
         public string cFileName;
         [MarshalAs(UnmanagedType.ByValTStr, SizeConst=14)]
         public string cAlternateFileName;
      }

      [StructLayout(LayoutKind.Sequential)]
      struct FILETIME
      {
         public int dwLowDateTime;
         public int dwHighDateTime;
      };

      [DllImport("note_prj", EntryPoint="FindFirstFlashCard")]
      extern static IntPtr FindFirstFlashCard(ref WIN32_FIND_DATA findData);

      [DllImport("note_prj", EntryPoint="FindNextFlashCard")]
      [return: MarshalAs(UnmanagedType.Bool)]
      extern static bool FindNextFlashCard(IntPtr hFlashCard, ref WIN32_FIND_DATA findData);

      [DllImport("coredll")]
      static extern bool FindClose(IntPtr hFindFile);

      public static string GetRemovableStorageDirectory()
      {
         string removableStorageDirectory = null;
         IntPtr handle = IntPtr.Zero;
         try
         {
            WIN32_FIND_DATA findData = new WIN32_FIND_DATA();

            handle = FindFirstFlashCard(ref findData);

            if(handle != INVALID_HANDLE_VALUE)
            {
               do
               {
                  if(!string.IsNullOrEmpty(findData.cFileName))
                  {
                     removableStorageDirectory = findData.cFileName;
                     break;
                  }
               }
               while(FindNextFlashCard(handle, ref findData));
            }
         }
         catch
         {
            removableStorageDirectory = null;
         }
         finally
         {
            if(handle != INVALID_HANDLE_VALUE)
            {
               FindClose(handle);
            }
         }
         return removableStorageDirectory;
      }

      [DllImport("coredll.dll")]
      public static extern int ShowWindow(IntPtr hWnd, int nCmdShow);

      public const int SW_MINIMIZED = 6;

      public const int PPN_UNATTENDEDMODE = 0x0003;
      public const int POWER_NAME = 0x00000001;
      public const int POWER_FORCE = 0x00001000;

      [DllImport("coredll.dll")]
      public static extern bool PowerPolicyNotify(int dwMessage, bool dwData);

      [DllImport("coredll.dll", SetLastError=true)]
      public static extern IntPtr SetPowerRequirement(string pvDevice, CedevicePowerStateState deviceState, uint deviceFlags, string pvSystemState, ulong stateFlags);

      [DllImport("coredll.dll", SetLastError=true)]
      public static extern int ReleasePowerRequirement(IntPtr hPowerReq);

      public enum CedevicePowerStateState : int
      {
         PwrDeviceUnspecified=-1,
         D0=0,
         D1,
         D2,
         D3,
         D4,
      }

      [DllImport("coredll")]
      public static extern void SystemIdleTimerReset();
   }
}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.