From: Stephen Rasey on 24 Dec 2006 00:40
I have a user function that creates a hash value from the contents of a
range. It uses the CryptAcqureContext and CryptCreateHash functions in the
advapi32 library. These have worked splendidly on a WinXP SP2, Office 2003
system. They have worked on several other systems without trouble.
I have a new computer using Windows Media Center. I loaded Office 2003,
then Office 2007 keeping the Office 2003 applications.
The CryptAcquireContext function returns a zero in the hProv argument
instead of some non-zero long integer. This tells me that the reference to
Lib advapi32 is mixed up, or there is some incompatibility between this
function and Windows Media Center (which I have trouble believing).
I have un-installed Office 2007,
Repaired Office 2003 Prof.
CryptAcquireContext hProv, ..... hProv = 0. wrong.
Un-installed Office 2003.
Install Office 2003 Prof. Complete.
CryptAcquireContext hProv,.... hProv = 0. Still not working.
Version is the same as on the Winbook, WinXP SP2, Off 2003 where it works
it is located in the same place: C:\Windows\System32\advapi32.dll.
Additionally, my Outlook will not remember my email passwords.
My feeling is the registry is a mess at this point. Anyone recommend a
good registry clean-up tool?
I'm about to implement KB290301 "Windows installer cleanup utility" to try
and go after some registration issues.
"Stephen Rasey" <rasey66(a)wiserways.com> wrote in message
> 'a Hash Function from Stephen Bullen.
> 'From: Stephen Bullen (stephen(a)bmsltd.ie)
> 'Subject: Re: Hash (MD5) in Excel
> 'Newsgroups: microsoft.public.Excel.programming Date: 2004-02-05
> 12:50:20 PST
> 'Modified (bug fix) by Stephen Rasey June 2004
> Option Explicit
> Declare Function CryptAcquireContext Lib "advapi32" Alias
> "CryptAcquireContextA" (ByRef hProv As Long, ByVal sContainer As String, _
> ByVal sProvider As String, ByVal lProvType As Long, ByVal lFlags As
> Long) As Long
> Declare Function CryptCreateHash Lib "advapi32" (ByVal hProv As Long,
> lALG_ID As Long, _
> ByVal hKey As Long, ByVal
> lFlags As Long, ByRef hhash As Long) As Long
> Declare Function CryptHashData Lib "advapi32" (ByVal hhash As Long, ByVal
> lDataPtr As Long, ByVal lLen As Long, ByVal lFlags As Long) As Long
> Declare Function CryptGetHashParam Lib "advapi32" (ByVal hhash As Long,
> ByVal lParam As Long, ByVal sBuffer As String, _
> ByRef lLen As Long,
> lFlags As Long) As Long
> Declare Function CryptDestroyHash Lib "advapi32" (ByVal hhash As Long) As
> Declare Function CryptReleaseContext Lib "advapi32" (ByVal hProv As Long,
> ByVal lFlags As Long) As Long
> Const MS_DEF_PROV = "Microsoft Base Cryptographic Provider v1.0"
> Const PROV_RSA_FULL As Long = 1
> Const CRYPT_NEWKEYSET As Long = 8
> Const CALG_MD5 As Long = 32771
> Const HP_HASHVAL As Long = 2
> ' wwGetMD5Hash - GetMD5Hash (written by Stephen Bullen) modified by
> Stephen Rasey 040612
> ' Changes: Use StrPtr and coerse all cell values to strings
> ' Empty cells are not ignored, but the cell number in the
> ' is used to generate more data for the hash
> Public Function wwGetMD5Hash(rngData As Range) As String
> Dim hProv As Long
> Dim hhash As Long
> Dim lLen As Long
> Dim ocell As Range
> Dim baData() As Byte
> Dim sBuffer As String
> Dim vValue As String
> Dim vU2 As Variant
> Dim lresult As Long
> Dim lcellCounter As Long
> On Error GoTo E1
> 'Get/create a cryptography context
> CryptAcquireContext hProv, vbNullString, MS_DEF_PROV, PROV_RSA_FULL, 0
> If hProv = 0 Then
> CryptAcquireContext hProv, vbNullString, MS_DEF_PROV,
> End If
> 'If we got one...
> If hProv <> 0 Then
> 'Create an MD5 Hash
> CryptCreateHash hProv, CALG_MD5, 0, 0, hhash
> 'If that was OK...
> If hhash <> 0 Then
> 'Fill it with the contents of the range
> (and it continues...)
> the full function can be found here:
> -Stephen Rasey
From: Stephen Rasey on 24 Dec 2006 12:25
The application runs fine on another computer running Media Center. So
there is no innate conflict between the CryptAcquireContext in lib
advapi32.dll and Media Center.
This Computer's windows installation appears hopelessly corrupted. I don't
know what happened. The only thing that I can blame is the installing of
Office 2003, then Office 2007 for a dual version Office Development Platform
caused all this grief. I don't know Office 2007 is the cause, but I don't
think I'll try it again anytime soon.