"What is the correct way to define the API functions?"
As stated previously, change all "Long" to "Integer".
For example, the first one of:
Public Declare Function CryptAcquireContext Lib "advapi32.dll" Alias "CryptAcquireContextA" ( _
phProv As Long, ByVal pszContainer As Long, ByVal pszProvider As String, _
ByVal dwProvType As Long, ByVal dwFlags As Long) As Long
Becomes this:
Public Declare Function CryptAcquireContext Lib "advapi32.dll" Alias "CryptAcquireContextA" ( _
phProv As Integer, ByVal pszContainer As Integer, ByVal pszProvider As String, _
ByVal dwProvType As Integer, ByVal dwFlags As Integer) As Integer
Be sure to change the local variables as well!
So this line:
Dim lHExchgKey As Long
Would become:
Dim lHExchgKey As Integer