VBA 64位API声明语句第013讲

B站影视 港台电影 2025-09-03 18:03 1

摘要:跟我学VBA,我这里专注VBA, 授人以渔。我98年开始,从源码接触VBA已经20余年了,随着年龄的增长,越来越觉得有必要把这项技能传递给需要这项技术的职场人员。希望职场和数据打交道的朋友,都来学习VBA,利用VBA,起码可以提高自己的工作效率,可以有时间多陪

跟我学VBA,我这里专注VBA, 授人以渔。我98年开始,从源码接触VBA已经20余年了,随着年龄的增长,越来越觉得有必要把这项技能传递给需要这项技术的职场人员。希望职场和数据打交道的朋友,都来学习VBA,利用VBA,起码可以提高自己的工作效率,可以有时间多陪陪父母,多陪陪家人,何乐而不为呢?我的教程一共九套,从入门开始一直讲到程序的分发,是学习利用VBA的实用教程。这份API资料是随高级教程赠送的.

这讲我们继续学习VBA 64位API声明语句第013讲,这些内容是MS的权威资料,看似枯燥,但对于想学习API函数的朋友是非常有用的。

【分享成果,随喜正能量】252 有些人的信仰,是挂在墙上的,实际上他对自己都不信。有些人的信仰,是浸入骨子里的,它没有高吭的言语,信誓旦旦的承诺,只有默默的守护。。

当学员学习到高级阶段,如果引用API,这个资料可以直接查到64位写法。大多数情况下我们是将低版本的程序文件升级到高版本,这时您就不必为如下的错误提示所困扰了:

Declare PtrSafe Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Declare PtrSafe Function GlobalAlloc Lib "kernel32" Alias "GlobalAlloc" (ByVal wFlags As Long, ByVal dwBytes As LongPtr) As LongPtr

Declare PtrSafe Function GlobalFree Lib "kernel32" Alias "GlobalFree" (ByVal hMem As LongPtr) As LongPtr

Declare PtrSafe Function GlobalHandle Lib "kernel32" Alias "GlobalHandle" (wMem As Any) As LongPtr

Declare PtrSafe Function GlobalLock Lib "kernel32" Alias "GlobalLock" (ByVal hMem As LongPtr) As LongPtr

Declare PtrSafe Function GlobalReAlloc Lib "kernel32" Alias "GlobalReAlloc" (ByVal hMem As LongPtr, ByVal dwBytes As LongPtr, ByVal wFlags As Long) As LongPtr

Declare PtrSafe Function GlobalSize Lib "kernel32" Alias "GlobalSize" (ByVal hMem As LongPtr) As LongPtr

Declare PtrSafe Function GlobalUnlock Lib "kernel32" Alias "GlobalUnlock" (ByVal hMem As LongPtr) As Long

Declare PtrSafe Function GlobalFlags Lib "kernel32" Alias "GlobalFlags" (ByVal hMem As LongPtr) As Long

Declare PtrSafe Sub GlobalMemoryStatus Lib "kernel32" Alias "GlobalMemoryStatus" (lpBuffer As MEMORYSTATUS)

Const LNOTIFY_OUTOFMEM = 0

Const LNOTIFY_MOVE = 1

Const LNOTIFY_DISCARD = 2

Declare PtrSafe Function LocalAlloc Lib "kernel32" Alias "LocalAlloc" (ByVal wFlags As Long, ByVal wBytes As LongPtr) As LongPtr

Declare PtrSafe Function LocalFree Lib "kernel32" Alias "LocalFree" (ByVal hMem As LongPtr) As LongPtr

Declare PtrSafe Function LocalHandle Lib "kernel32" Alias "LocalHandle" (wMem As Any) As LongPtr

Declare PtrSafe Function LocalLock Lib "kernel32" Alias "LocalLock" (ByVal hMem As LongPtr) As LongPtr

Declare PtrSafe Function LocalReAlloc Lib "kernel32" Alias "LocalReAlloc" (ByVal hMem As LongPtr, ByVal wBytes As LongPtr, ByVal wFlags As Long) As LongPtr

Declare PtrSafe Function LocalSize Lib "kernel32" Alias "LocalSize" (ByVal hMem As LongPtr) As Long

Declare PtrSafe Function LocalUnlock Lib "kernel32" Alias "LocalUnlock" (ByVal hMem As LongPtr) As Long

Declare PtrSafe Function LocalFlags Lib "kernel32" Alias "LocalFlags" (ByVal hMem As LongPtr) As Long

Type MEMORY_BASIC_INFORMATION

BaseAddress as LongPtr

AllocationBase as LongPtr

AllocationProtect As Long

RegionSize As LongPtr

State As Long

Protect As Long

lType As Long

End Type

Declare PtrSafe Function FlushInstructionCache Lib "kernel32" Alias "FlushInstructionCache" (ByVal hProcess As LongPtr, lpBaseAddress As Any, ByVal dwSize As LongPtr) As Long

Declare PtrSafe Function VirtualAlloc Lib "kernel32" Alias "VirtualAlloc" (lpAddress As Any, ByVal dwSize As LongPtr, ByVal flAllocationType As Long, ByVal flProtect As Long) As LongPtr

Declare PtrSafe Function VirtualFree Lib "kernel32" Alias "VirtualFree" (lpAddress As Any, ByVal dwSize As LongPtr, ByVal dwFreeType As Long) As Long

Declare PtrSafe Function VirtualProtect Lib "kernel32" Alias "VirtualProtect" (lpAddress As Any, ByVal dwSize As LongPtr, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long

Declare PtrSafe Function VirtualQuery Lib "kernel32" Alias "VirtualQuery" (lpAddress As Any, lpBuffer As MEMORY_BASIC_INFORMATION, ByVal dwLength As LongPtr) As LongPtr

Declare PtrSafe Function VirtualProtectEx Lib "kernel32" Alias "VirtualProtectEx" (ByVal hProcess As LongPtr, lpAddress As Any, ByVal dwSize As LongPtr, ByVal flNewProtect As Long, lpflOldProtect As Long) As Long

Declare PtrSafe Function VirtualQueryEx Lib "kernel32" Alias "VirtualQueryEx" (ByVal hProcess As LongPtr, lpAddress As Any, lpBuffer As MEMORY_BASIC_INFORMATION, ByVal dwLength As LongPtr) As LongPtr

Declare PtrSafe Function HeapCreate Lib "kernel32" Alias "HeapCreate" (ByVal flOptions As Long, ByVal dwInitialSize As LongPtr, ByVal dwMaximumSize As LongPtr) As LongPtr

Declare PtrSafe Function HeapDestroy Lib "kernel32" Alias "HeapDestroy" (ByVal hHeap As LongPtr) As Long

Declare PtrSafe Function HeapAlloc Lib "kernel32" Alias "HeapAlloc" (ByVal hHeap As LongPtr, ByVal dwFlags As Long, ByVal dwBytes As LongPtr) As LongPtr

Declare PtrSafe Function HeapReAlloc Lib "kernel32" Alias "HeapReAlloc" (ByVal hHeap As LongPtr, ByVal dwFlags As Long, lpMem As Any, ByVal dwBytes As LongPtr) As LongPtr

Declare PtrSafe Function HeapFree Lib "kernel32" Alias "HeapFree" (ByVal hHeap As LongPtr, ByVal dwFlags As Long, lpMem As Any) As Long

Declare PtrSafe Function HeapSize Lib "kernel32" Alias "HeapSize" (ByVal hHeap As LongPtr, ByVal dwFlags As Long, lpMem As Any) As LongPtr

Declare PtrSafe Function GetProcessHeap Lib "kernel32" Alias "GetProcessHeap" As LongPtr

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

Declare PtrSafe Function OpenProcess Lib "kernel32" Alias "OpenProcess" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPtr

Declare PtrSafe Function GetCurrentProcess Lib "kernel32" Alias "GetCurrentProcess" As LongPtr

Declare PtrSafe Function GetCurrentProcessId Lib "kernel32" Alias "GetCurrentProcessId" As Long

Declare PtrSafe Sub ExitProcess Lib "kernel32" Alias "ExitProcess" (ByVal uExitCode As Long)

Declare PtrSafe Function TerminateProcess Lib "kernel32" Alias "TerminateProcess" (ByVal hProcess As LongPtr, ByVal uExitCode As Long) As Long

Declare PtrSafe Function GetExitCodeProcess Lib "kernel32" Alias "GetExitCodeProcess" (ByVal hProcess As LongPtr, lpExitCode As Long) As Long

Declare PtrSafe Function GetLastError Lib "kernel32" Alias "GetLastError" As Long

Declare PtrSafe Sub SetLastError Lib "kernel32" Alias "SetLastError" (ByVal dwErrCode As Long)

Const SLE_ERROR = &H1

Const SLE_MINORERROR = &H2

Const SLE_WARNING = &H3

Declare PtrSafe Sub SetLastErrorEx Lib "user32" Alias "SetLastErrorEx" (ByVal dwErrCode As Long, ByVal dwType As Long)

Declare PtrSafe Function GetOverlappedResult Lib "kernel32" Alias "GetOverlappedResult" (ByVal hFile As LongPtr, lpOverlapped As OVERLAPPED, lpNumberOfBytesTransferred As Long, ByVal bWait As Long) As Long

Const SEM_FAILCRITICALERRORS = &H1

Const SEM_NOGPFAULTERRORBOX = &H2

Const SEM_NOOPENFILEERRORBOX = &H8000&

Declare PtrSafe Sub SetDebugErrorLevel Lib "user32" Alias "SetDebugErrorLevel" (ByVal dwLevel As Long)

Declare PtrSafe Function SetErrorMode Lib "kernel32" Alias "SetErrorMode" (ByVal wMode As Long) As Long

Declare PtrSafe Function ReadProcessMemory Lib "kernel32" Alias "ReadProcessMemory" (ByVal hProcess As LongPtr, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As LongPtr, lpNumberOfBytesWritten As LongPtr) As Long

Declare PtrSafe Function WriteProcessMemory Lib "kernel32" Alias "WriteProcessMemory" (ByVal hProcess As LongPtr, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As LongPtr, lpNumberOfBytesWritten As LongPtr) As Long

我20多年的VBA实践经验,全部浓缩在下面的各个教程中:

来源:VBA语言专业教育

相关推荐