玖叶教程网

前端编程开发入门

VBA内置函数声明系列之十三(vba 内置函数)

大家好,在64版本OFFICE是最新的版本,我们在学习VBA的时候,API函数也是我们经常要用到的,这讲我们继续分享VBA中64位API函数声明方案,在64版本OFFICE学习VBA时如果还沿用之前的代码会有一些bug,为此我推出了各套教程均是适合64位Office版本和32位Office版本的。为了满足大家的需求,我陆续把在一些API函数如何在64位系统中声明的方法介绍给大家。今日是第十 部分。

Declare PtrSafe Function SetPriorityClass Lib "kernel32" Alias "SetPriorityClass" (ByVal hProcess As LongPtr, ByVal dwPriorityClass As Long) As Long

Declare PtrSafe Function GetPriorityClass Lib "kernel32" Alias "GetPriorityClass" (ByVal hProcess As LongPtr) As Long

#If Win64 Then

Type M128A

Low As LongLong

High As LongLong

End Type

Type XMM_SAVE_AREA32

ControlWord As Integer

StatusWord As Integer

TagWord As Byte

Reserved1 As Byte

ErrorOpcode As Integer

ErrorOffset As Long

ErrorSelector As Integer

Reserved2 As Integer

DataOffset As Long

DataSelector As Integer

Reserved3 As Integer

MxCsr As Long

MxCsr_Mask As Long

FloatRegisters(0 To 7) As M128A

XmmRegisters(0 To 15) As M128A

Reserved4(0 To 95) As Byte

End Type


Type CONTEXT

' Register parameter home addresses

P1Home As LongLong

P2Home As LongLong

P3Home As LongLong

P4Home As LongLong

P5Home As LongLong

P6Home As LongLong


' Control flags

ContextFlags As Long

MxCsr As Long


' Segment Registers and processor flags

SegCs As Integer

SegDs As Integer

SegEs As Integer

SegFs As Integer

SegGs As Integer

SegSs As Integer

EFlags As Long


' Debug registers

Dr0 As LongLong

Dr1 As LongLong

Dr2 As LongLong

Dr3 As LongLong

Dr6 As LongLong

Dr7 As LongLong


' Integer registers

Rax As LongLong

Rcx As LongLong

Rdx As LongLong

Rbx As LongLong

Rsp As LongLong

Rbp As LongLong

Rsi As LongLong

Rdi As LongLong

R8 As LongLong

R9 As LongLong

R10 As LongLong

R11 As LongLong

R12 As LongLong

R13 As LongLong

R14 As LongLong

R15 As LongLong


' Program counter

Rip As LongLong


' Floating point state

FltSave As XMM_SAVE_AREA32


' Vector registers

VectorRegister(0 To 25) As M128A

VectorControl As LongLong


' Special debug control registers

DebugControl As LongLong

LastBranchToRip As LongLong

LastBranchFromRip As LongLong

LastExceptionToRip As LongLong

LastExceptionFromRip As LongLong

End Type

#ElseIf Win32 Then

Const SIZE_OF_80387_REGISTERS = 80

Const MAXIMUM_SUPPORTED_EXTENSION = 512


Type FLOATING_SAVE_AREA

ControlWord As Long

StatusWord As Long

TagWord As Long

ErrorOffset As Long

ErrorSelector As Long

DataOffset As Long

DataSelector As Long

RegisterArea(0 To SIZE_OF_80387_REGISTERS - 1) As Byte

Cr0NpxState As Long

End Type


Type CONTEXT

ContextFlags As Long


Dr0 As Long

Dr1 As Long

Dr2 As Long

Dr3 As Long

Dr6 As Long

Dr7 As Long


FloatSave As FLOATING_SAVE_AREA


SegGs As Long

SegFs As Long

SegEs As Long

SegDs As Long


Edi As Long

Esi As Long

Ebx As Long

Edx As Long

Ecx As Long

Eax As Long


Ebp As Long

Eip As Long

SegCs As Long ' MUST BE SANITIZED

EFlags As Long ' MUST BE SANITIZED

Esp As Long

SegSs As Long


ExtendedRegisters(0 To MAXIMUM_SUPPORTED_EXTENSION - 1) As Byte

End Type

#End If


Type EXCEPTION_POINTERS

pExceptionRecord As EXCEPTION_RECORD

ContextRecord As CONTEXT

End Type


Type LDT_BYTES ' Defined for use in LDT_ENTRY Type

BaseMid As Byte

Flags1 As Byte

Flags2 As Byte

BaseHi As Byte

End Type


Type LDT_ENTRY

LimitLow As Integer

BaseLow As Integer

HighWord As Long ' Can use LDT_BYTES Type

End Type


Declare PtrSafe Sub FatalExit Lib "kernel32" Alias "FatalExit" (ByVal code As Long)

Declare PtrSafe Function GetEnvironmentStrings Lib "kernel32" Alias "GetEnvironmentStringsA" () As String

Declare PtrSafe Sub RaiseException Lib "kernel32" Alias "RaiseException" (ByVal dwExceptionCode As Long, ByVal dwExceptionFlags As Long, ByVal nNumberOfArguments As Long, lpArguments As LongPtr)

Declare PtrSafe Function UnhandledExceptionFilter Lib "kernel32" Alias "UnhandledExceptionFilter" (ExceptionInfo As EXCEPTION_POINTERS) As Long


Declare PtrSafe Function CreateThread Lib "kernel32" Alias "CreateThread" (lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal dwStackSize As LongPtr, lpStartAddress As LongPtr, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr

Declare PtrSafe Function CreateRemoteThread Lib "kernel32" Alias "CreateRemoteThread" (ByVal hProcess As LongPtr, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal dwStackSize As LongPtr, lpStartAddress As LongPtr, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadId As Long) As LongPtr

Declare PtrSafe Function GetCurrentThread Lib "kernel32" Alias "GetCurrentThread" () As LongPtr

Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" Alias "GetCurrentThreadId" () As Long

Declare PtrSafe Function SetThreadPriority Lib "kernel32" Alias "SetThreadPriority" (ByVal hThread As LongPtr, ByVal nPriority As Long) As Long

Declare PtrSafe Function GetThreadPriority Lib "kernel32" Alias "GetThreadPriority" (ByVal hThread As LongPtr) As Long

Declare PtrSafe Function GetThreadTimes Lib "kernel32" Alias "GetThreadTimes" (ByVal hThread As LongPtr, lpCreationTime As FILETIME, lpExitTime As FILETIME, lpKernelTime As FILETIME, lpUserTime As FILETIME) As Long

Declare PtrSafe Sub ExitThread Lib "kernel32" Alias "ExitThread" (ByVal dwExitCode As Long)

Declare PtrSafe Function TerminateThread Lib "kernel32" Alias "TerminateThread" (ByVal hThread As LongPtr, ByVal dwExitCode As Long) As Long

Declare PtrSafe Function GetExitCodeThread Lib "kernel32" Alias "GetExitCodeThread" (ByVal hThread As LongPtr, lpExitCode As Long) As Long

Declare PtrSafe Function GetThreadSelectorEntry Lib "kernel32" Alias "GetThreadSelectorEntry" (ByVal hThread As LongPtr, ByVal dwSelector As Long, lpSelectorEntry As LDT_ENTRY) As Long


' COMM declarations

Declare PtrSafe Function SetCommState Lib "kernel32" Alias "SetCommState" (ByVal hCommDev As LongPtr, lpDCB As DCB) As Long

Declare PtrSafe Function SetCommTimeouts Lib "kernel32" Alias "SetCommTimeouts" (ByVal hFile As LongPtr, lpCommTimeouts As COMMTIMEOUTS) As Long

Declare PtrSafe Function GetCommState Lib "kernel32" Alias "GetCommState" (ByVal nCid As LongPtr, lpDCB As DCB) As Long


分享成果,随喜正能量

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言