use AddressOf in VBA in win x64

8.5k views Asked by At

I use this program in winx86 without any error but when i try use it in win x64 my problems started. I use ptrsafe in my code to let me run in win 7 64bit, I'll add that this module have more code but for limitations of this site i had delete that. if need to now that lines of my code tell me to put them here. please help me and tell me Why my code produce an error:

'UDT for passing data through the hook
Private Type MSGBOX_HOOK_PARAMS
   hwndOwner   As Long
   hHook       As Long
End Type

Private MSGHOOK As MSGBOX_HOOK_PARAMS
#If VBA7 Then

    Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" _
       Alias "SetWindowsHookExA" _
      (ByVal idHook As Long, _
       ByVal lpfn As Long, _
       ByVal hmod As Long, _
       ByVal dwThreadId As Long) As Long
 #Else

    Private Declare Function SetWindowsHookEx Lib "user32" _
       Alias "SetWindowsHookExA" _
      (ByVal idHook As Long, _
       ByVal lpfn As Long, _
       ByVal hmod As Long, _
       ByVal dwThreadId As Long) As Long
#End If

Public Function MsgBoxHookProc(ByVal uMsg As Long, _
                               ByVal wParam As Long, _
                               ByVal lParam As Long) As Long

   If uMsg = HCBT_ACTIVATE Then

      SetDlgItemText wParam, vbYes, "بلـي"
      SetDlgItemText wParam, vbNo, "خـير"
      SetDlgItemText wParam, vbIgnore, "انصـراف"
      SetDlgItemText wParam, vbOK, "تـــاييد"

      UnhookWindowsHookEx MSGHOOK.hHook

   End If

   MsgBoxHookProc = False

End Function

Public Function MsgBoxFa(Prompt, Optional Buttons As VbMsgBoxStyle = vbOKOnly, Optional Tiltle = "", Optional HelpFile, Optional Context) As Long

  'Wrapper function for the MessageBox API
Dim hwndThreadOwner As Long
Dim frmCurrentForm As Form
Set frmCurrentForm = Screen.ActiveForm

hwndThreadOwner = frmCurrentForm.hwnd

   Dim hInstance As Long

   Dim hThreadId As Long
   Dim hwndOwner As Long
   hwndOwner = GetDesktopWindow()
   hInstance = GetWindowLong(hwndThreadOwner, GWL_HINSTANCE)
   hThreadId = GetCurrentThreadId()

   With MSGHOOK
      .hwndOwner = hwndOwner
'in next line the error produced******************************
      .hHook = SetWindowsHookEx(WH_CBT, _
                                AddressOf MsgBoxHookProc, _
                                hInstance, hThreadId)
   End With


 MsgBoxFa = MessageBox(hwndThreadOwner, Prompt, Tiltle, Buttons)

End Function
0

There are 0 answers