⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rapi.vb

📁 Programming the .NET Compact Framework with vb 源代码
💻 VB
📖 第 1 页 / 共 3 页
字号:
' Library Name: Rapi.dll
'
' File Name: Rapi.vb - P/Invoke wrappers for RAPI functions
'
' Generated by PInvoke Wizard (v 1.0) from The Paul Yao Company http://www.paulyao.com 
'
' Code from _Programming the .NET Compact Framework with C#_
' and _Programming the .NET Compact Framework with VB_
' (c) Copyright 2002-2003 Paul Yao and David Durant. 
' All rights reserved.

Imports System
Imports System.Runtime.InteropServices

   '/ <summary>
   '/ Rapi - Wrapper for ActiveSync RAPI functions.
   '/ </summary>
   Public Class Rapi
      Public Const DllName As String = "rapi.dll"
      Public Const MAX_PATH As Integer = 260
      Public Const S_OK As Integer = 0
      Public Const ERROR_SUCCESS As Integer = 0
      Public Const ERROR_NO_MORE_ITEMS As Integer = 259
      Public Const E_FAIL As Integer = &H80004005
      Public Const RAPI_TRUE As Integer = 1
      Public Const RAPI_FALSE As Integer = 0
      Public Shared INVALID_HANDLE_VALUE As IntPtr = New IntPtr(&HFFFFFFFF)

      ' Registry values.
      Public Shared HKEY_CLASSES_ROOT As IntPtr = New IntPtr(&H80000000)
      Public Shared HKEY_CURRENT_USER As IntPtr = New IntPtr(&H80000001)
      Public Shared HKEY_LOCAL_MACHINE As IntPtr = New IntPtr(&H80000002)
      Public Shared HKEY_USERS As IntPtr = New IntPtr(&H80000003)

      <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode, Pack:=4)> _
         Public Structure CE_FIND_DATA
         Public dwFileAttributes As Integer
         Public ftCreationTime As FILETIME
         Public ftLastAccessTime As FILETIME
         Public ftLastWriteTime As FILETIME
         Public nFileSizeHigh As Integer
         Public nFileSizeLow As Integer
         Public dwOID As Integer
         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_PATH)> _
         Public cFileName As String
         End Structure


      <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode, Pack:=4)> _
      Public Structure CEPROPID
         Dim type As CEVT
         Dim id As Short
      End Structure

      Public Enum FAF
         FAF_ATTRIBUTES = &H1
         FAF_CREATION_TIME = &H2
         FAF_LASTACCESS_TIME = &H4
         FAF_LASTWRITE_TIME = &H8
         FAF_SIZE_HIGH = &H10
         FAF_SIZE_LOW = &H20
         FAF_OID = &H40
         FAF_NAME = &H80
         FAF_FLAG_COUNT = 8
         FAF_ATTRIB_CHILDREN = &H1000
         FAF_ATTRIB_NO_HIDDEN = &H2000
         FAF_FOLDERS_ONLY = &H4000
         FAF_NO_HIDDEN_SYS_ROMMODULES = &H8000
         FAF_GETTARGET = &H10000
      End Enum

      Public Enum FAD
         FAD_OID = &H1
         FAD_FLAGS = &H2
         FAD_NAME = &H4
         FAD_TYPE = &H8
         FAD_NUM_RECORDS = &H10
         FAD_NUM_SORT_ORDER = &H20
         FAD_SIZE = &H40
         FAD_LAST_MODIFIED = &H80
         FAD_SORT_SPECS = &H100
         FAD_FLAG_COUNT = 9
      End Enum

      Public Enum FILE_ATTRIBUTE
         FILE_ATTRIBUTE_HAS_CHILDREN = &H10000
         FILE_ATTRIBUTE_SHORTCUT = &H20000
         FILE_ATTRIBUTE_READONLY = &H1
         FILE_ATTRIBUTE_HIDDEN = &H2
         FILE_ATTRIBUTE_SYSTEM = &H4
         FILE_ATTRIBUTE_DIRECTORY = &H10
         FILE_ATTRIBUTE_ARCHIVE = &H20
         FILE_ATTRIBUTE_INROM = &H40
         FILE_ATTRIBUTE_ENCRYPTED = &H40
         FILE_ATTRIBUTE_NORMAL = &H80
         FILE_ATTRIBUTE_TEMPORARY = &H100
         FILE_ATTRIBUTE_SPARSE_FILE = &H200
         FILE_ATTRIBUTE_REPARSE_POINT = &H400
         FILE_ATTRIBUTE_COMPRESSED = &H800
         FILE_ATTRIBUTE_OFFLINE = &H1000
         FILE_ATTRIBUTE_ROMSTATICREF = &H1000
         FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = &H2000
         FILE_ATTRIBUTE_ROMMODULE = &H2000
      End Enum

      Public Enum RAPI_ERROR
         ERROR_FILE_NOT_FOUND = 2
         ERROR_PATH_NOT_FOUND = 3
         ERROR_TOO_MANY_OPEN_FILES = 4
         ERROR_ACCESS_DENIED = 5
         ERROR_INVALID_HANDLE = 6
      End Enum

      Public Enum RAPISTREAMFLAG
         STREAM_TIMEOUT_READ
      End Enum


      Public Enum REGTYPE
         REG_NONE = 0
         REG_SZ = 1
         REG_EXPAND_SZ = 2
         REG_BINARY = 3
         REG_DWORD = 4
         REG_DWORD_LITTLE_ENDIAN = 4
         REG_DWORD_BIG_ENDIAN = 5
         REG_LINK = 6
         REG_MULTI_SZ = 7
         REG_RESOURCE_LIST = 8
      End Enum

      Public Interface ISequentialStream
         Function Read(ByRef pv As Byte, ByVal cb As Integer, ByRef pcbRead As Integer) As Integer
         Function Write(ByRef pv As Byte, ByVal cb As Integer, ByRef pcbWritten As Integer) As Integer
      End Interface

      Public Interface IStream
    Inherits ISequentialStream
      Function Seek(ByVal dlibMove As Long, ByVal dwOrigin As Integer, ByRef plibNewPosition As Long) As Integer
      Function SetSize(ByVal libNewSize As Long) As Integer
      Function CopyTo(ByVal pstm As IStream, ByVal cb As Long, ByRef pcbRead As Long, ByRef pcbWritten As Long) As Integer
      Function Commit(ByVal grfCommitFlags As Integer) As Integer
      Function Revert() As Integer
      Function LockRegion(ByVal libOffset As Long, ByVal cb As Long, ByVal dwLockType As Integer) As Integer
      Function UnlockRegion(ByVal libOffset As Long, ByVal cb As Long, ByVal dwLockType As Integer) As Integer
      Function Stat(ByRef pstatstg As STATSTG, ByVal grfStatFlag As Integer) As Integer
      Function Clone(ByRef ppstm As IStream) As Integer
      End Interface

      Public Interface IRAPIStream
    Inherits IStream
         Function SetRapiStat(ByVal dwValue As Integer) As Integer
         Function GetRapiStat(ByRef pdwValue As Integer) As Integer
      End Interface


      <StructLayout(LayoutKind.Sequential, Pack:=4)> _
         Public Structure STORE_INFORMATION
         Dim dwStoreSize As Integer
         Dim dwFreeSize As Integer
         End Structure


      <StructLayout(LayoutKind.Sequential, Pack:=4)> _
         Public Structure CEGUID
         Dim Data1 As Integer
         Dim Data2 As Integer
         Dim Data3 As Integer
         Dim Data4 As Integer
         End Structure


      <StructLayout(LayoutKind.Sequential, Pack:=4)> _
         Public Structure CENOTIFICATION
         Dim dwSize As Integer
         Dim dwParam As Integer
         Dim uType As Integer
         Dim guid As CEGUID
         Dim oid As Integer
         Dim oidParent As Integer
         End Structure


      Public Const CEDB_EXNOTIFICATION As Integer = &H1

      <StructLayout(LayoutKind.Sequential, Pack:=4)> _
         Public Structure CENOTIFYREQUEST
         Dim dwSize As Integer
         Dim hwnd As IntPtr
         Dim dwFlags As Integer
         Dim hHeap As IntPtr
         Dim dwParam As Integer
         End Structure


      <StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Unicode)> _
         Public Structure CEFILEINFO
         Dim dwAttributes As Integer
         Dim oidParent As Integer
         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_PATH)> _
         Dim szFileName As String
         Dim ftLastChanged As FILETIME
         Dim dwLength As Integer
         End Structure


     <StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Unicode)> _
         Public Structure CEDIRINFO
         Dim dwAttributes As Integer
         Dim oidParent As Integer
         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=MAX_PATH)> _
         Dim szDirName As String
         End Structure


      <StructLayout(LayoutKind.Sequential, Pack:=4)> _
         Public Structure CERECORDINFO
         Dim oidParent As Integer
         End Structure


       Public Enum CEDB_SORT
         CEDB_SORT_DESCENDING = &H1
         CEDB_SORT_CASEINSENSITIVE = &H2
         CEDB_SORT_UNKNOWNFIRST = &H4
         CEDB_SORT_GENERICORDER = &H8
       End Enum

      <StructLayout(LayoutKind.Sequential, Pack:=4)> _
         Public Structure SORTORDERSPEC
         Public propid As Integer
         Public dwFlags As Integer
         End Structure



      Public Const CEDB_MAXDBASENAMELEN As Integer = 32
      Public Const CEDB_MAXSORTORDER As Integer = 4

      Public Enum CEDB
         CEDB_VALIDNAME = &H1
         CEDB_VALIDTYPE = &H2
         CEDB_VALIDSORTSPEC = &H4
         CEDB_VALIDMODTIME = &H8
         CEDB_VALIDDBFLAGS = &H10
         CEDB_VALIDCREATE = CEDB_VALIDNAME + CEDB_VALIDTYPE + CEDB_VALIDSORTSPEC + CEDB_VALIDDBFLAGS
         CEDB_NOCOMPRESS = &H10000
      End Enum

      <StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Unicode)> _
      Public Structure CEDBASEINFO
         Public dwFlags As Integer
         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CEDB_MAXDBASENAMELEN)> _
         Public szDbaseName As String
         Public dwDbaseType As Integer
         Public wNumRecords As Short
         Public wNumSortOrder As Short
         Public dwSize As Integer
         Public ftLastModified As FILETIME

         ' public SORTORDERSPEC [] rgSortSpecs;
         ' Try #2 -- This works.
         Public rgSortSpec1 As SORTORDERSPEC
         Public rgSortSpec2 As SORTORDERSPEC
         Public rgSortSpec3 As SORTORDERSPEC
         Public rgSortSpec4 As SORTORDERSPEC

