64位OfficeAPI声明语句第115讲

VBA语言専攻 2024-02-06 18:00:23

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

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

【分享成果,随喜正能量】 修得不生气的心,才有好福气的命,一张笑脸,向顺,向福。一切有为法,如梦幻泡影,如露亦如电,应作如是观。若是生活发生了太多,那就呵护好自己内心的快乐,快乐多一点,生活的阳光就多一分。。

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

MousePos As POINTAPI

End Type

Type ANIMATIONINFO

cbSize As Long

iMinAnimate As Long

End Type

Type MINIMIZEDMETRICS

cbSize As Long

iWidth As Long

iHorzGap As Long

iVertGap As Long

iArrange As Long

End Type

' Define API decoration for direct importing of DLL references.

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

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

Const PROCESS_HEAP_REGION = &H1

Const PROCESS_HEAP_UNCOMMITTED_RANGE = &H2

Const PROCESS_HEAP_ENTRY_BUSY = &H4

Const PROCESS_HEAP_ENTRY_MOVEABLE = &H10

Const PROCESS_HEAP_ENTRY_DDESHARE = &H20

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

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

' GetBinaryType return values.

Const SCS_32BIT_BINARY = 0

Const SCS_DOS_BINARY = 1

Const SCS_WOW_BINARY = 2

Const SCS_PIF_BINARY = 3

Const SCS_POSIX_BINARY = 4

Const SCS_OS216_BINARY = 5

Declare PtrSafe Function GetBinaryType Lib "kernel32" Alias "GetBinaryTypeA" (ByVal lpApplicationName As String, lpBinaryType As Long) As Long

Declare PtrSafe Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

Declare PtrSafe Function GetProcessAffinityMask Lib "kernel32" Alias "GetProcessAffinityMask" (ByVal hProcess As LongPtr, lpProcessAffinityMask As LongPtr, SystemAffinityMask As LongPtr) As Long

' Logon Support APIs

Const LOGON32_LOGON_INTERACTIVE = 2

Const LOGON32_LOGON_BATCH = 4

Const LOGON32_LOGON_SERVICE = 5

Const LOGON32_PROVIDER_DEFAULT = 0

Const LOGON32_PROVIDER_WINNT35 = 1

Declare PtrSafe Function LogonUser Lib "kernel32" Alias "LogonUserA" (ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As Long, ByVal dwLogonProvider As Long, phToken As LongPtr) As Long

Declare PtrSafe Function ImpersonateLoggedOnUser Lib "kernel32" Alias "ImpersonateLoggedOnUser" (ByVal hToken As LongPtr) As Long

Declare PtrSafe Function CreateProcessAsUser Lib "advapi32.dll" Alias "CreateProcessAsUserA" (ByVal hToken As LongPtr, ByVal lpApplicationName As String, ByVal lpCommandLine As String, lpProcessAttributes As SECURITY_ATTRIBUTES, lpThreadAttributes As SECURITY_ATTRIBUTES, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As String, ByVal lpCurrentDirectory As String, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long

' Performance counter API's

Type OSVERSIONINFO

dwOSVersionInfoSize As Long

dwMajorVersion As Long

dwMinorVersion As Long

dwBuildNumber As Long

dwPlatformId As Long

szCSDVersion(0 To 127) As Byte ' Maintenance string for PSS usage

End Type

' dwPlatformId defines:

'

Const VER_PLATFORM_WIN32s = 0

Const VER_PLATFORM_WIN32_WINDOWS = 1

Const VER_PLATFORM_WIN32_NT = 2

Declare PtrSafe Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long

' Power Management APIs

Const AC_LINE_OFFLINE = &H0

Const AC_LINE_ONLINE = &H1

Const AC_LINE_BACKUP_POWER = &H2

Const AC_LINE_UNKNOWN = &HFF

Const BATTERY_FLAG_HIGH = &H1

Const BATTERY_FLAG_LOW = &H2

Const BATTERY_FLAG_CRITICAL = &H4

Const BATTERY_FLAG_CHARGING = &H8

Const BATTERY_FLAG_NO_BATTERY = &H80

Const BATTERY_FLAG_UNKNOWN = &HFF

Const BATTERY_PERCENTAGE_UNKNOWN = &HFF

Const BATTERY_LIFE_UNKNOWN = &HFFFFFFFF

Type SYSTEM_POWER_STATUS

ACLineStatus As Byte

BatteryFlag As Byte

BatteryLifePercent As Byte

Reserved1 As Byte

BatteryLifeTime As Long

BatteryFullLifeTime As Long

End Type

Declare PtrSafe Function GetSystemPowerStatus Lib "kernel32" Alias "GetSystemPowerStatus" (lpSystemPowerStatus As SYSTEM_POWER_STATUS) As Long

Declare PtrSafe Function SetSystemPowerState Lib "kernel32" Alias "SetSystemPowerState" (ByVal fSuspend As Long, ByVal fForce As Long) As Long

' * commdlg.h -- This module defines the 32-Bit Common Dialog APIs *

Type OPENFILENAME

lStructSize As Long

hwndOwner As LongPtr

hInstance As LongPtr

lpstrFilter As String

lpstrCustomFilter As String

nMaxCustFilter As Long

nFilterIndex As Long

lpstrFile As String

nMaxFile As Long

lpstrFileTitle As String

nMaxFileTitle As Long

lpstrInitialDir As String

lpstrTitle As String

flags As Long

nFileOffset As Integer

nFileExtension As Integer

lpstrDefExt As String

lCustData As LongPtr

lpfnHook As LongPtr

lpTemplateName As String

'#if (_WIN32_WINNT >= 0x0500)

pvReserved As LongPtr

dwReserved As Long

FlagsEx As Long

'#endif // (_WIN32_WINNT >= 0x0500)

End Type

Declare PtrSafe Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Declare PtrSafe Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long

Declare PtrSafe Function GetFileTitle Lib "comdlg32.dll" Alias "GetFileTitleA" (ByVal lpszFile As String, ByVal lpszTitle As String, ByVal cbBuf As Integer) As Integer

Const OFN_READONLY = &H1

Const OFN_OVERWRITEPROMPT = &H2

Const OFN_HIDEREADONLY = &H4

Const OFN_NOCHANGEDIR = &H8

Const OFN_SHOWHELP = &H10

Const OFN_ENABLEHOOK = &H20

Const OFN_ENABLETEMPLATE = &H40

Const OFN_ENABLETEMPLATEHANDLE = &H80

Const OFN_NOVALIDATE = &H100

Const OFN_ALLOWMULTISELECT = &H200

Const OFN_EXTENSIONDIFFERENT = &H400

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

0 阅读:0