跟我學VBA,我這里專注VBA, 授人以漁。我98年開始,從源碼接觸VBA已經20余年了,隨著年齡的增長,越來越覺得有必要把這項技能傳遞給需要這項技術的職場人員。希望職場和數據打交道的朋友,都來學習VBA,利用VBA,起碼可以提高自己的工作效率,可以有時間多陪陪父母,多陪陪家人,何樂而不為呢?我的教程一共九套,從入門開始一直講到程序的分發,是學習利用VBA的實用教程。這份API資料是隨高級教程贈送的.
這講我們繼續學習VBA 64位API聲明語句第012講,這些內容是MS的權威資料,看似枯燥,但對于想學習API函數的朋友是非常有用的。
【分享成果,隨喜正能量】222 苦非苦,樂非樂,只是一時的執念而已。執于一念,將受困于一念;一念放下,會自在于心間。物隨心轉,境由心造,煩惱皆由心生。有些人,有些事,是可遇不可求的,強求只有痛苦。既然這樣,就放寬心態,順其自然。無論何時何地,都要擁有一顆安閑自在的心,保持豁達的心態。
當學員學習到高級階段,如果引用API,這個資料可以直接查到64位寫法。大多數情況下我們是將低版本的程序文件升級到高版本,這時您就不必為如下的錯誤提示所困擾了:
Declare PtrSafe Function ContinueDebugEvent Lib "kernel32" Alias "ContinueDebugEvent" (ByVal dwProcessId As Long, ByVal dwThreadId As Long, ByVal dwContinueStatus As Long) As Long
Declare PtrSafe Function DebugActiveProcess Lib "kernel32" Alias "DebugActiveProcess" (ByVal dwProcessId As Long) As Long
Type CRITICAL_SECTION
DebugInfo As LongPtr
LockCount As Long
RecursionCount As Long
OwningThread As LongPtr
LockSemaphore As LongPtr
SpinCount As LongPtr
End Type
Declare PtrSafe Sub InitializeCriticalSection Lib "kernel32" Alias "InitializeCriticalSection" (lpCriticalSection As CRITICAL_SECTION)
Declare PtrSafe Sub EnterCriticalSection Lib "kernel32" Alias "EnterCriticalSection" (lpCriticalSection As CRITICAL_SECTION)
Declare PtrSafe Sub LeaveCriticalSection Lib "kernel32" Alias "LeaveCriticalSection" (lpCriticalSection As CRITICAL_SECTION)
Declare PtrSafe Sub DeleteCriticalSection Lib "kernel32" Alias "DeleteCriticalSection" (lpCriticalSection As CRITICAL_SECTION)
Declare PtrSafe Function SetEvent Lib "kernel32" Alias "SetEvent" (ByVal hEvent As LongPtr) As Long
Declare PtrSafe Function ResetEvent Lib "kernel32" Alias "ResetEvent" (ByVal hEvent As LongPtr) As Long
Declare PtrSafe Function PulseEvent Lib "kernel32" Alias "PulseEvent" (ByVal hEvent As LongPtr) As Long
Declare PtrSafe Function ReleaseSemaphore Lib "kernel32" Alias "ReleaseSemaphore" (ByVal hSemaphore As LongPtr, ByVal lReleaseCount As Long, lpPreviousCount As Long) As Long
Declare PtrSafe Function ReleaseMutex Lib "kernel32" Alias "ReleaseMutex" (ByVal hMutex As LongPtr) As Long
Declare PtrSafe Function WaitForSingleObject Lib "kernel32" Alias "WaitForSingleObject" (ByVal hHandle As LongPtr, ByVal dwMilliseconds As Long) As Long
Declare PtrSafe Function WaitForMultipleObjects Lib "kernel32" Alias "WaitForMultipleObjects" (ByVal nCount As Long, lpHandles As LongPtr, ByVal bWaitAll As Long, ByVal dwMilliseconds As Long) As Long
Declare PtrSafe Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
Declare PtrSafe Sub OutputDebugString Lib "kernel32" Alias "OutputDebugStringA" (ByVal lpOutputString As String)
Declare PtrSafe Function GetVersion Lib "kernel32" Alias "GetVersion" () As Long
Declare PtrSafe Function OpenFile Lib "kernel32" Alias "OpenFile" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
' GetTempFileName() Flags
'
Const TF_FORCEDRIVE = &H80
Declare PtrSafe Function GetTempFileName Lib "kernel32" Alias "GetTempFileNameA" (ByVal lpszPath As String, ByVal lpPrefixString As String, ByVal wUnique As Long, ByVal lpTempFileName As String) As Long
Declare PtrSafe Function SetHandleCount Lib "kernel32" Alias "SetHandleCount" (ByVal wNumber As Long) As Long
Declare PtrSafe Function GetLogicalDrives Lib "kernel32" Alias "GetLogicalDrives" () As Long
Declare PtrSafe Function LockFile Lib "kernel32" Alias "LockFile" (ByVal hFile As LongPtr, ByVal dwFileOffsetLow As Long, ByVal dwFileOffsetHigh As Long, ByVal nNumberOfBytesToLockLow As Long, ByVal nNumberOfBytesToLockHigh As Long) As Long
Declare PtrSafe Function UnlockFile Lib "kernel32" Alias "UnlockFile" (ByVal hFile As LongPtr, ByVal dwFileOffsetLow As Long, ByVal dwFileOffsetHigh As Long, ByVal nNumberOfBytesToUnlockLow As Long, ByVal nNumberOfBytesToUnlockHigh As Long) As Long
Declare PtrSafe Function LockFileEx Lib "kernel32" Alias "LockFileEx" (ByVal hFile As LongPtr, ByVal dwFlags As Long, ByVal dwReserved As Long, ByVal nNumberOfBytesToLockLow As Long, ByVal nNumberOfBytesToLockHigh As Long, lpOverlapped As OVERLAPPED) As Long
Const LOCKFILE_FAIL_IMMEDIATELY = &H1
Const LOCKFILE_EXCLUSIVE_LOCK = &H2
Declare PtrSafe Function UnlockFileEx Lib "kernel32" Alias "UnlockFileEx" (ByVal hFile As LongPtr, ByVal dwReserved As Long, ByVal nNumberOfBytesToUnlockLow As Long, ByVal nNumberOfBytesToUnlockHigh As Long, lpOverlapped As OVERLAPPED) As Long
Type BY_HANDLE_FILE_INFORMATION
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
dwVolumeSerialNumber As Long
nFileSizeHigh As Long
nFileSizeLow As Long
nNumberOfLinks As Long
nFileIndexHigh As Long
nFileIndexLow As Long
End Type
Declare PtrSafe Function GetFileInformationByHandle Lib "kernel32" Alias "GetFileInformationByHandle" (ByVal hFile As LongPtr, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long
Declare PtrSafe Function GetFileType Lib "kernel32" Alias "GetFileType" (ByVal hFile As LongPtr) As Long
Declare PtrSafe Function GetFileSize Lib "kernel32" Alias "GetFileSize" (ByVal hFile As LongPtr, lpFileSizeHigh As Long) As Long
Declare PtrSafe Function GetStdHandle Lib "kernel32" Alias "GetStdHandle" (ByVal nStdHandle As Long) As LongPtr
Declare PtrSafe Function SetStdHandle Lib "kernel32" Alias "SetStdHandle" (ByVal nStdHandle As Long, ByVal nHandle As LongPtr) As Long
Declare PtrSafe Function WriteFile Lib "kernel32" Alias "WriteFile" (ByVal hFile As LongPtr, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, lpOverlapped As OVERLAPPED) As Long
Declare PtrSafe Function ReadFile Lib "kernel32" Alias "ReadFile" (ByVal hFile As LongPtr, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, lpOverlapped As OVERLAPPED) As Long
Declare PtrSafe Function FlushFileBuffers Lib "kernel32" Alias "FlushFileBuffers" (ByVal hFile As LongPtr) As Long
Declare PtrSafe Function DeviceIoControl Lib "kernel32" Alias "DeviceIoControl" (ByVal hDevice As LongPtr, ByVal dwIoControlCode As Long, lpInBuffer As Any, ByVal nInBufferSize As Long, lpOutBuffer As Any, ByVal nOutBufferSize As Long, lpBytesReturned As Long, lpOverlapped As OVERLAPPED) As Long
Declare PtrSafe Function SetEndOfFile Lib "kernel32" Alias "SetEndOfFile" (ByVal hFile As LongPtr) As Long
Declare PtrSafe Function SetFilePointer Lib "kernel32" Alias "SetFilePointer" (ByVal hFile As LongPtr, ByVal lDistanceToMove As Long, lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
Declare PtrSafe Function FindClose Lib "kernel32" Alias "FindClose" (ByVal hFindFile As LongPtr) As Long
Declare PtrSafe Function GetFileTime Lib "kernel32" Alias "GetFileTime" (ByVal hFile As LongPtr, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Declare PtrSafe Function SetFileTime Lib "kernel32" Alias "SetFileTime" (ByVal hFile As LongPtr, lpCreationTime As FILETIME, lpLastAccessTime As FILETIME, lpLastWriteTime As FILETIME) As Long
Declare PtrSafe Function CloseHandle Lib "kernel32" Alias "CloseHandle" (ByVal hObject As LongPtr) As Long
Declare PtrSafe Function DuplicateHandle Lib "kernel32" Alias "DuplicateHandle" (ByVal hSourceProcessHandle As LongPtr, ByVal hSourceHandle As LongPtr, ByVal hTargetProcessHandle As LongPtr, lpTargetHandle As LongPtr, ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwOptions As Long) As Long
我20多年的VBA實踐經驗,全部濃縮在下面的各個教程中: