Link to home
Start Free TrialLog in
Avatar of David Smithstein
David SmithsteinFlag for United States of America

asked on

StrPtr doesn't compile in MS Access 2013 64 bit

I need some help adjusting some code to compile in both 64 and 32 bit Office environments.  The follow code works perfectly in the 32 bit world but not 64.  I figured out that I needed to PtrSafe all my declare statements, but this isn't in a declare statement so I'm not sure what I'm doing here.

The section of code is just for reference to show how the WindowsPassword function is being used.
If WindowPassword(Forms![Frm_ElectronicSignature]![Password2], Forms![Frm_ElectronicSignature]![Password2]) = True Then
    GoTo ApplySignature
Else
   GoTo PasswordFail
End If

Open in new window


This next section doesn't compile in 64 bit MS Access 2013, and I get the message "Compile Error - Type Mismatch" with StrPtr highlighted.

Public Function WindowPassword( _
     ByVal oldpw As String, _
     ByVal newpw As String, _
     Optional ByVal Username As String = vbNullString) As Boolean
    
     Dim NetRet As Long
         
     'If UserName not specified, _
         defaults to current user logged on.
     
    NetRet = NetUserChangePassword(0&, _
         StrPtr(Username), _
         StrPtr(oldpw), _
         StrPtr(newpw))
         
     Select Case NetRet
         Case NERR_SUCCESS
        
                WindowPassword = True
         Case INVALID_PASSWORD
          
                WindowPassword = False
          
         Case ACCESS_DENIED
                WindowPassword = False
           
     End Select
     
 End Function

Open in new window


I did enough research to get the idea that between 32 bit and 64 bit apps there is some issue about going between ANSI and UNICODE and something about a variable or a pointer overwriting the address next to it if it gets a 64 bit package for only a 32 bit address...or something like that....the reason behind "PtrSafe" no doubt.  Enough to know I'd better ask someone who knows more about it than I do.

Any help getting this to work in both environments would be deeply appreciated...

Thanks!
David
Avatar of John Tsioumpris
John Tsioumpris
Flag of Greece image

StrPrt on 64bit systems behaves  different then  x86

StrPtr String converter. Returns a LongPtr on 64-bit versions, and a Long on 32-bit versions (4 bytes).
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David Smithstein

ASKER

Thanks Jim, I appreciate the references, I guess I need to invest the time to make this a good solution, and not just a quick one.  :-)