IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Problème compatibilité 32bits et 64bits [XL-2010]


Sujet :

Macros et VBA Excel

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Par défaut Problème compatibilité 32bits et 64bits
    Bonjour à tous,

    Je me tourne vers vous car le problème ci-contre me chagrine depuis ce matin. En effet, je cherche à faire un code vba compatible 32 et 64 bits.
    Le souci est que je tombe sur une "erreur de compilation : incompatibilité de type" sur la procédure
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    AddressOf LowLevelMouseProc
    dans le Sub Hook_Mouse.

    Je ne comprends pas pourquoi? Pouvez-vous m'éclairer de vos lumières?

    Le bout de code sert à permettre l'exécution de la molette dans les combobox.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    '-----Allows use of MouseWheel on designated ListBox/ComboBox on a form or, sheet if modified.--------
    Option Explicit
     
    #If Win64 Then
        Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
                                    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
     
        Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
     
        Declare PtrSafe Function GetForegroundWindow Lib "user32" () As Long
     
        Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
                               (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
     
        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
     
        Declare PtrSafe Function CallNextHookEx Lib "user32" (ByVal hHook As Long, _
                                                      ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
     
        Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
     
        Declare PtrSafe Function GetLastError Lib "kernel32" () As Long  ' Used this one to crack the problem.
    #Else
        Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
                                    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
     
        Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
     
        Declare Function GetForegroundWindow Lib "user32" () As Long
     
        Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
                               (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
     
        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
     
        Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, _
                                                      ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
     
        Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
     
        Declare Function GetLastError Lib "kernel32" () As Long  ' Used this one to crack the problem.
    #End If
     
    Type POINTAPI
      X As Long
      Y As Long
    End Type
     
    Type MSLLHOOKSTRUCT  'Will Hold the lParam struct Data
      pt As POINTAPI
      mouseData As Long  ' Holds Forward\Bacward flag
      flags As Long
      time As Long
      dwExtraInfo As Long
    End Type
     
    Const HC_ACTION = 0
    Const WH_MOUSE_LL = 14
    Const WM_MOUSEWHEEL = &H20A
     
    Dim hhkLowLevelMouse, lngInitialColor As Long
    Dim udtlParamStuct As MSLLHOOKSTRUCT
     
    Public Const GWL_HINSTANCE = (-6)
    Public intTopIndex As Integer
    Public ObjUSF As UserForm, ObjList As Object
     
    Function GetHookStruct(ByVal lParam As Long) As MSLLHOOKSTRUCT
    ' VarPtr returns address; LenB returns size in bytes.
      CopyMemory VarPtr(udtlParamStuct), lParam, LenB(udtlParamStuct)
      GetHookStruct = udtlParamStuct
    End Function
     
    Function LowLevelMouseProc _
             (ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    'Avoid XL crashing if RunTime error occurs due to Mouse fast movement
      On Error Resume Next
      '    \\ Unhook & get out in case the application is deactivated
      If GetForegroundWindow <> FindWindow("ThunderDFrame", ObjUSF.Caption) Then
        UnHook_Mouse
        Exit Function
      End If
      If (nCode = HC_ACTION) Then
        If wParam = WM_MOUSEWHEEL Then
          '\\ Don't process Default WM_MOUSEWHEEL Window message
          LowLevelMouseProc = True
          '\\ Change Sheet&\DropDown names as required
          With ObjList
            '\\ if rolling forward increase Top index by 1 to cause an Up Scroll
            If GetHookStruct(lParam).mouseData > 0 Then
              .TopIndex = intTopIndex - 1
              '\\ Store new TopIndex value
              intTopIndex = .TopIndex
            Else  '\\ if rolling backward decrease Top index by 1 to cause _
                  '\\a Down Scroll
              .TopIndex = intTopIndex + 1
              '\\ Store new TopIndex value
              intTopIndex = .TopIndex
            End If
          End With
        End If
        Exit Function
      End If
      LowLevelMouseProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
    End Function
     
    Sub Hook_Mouse()
    ' Statement to maintain the handle of the hook if clicking outside of the control.
    ' There isn't a Hinstance for Application, so used GetWindowLong to get handle.
      If hhkLowLevelMouse < 1 Then hhkLowLevelMouse = SetWindowsHookEx(WH_MOUSE_LL, AddressOf LowLevelMouseProc, _
                                                                       GetWindowLong(FindWindow("ThunderDFrame", ObjUSF.Caption), GWL_HINSTANCE), 0)
    End Sub
     
    Sub UnHook_Mouse()
      If hhkLowLevelMouse <> 0 Then
        UnhookWindowsHookEx hhkLowLevelMouse
        hhkLowLevelMouse = 0
      End If
    End Sub
    Je vous remercie par avance pour votre aide et vous souhaite une très bonne année et pleins de bonnes choses, soit dit en passant.

    Cordialement,

    Anthony

  2. #2
    Membre Expert
    Homme Profil pro
    retraité
    Inscrit en
    Mars 2013
    Messages
    885
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2013
    Messages : 885
    Par défaut problème compatibilité 32 et 64bits
    bonsoir,

    regarde ceci tiré d'une discussion avec PatrickToulon.

    cette proposition est si ma mémoire ne me trahie pas de Nouveau2 (outre win64 il est fait état de VBA7). le résultat était pour le cas traité parfait.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
     
    ' Exemple de déclaration compatible avec 64 bit tiré du fichier "redimensionner userform.xlm"
    ' voir également pour formation le documet sur le net "compatibilité entre les version 64 bits et 32 bits sur d'office 2010"
    Option Explicit
    #If VBA7 Then
         ' api pour changer le mode d affichage du userform et activer ou non la fenetre
        Public Declare PtrSafe Function SWH Lib "user32" Alias "ShowWindow" (ByVal hwnd As LongPtr, ByVal nCmdShow As Long) As Long
         ' api pour changer le mode d affichage du userform et activer ou non la fenetre
        Public Declare PtrSafe Function SWA Lib "user32" Alias "ShowWindowAsync" (ByVal hwnd As LongPtr, ByVal nCmdShow As Long) As Long
         ' api pour redresser l'affichage en cas de modification de la caption
        Public Declare PtrSafe Function DMB Lib "user32" Alias "DrawMenuBar" (ByVal hwnd As LongPtr) As Long
          #If Win64 Then
             Public Declare PtrSafe Function SWLA Lib "user32" Alias "SetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
             Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
          #Else
             ' api pour trouver et identifier le handle de la fenetre (identifiant de la fenetre
             Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
             ' api pour appliquer le nouveau style a la fenetre (userform)
             Public Declare PtrSafe Function SWLA Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
          #End If
     
    #Else
         ' api pour trouver et identifier le handle de la fenetre (identifiant de la fenetre
        Public Declare Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
         ' api pour appliquer le nouveau style a la fenetre (userform)
        Public Declare Function SWLA Lib "User32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
         ' api pour redresser l'affichage en cas de modification de la caption
        Public Declare Function DMB Lib "User32" Alias "DrawMenuBar" (ByVal hWnd As Long) As Long
    #End If
    Cordialement,

  3. #3
    Membre émérite Avatar de issoram
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Janvier 2009
    Messages
    665
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Saône et Loire (Bourgogne)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Janvier 2009
    Messages : 665
    Par défaut
    Bonjour,

    Alors déjà la déclaration de SetWindowsHookEx est différente pour Office 64, ce qui génère ton erreur.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As LongPtr, ByVal hmod As LongPtr, ByVal dwThreadId As Long) As LongPtr
    Ensuite de manière générale, la déclaration des API est différente en Office 64. Donc tes autres déclarations sont certainement à revoir aussi.
    Je te renvoie à cet excellent tuto sur le sujet.

    Bonne journée et bonne année à toi aussi.

  4. #4
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Par défaut
    C'est bon j'ai réussi à trouver et faire un truc qui fonctionne bien sur 32 bits comme sur 64 bits.

    Si vous souhaitez le code, dites le moi.
    Par contre, pensez-vous qu'une double condition avec VBA7 soit nécessaire avec les api qui sont là?

    Je vous remercie pour votre aide et vous dit à bientôt.
    Bien cordialement,

    Anthony

  5. #5
    Membre Expert
    Homme Profil pro
    retraité
    Inscrit en
    Mars 2013
    Messages
    885
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2013
    Messages : 885
    Par défaut problème compatibilité 32 et 64bits
    Bonsoir,

    Il est toujours souhaitable avant de cliquer sur résolu de mettre sa solution qui peut profiter à d'autres et éviter également que ces autres posent inutilement la même question.

    Pour VBA7, je ne suis pas assez avancé pour affirmer sa nécessité mais je pense que si "Nouveau2" l'a inclus dans son code, c'est que cela doit avoir son utilité.

    Cordialement

  6. #6
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    39
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2011
    Messages : 39
    Par défaut
    Bonjour à tous,

    Désolé pour ne pas avoir posté ma réponse qui est la suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
     
    Option Explicit
     
    #If Win64 Then
        Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" _
                                    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
     
        Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
     
        Declare PtrSafe Function GetForegroundWindow Lib "user32" () As Long
     
        Declare PtrSafe Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
                               (ByVal Destination As LongPtr, ByVal Source As LongPtr, ByVal Length As LongPtr)
     
        Declare PtrSafe Function SetWindowsHookEx Lib _
                                          "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As LongPtr, _
                                                                              ByVal hmod As LongPtr, ByVal dwThreadId As Long) As LongPtr
     
        Declare PtrSafe Function CallNextHookEx Lib "user32" (ByVal hHook As Long, _
                                                      ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
     
        Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
     
        Declare PtrSafe Function GetLastError Lib "kernel32" () As Long  ' Used this one to crack the problem.
    #Else
        Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
                                    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
     
        Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
     
        Declare Function GetForegroundWindow Lib "user32" () As Long
     
        Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
                               (ByVal Destination As Long, ByVal Source As Long, ByVal Length As Long)
     
        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
     
        Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, _
                                                      ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
     
        Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
     
        Declare Function GetLastError Lib "kernel32" () As Long  ' Used this one to crack the problem.
    #End If
     
    Type POINTAPI
      X As Long
      Y As Long
    End Type
     
    Type MSLLHOOKSTRUCT  'Will Hold the lParam struct Data
      pt As POINTAPI
      mouseData As Long  ' Holds Forward\Bacward flag
      flags As Long
      time As Long
      dwExtraInfo As Long
    End Type
     
    Const HC_ACTION = 0
    Const WH_MOUSE_LL = 14
    Const WM_MOUSEWHEEL = &H20A
     
    #If Win64 Then
        Dim hhkLowLevelMouse, lngInitialColor As LongPtr
    #Else
        Dim hhkLowLevelMouse, lngInitialColor As Long
    #End If
     
     
    Dim udtlParamStuct As MSLLHOOKSTRUCT
     
    Public Const GWL_HINSTANCE = (-6)
    Public intTopIndex As Integer
    Public ObjUSF As UserForm, ObjList As Object
     
    Function GetHookStruct(ByVal lParam As Long) As MSLLHOOKSTRUCT
    ' VarPtr returns address; LenB returns size in bytes.
      CopyMemory VarPtr(udtlParamStuct), lParam, LenB(udtlParamStuct)
      GetHookStruct = udtlParamStuct
    End Function
     
    #If Win64 Then
        Function LowLevelMouseProc _
                 (ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As LongPtr
        'Avoid XL crashing if RunTime error occurs due to Mouse fast movement
          On Error Resume Next
          '    \\ Unhook & get out in case the application is deactivated
          If GetForegroundWindow <> FindWindow("ThunderDFrame", ObjUSF.Caption) Then
            UnHook_Mouse
            Exit Function
          End If
          If (nCode = HC_ACTION) Then
            If wParam = WM_MOUSEWHEEL Then
              '\\ Don't process Default WM_MOUSEWHEEL Window message
              LowLevelMouseProc = True
              '\\ Change Sheet&\DropDown names as required
              With ObjList
                '\\ if rolling forward increase Top index by 1 to cause an Up Scroll
                If GetHookStruct(lParam).mouseData > 0 Then
                  .TopIndex = intTopIndex - 1
                  '\\ Store new TopIndex value
                  intTopIndex = .TopIndex
                Else  '\\ if rolling backward decrease Top index by 1 to cause _
                      '\\a Down Scroll
                  .TopIndex = intTopIndex + 1
                  '\\ Store new TopIndex value
                  intTopIndex = .TopIndex
                End If
              End With
            End If
            Exit Function
          End If
          LowLevelMouseProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
        End Function
    #Else
        Function LowLevelMouseProc _
                 (ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        'Avoid XL crashing if RunTime error occurs due to Mouse fast movement
          On Error Resume Next
          '    \\ Unhook & get out in case the application is deactivated
          If GetForegroundWindow <> FindWindow("ThunderDFrame", ObjUSF.Caption) Then
            UnHook_Mouse
            Exit Function
          End If
          If (nCode = HC_ACTION) Then
            If wParam = WM_MOUSEWHEEL Then
              '\\ Don't process Default WM_MOUSEWHEEL Window message
              LowLevelMouseProc = True
              '\\ Change Sheet&\DropDown names as required
              With ObjList
                '\\ if rolling forward increase Top index by 1 to cause an Up Scroll
                If GetHookStruct(lParam).mouseData > 0 Then
                  .TopIndex = intTopIndex - 1
                  '\\ Store new TopIndex value
                  intTopIndex = .TopIndex
                Else  '\\ if rolling backward decrease Top index by 1 to cause _
                      '\\a Down Scroll
                  .TopIndex = intTopIndex + 1
                  '\\ Store new TopIndex value
                  intTopIndex = .TopIndex
                End If
              End With
            End If
            Exit Function
          End If
          LowLevelMouseProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
        End Function
    #End If
     
    Sub Hook_Mouse()
    ' Statement to maintain the handle of the hook if clicking outside of the control.
    ' There isn't a Hinstance for Application, so used GetWindowLong to get handle.
      If hhkLowLevelMouse < 1 Then hhkLowLevelMouse = SetWindowsHookEx(WH_MOUSE_LL, AddressOf LowLevelMouseProc, _
                                                                       GetWindowLong(FindWindow("ThunderDFrame", ObjUSF.Caption), GWL_HINSTANCE), 0)
    End Sub
     
    Sub UnHook_Mouse()
      If hhkLowLevelMouse <> 0 Then
        UnhookWindowsHookEx hhkLowLevelMouse
        hhkLowLevelMouse = 0
      End If
    End Sub
    J'ai donc reprsie ligne par ligne mon problème et j'ai résolu le problème en comprenant où étaient les incompatibilité de déclaration entre long et longptr.

    Par contre, je ne vois pas l'utilité du VBA7 car mon programme fonctionne aussi bien sur VBA6 que sur le 7, j'avais juste un souci entre le 32 et le 64 bits.

    Merci encore pour votre aide.

    Bien cordialement,

    Anthony

  7. #7
    Invité
    Invité(e)
    Par défaut
    Salut,

    Tu peux écrire directement une fonction commune comme suit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    #If Win64 Then
    Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
        Dim hHandleA As LongPtr
        Dim hHandleB As LongPtr
        Dim hHandleC As LongPtr
        Dim lpPointeurA As LongPtr
        Dim lpPointeurB As LongPtr
        Dim lpPointeurC As LongPtr
     
    #Else
    Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        Dim hHandleA As Long
        Dim hHandleB As Long
        Dim hHandleC As Long
        Dim lpPointeurA As Long
        Dim lpPointeurB As Long
        Dim lpPointeurC As Long
     
    #End If
     
        ' Code commun
        '[...]
        '[...]
        '[...]
     
    End Function

    ou alors

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    #If VBA7 Then
    Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
        Dim hHandleA As LongPtr
        Dim hHandleB As LongPtr
        Dim hHandleC As LongPtr
        Dim lpPointeurA As LongPtr
        Dim lpPointeurB As LongPtr
        Dim lpPointeurC As LongPtr
     
    #Else
    Function LowLevelMouseProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        Dim hHandleA As Long
        Dim hHandleB As Long
        Dim hHandleC As Long
        Dim lpPointeurA As Long
        Dim lpPointeurB As Long
        Dim lpPointeurC As Long
     
    #End If
     
        ' Code commun
        '[...]
        '[...]
        '[...]
     
    End Function

    Sinon, tous les Handle (retour de FindWindow, GetWindowLong etc... doivent être typé As LongPtr).
    Pour les déclarations, tu suivre la démarche. http://support.microsoft.com/kb/2030490

    @nibledispo,
    Je n'ai pas écrit ça par contre.
    ShowWindow et ShowWindowAsyn ont disparu de la déclaration pour ceux qui ont une versions antérieurs a office 2010. Il doit y avoir autant de fonctions dans les 2 branches #If si possible.


    P.S.: Ah si effectivement, j'ai retrouvé le post (http://www.developpez.net/forums/d13...m/#post7494373) et fait une erreur (oubli).

  8. #8
    Membre à l'essai
    Homme Profil pro
    retraité
    Inscrit en
    Novembre 2018
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loiret (Centre)

    Informations professionnelles :
    Activité : retraité

    Informations forums :
    Inscription : Novembre 2018
    Messages : 5
    Par défaut Problème compatibilité 32bits et 64bits
    Bonjour
    Je viens vers vous car j'ai aussi un problème de passage d'excel 2016 32 bits vers excel 2019 64bits.
    le message d’erreur suivant apparaît
    instruction incorrect à l’extérieur de la procédure

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    If lngCode < HC_ACTION Then
    Cette ligne en rouge fait partie du code suivant pour gérer le mot passe permettant d'ouvrir la fenêtre VBA de mon appli excel

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    'Module pour inputbox pour les mots de passe
    Option Explicit
    
    Private Declare PtrSafe Function CallNextHookEx Lib "user32" (ByVal hHook As LongPtr, ByVal nCode As LongPtr, ByVal wParam As LongPtr, lParam As Any) As LongPtr
    Private Declare PtrSafe Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As LongPtr
    Private Declare PtrSafe Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As LongPtr, ByVal lpfn As Long, ByVal hmod As LongPtr, _
    ByVal dwThreadId As LongPtr) As LongPtr
    Private Declare PtrSafe Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As LongPtr) As LongPtr
    Private Declare PtrSafe Function SendDlgItemMessage Lib "user32" Alias "SendDlgItemMessageA" (ByVal hDlg As LongPtr, ByVal nIDDlgItem As LongPtr, ByVal wMsg As LongPtr, _
    ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
    Private Declare PtrSafe Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hWnd As LongPtr, ByVal lpClassName As String, ByVal nMaxCount As LongPtr) As LongPtr
    Private Declare PtrSafe Function GetCurrentThreadId Lib "kernel32" () As LongPtr
    Private Const EM_SETPASSWORDCHAR = &HCC
    Private Const WH_CBT = 5
    Private Const HCBT_ACTIVATE = 5
    Private Const HC_ACTION = 0
    Private hHook As LongPtr
    
     Declare PtrSafe Function NewProc Lib "user32" (ByVal lngCode As LongPtr, ByVal wParam As LongPtr, ByVal lParam As LongPtr) As LongPtr
    Dim RetVal
    Dim strClassName As String, lngBuffer As LongPtr
    If lngCode < HC_ACTION Then
    NewProc = CallNextHookEx(hHook, lngCode, wParam, lParam)
    Exit Function
    End If
    strClassName = String$(256, " ")
    lngBuffer = 255
    If lngCode = HCBT_ACTIVATE Then
    RetVal = GetClassName(wParam, strClassName, lngBuffer)
    If Left$(strClassName, RetVal) = "#32770" Then
    SendDlgItemMessage wParam, &H1324, EM_SETPASSWORDCHAR, Asc("*"), &H0
    End If
    End If
    CallNextHookEx hHook, lngCode, wParam, lParam
    End Function
    
     Declare PtrSafe Function InputBox Lib "user32" (Prompt, Optional Title, Optional Default, Optional XPos, _
    Optional YPos, Optional HelpFile, Optional Context) As String
    Dim lngModHwnd As LongPtr, lngThreadID As LongPtr
    lngThreadID = GetCurrentThreadId
    lngModHwnd = GetModuleHandle(vbNullString)
    hHook = SetWindowsHookEx(WH_CBT, AddressOf NewProc, lngModHwnd, lngThreadID)
    InputBox = InputBox(Prompt, Title, Default, XPos, YPos, HelpFile, Context)
    UnhookWindowsHookEx hHook
    End Function
    Merci d'avance pour votre aide.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2003] Problème de compatibilité 32bits-64bits
    Par mathspountz dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 30/06/2014, 17h33
  2. [10g] Problème ODBC 32bits/64bits
    Par Icchi dans le forum Connexions aux bases de données
    Réponses: 1
    Dernier message: 29/07/2013, 14h41
  3. [Toutes versions] Excel & Mscomctl : pb compatibilité 32Bits vs 64Bits
    Par Rikky13 dans le forum Excel
    Réponses: 13
    Dernier message: 28/06/2013, 21h19
  4. Réponses: 2
    Dernier message: 05/10/2010, 15h59
  5. Compatibilité des dump 32bits et 64bits
    Par matta dans le forum Adaptive Server Enterprise
    Réponses: 2
    Dernier message: 02/06/2010, 11h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo