Files
@ 65c134a3d619
Branch filter:
Location: seniordesign-ui/GMap.NET.WindowsMobile/GMap.NET.Internals/Native.cs
65c134a3d619
3.5 KiB
text/x-csharp
Initial import of mapping source (huge commit)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
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();
}
}
|