#If False Then
         ' public SORTORDERSPEC [] rgSortSpecs;
         ' Try #3: This works also - but not as nice.
         Public Sort1_propid As Integer
         Public Sort1_dwFlags As Integer
         Public Sort2_propid As Integer
         Public Sort2_dwFlags As Integer
         Public Sort3_propid As Integer
         Public Sort3_dwFlags As Integer
         Public Sort4_propid As Integer
         Public Sort4_dwFlags As Integer

         ' public SORTORDERSPEC [] rgSortSpecs;
         ' Try #1: The original - DESKTOP P/Invoke cannot deal with this
         ' Desktop P/Invoke cannot deal with this - 
         ' problem with structure array in a structure in a structure?!?
         < MarshalAs(UnmanagedType.ByValArray, SizeConst:=CEDB_MAXSORTORDER)> _ 
         Public rgSortSpecs() As SORTORDERSPEC
#End If
      End Structure


      <StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Unicode)> _
         Public Structure CEDB_FIND_DATA
         Public OidDb As Integer
         Public DbInfo As CEDBASEINFO
         End Structure


      Public Enum OBJTYPE
         OBJTYPE_INVALID = 0
         OBJTYPE_FILE = 1
         OBJTYPE_DIRECTORY = 2
         OBJTYPE_DATABASE = 3
         OBJTYPE_RECORD = 4
      End Enum

      <StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Unicode)> _
         Public Structure CEOIDINFO
         Dim wObjType As Short
         Dim wPad As Short
         <StructLayout(LayoutKind.Explicit)> _
            Public Structure _NESTED_CEOIDINFO_UNION
               <FieldOffset(0)> Dim infFile As CEFILEINFO
               <FieldOffset(0)> Dim infDirectory As CEDIRINFO
               <FieldOffset(0)> Dim infDatabase As CEDBASEINFO
               <FieldOffset(0)> Dim infRecord As CERECORDINFO
            End Structure

         End Structure


      Public Const CEDB_AUTOINCREMENT As Integer = &H1

      Public Enum CEDB_SEEK
         CEDB_SEEK_CEOID = &H1
         CEDB_SEEK_BEGINNING = &H2
         CEDB_SEEK_END = &H4
         CEDB_SEEK_CURRENT = &H8
         CEDB_SEEK_VALUESMALLER = &H10
         CEDB_SEEK_VALUEFIRSTEQUAL = &H20
         CEDB_SEEK_VALUEGREATER = &H40
         CEDB_SEEK_VALUENEXTEQUAL = &H80
      End Enum

      <StructLayout(LayoutKind.Sequential, Pack:=4)> _
         Public Structure CEBLOB
         Dim dwCount As Integer
         Dim lpb() As Byte
         End Structure


      Public Enum CEVT As Short
         CEVT_I2 = 2
         CEVT_UI2 = 18
         CEVT_I4 = 3
         CEVT_UI4 = 19
         CEVT_FILETIME = 64
         CEVT_LPWSTR = 31
         CEVT_BLOB = 65
         CEVT_BOOL = 11
         CEVT_R8 = 5
      End Enum

      <StructLayout(LayoutKind.Explicit, CharSet:=CharSet.Unicode)> _
         Public Structure CEVALUNION
         <FieldOffset(0)> Dim iVal As Short
         <FieldOffset(0)> Dim uiVal As Short
         <FieldOffset(0)> Dim lVal As Integer
         <FieldOffset(0)> Dim ulVal As Integer
         <FieldOffset(0)> Dim filetime As filetime
         <FieldOffset(0)> Dim lpwstr As String
         <FieldOffset(0)> Dim blob As CEBLOB
         <FieldOffset(0)> Dim boolVal As Integer
         <FieldOffset(0)> Dim dblVal As Double
         End Structure


      Public Enum CEDB_PROPVAL_FLAGS
         CEDB_PROPNOTFOUND = &H100
         CEDB_PROPDELETE = &H200
      End Enum

      <StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Unicode)> _
         Public Structure CEPROPVAL
         Dim propid As Integer
         Dim wLenData As Short
         Dim wFlags As Short
         Dim val As CEVALUNION
         End Structure


      Public Const CEDB_MAXDATABLOCKSIZE As Integer = 4092
      Public Const CEDB_MAXPROPDATASIZE As Integer = CEDB_MAXDATABLOCKSIZE * 16
      Public Const CEDB_MAXRECORDSIZE As Integer = 128 * 1024

      Public Enum CEDB_READRECORDPROPFLAGS
         CEDB_ALLOWREALLOC = &H1
      End Enum

       Public Enum SYSMEM
         SYSMEM_CHANGED = 0
         SYSMEM_MUSTREBOOT = 1
         SYSMEM_REBOOTPENDING = 2
         SYSMEM_FAILED = 3
       End Enum

       <StructLayout(LayoutKind.Sequential, Pack:=4, CharSet:=CharSet.Unicode)> _
         Public Structure CEOSVERSIONINFO
         Dim dwOSVersionInfoSize As Integer
         Dim dwMajorVersion As Integer
         Dim dwMinorVersion As Integer
         Dim dwBuildNumber As Integer
         Dim dwPlatformId As Integer
         <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
         Dim szCSDVersion As String
         End Structure


      Public Enum AC
         AC_LINE_OFFLINE = &H0
         AC_LINE_ONLINE = &H1
         AC_LINE_BACKUP_POWER = &H2
         AC_LINE_UNKNOWN = &HFF
      End Enum

      Public Enum BATTERY_FLAG
         BATTERY_FLAG_HIGH = &H1
         BATTERY_FLAG_LOW = &H2
         BATTERY_FLAG_CRITICAL = &H4
         BATTERY_FLAG_CHARGING = &H8

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -