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

VB.NET Discussion :

Problème Migration class .NET 3.5 en 4 > EZTW32.DLL


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Mars 2009
    Messages
    87
    Détails du profil
    Informations forums :
    Inscription : Mars 2009
    Messages : 87
    Par défaut
    Bonjour à tous,

    J'ai récemment eu besoin de migrer la classe ci dessous de .NET 3.5 ver 4 mais je rencontre le problème suivant à l'exécution.
    En l'état, le code fonctionne parfaitement sous 3.5.

    Erreur
    Un appel à la fonction PInvoke 'Scan dotnet!WindowsApplication1.Scanner::TWAIN_OpenSourceManager' a déséquilibré la pile. Cela peut se produire, car la signature PInvoke managée ne correspond pas à la signature cible non managée. Vérifiez que la convention d'appel et les paramètres de la signature PInvoke correspondent à la signature non managée cible.
    Class
    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
    Public Class Scanner
     
        Declare Function TWAIN_AcquireToClipboard Lib "EZTW32.DLL" (ByVal hwndApp&, ByVal wPixTypes&) As Integer
        Declare Function TWAIN_SetHideUI Lib "Eztw32.dll" Alias "TWAIN_SetHideUI" (ByVal ui As Long) As Long
        Declare Function TWAIN_OpenDefaultSource Lib "Eztw32.DLL" Alias "TWAIN_OpenDefaultSource" (ByVal hwnd As Long) As Integer
        Declare Function TWAIN_SetCurrentResolution Lib "Eztw32.dll" Alias "TWAIN_SetCurrentResolution" (ByVal neufdix As Double) As Long
        Declare Function TWAIN_SetCurrentPixelType Lib "Eztw32.dll" Alias "TWAIN_SetCurrentPixelType" (ByVal deux As Long) As Long
        Declare Function TWAIN_LoadSourceManager Lib "Eztw32.dll" Alias "TWAIN_LoadSourceManager" () As Long
        Declare Function TWAIN_SetCurrentUnits Lib "Eztw32.dll" Alias "TWAIN_SetCurrentUnits" (ByVal zero As Long) As Long
        Declare Function TWAIN_SetBitDepth Lib "Eztw32.dll" Alias "TWAIN_SetBitDepth" (ByVal zero As Long) As Long
        Declare Function TWAIN_OpenSourceManager Lib "EZTW32.DLL" Alias "TWAIN_OpenSourceManager" (ByVal hwnd As Long) As Long
        Declare Function TWAIN_CloseSource Lib "EZTW32.DLL" Alias "TWAIN_CloseSource" () As Long
        Declare Function TWAIN_SelectImageSource Lib "EZTW32.DLL" Alias "TWAIN_SelectImageSource" (ByVal hwnd As Long) As Integer
        Declare Function TWAIN_State Lib "EZTW32.DLL" Alias "TWAIN_State" () As Integer
     
        Declare Function TWAIN_AcquireToFilename Lib "Eztwain3.dll" (ByVal hwndApp As Long, ByVal sFile As String) As Long
        Declare Function TWAIN_SelectFeeder Lib "EZTW32.DLL" (ByVal fYes As Long) As Long
        Declare Function TWAIN_SetCurrentResolution Lib "EZTW32.DLL" (ByVal nRes As Long) As Long
     
        Declare Function TWAIN_LogFile Lib "EZTW32.DLL" (ByVal fLog As Long) As Long
        Declare Function TWAIN_SetAutoScan Lib "EZTW32.DLL" (ByVal fYes As Long) As Long
        Declare Function TWAIN_SetRegion Lib "EZTW32.DLL" (ByVal L As Double, ByVal T As Double, ByVal R As Double, ByVal B As Double) As Long
     
        Declare Function TWAIN_AcquireMultipageFile Lib "EZTW32.DLL" (ByVal hwndApp As Long, ByVal FileName As String) As Long
        Declare Function TWAIN_LastErrorCode Lib "EZTW32.DLL" () As Long
        Declare Function TWAIN_ReportLastError Lib "EZTW32.DLL" (ByVal pzMsg As String) As Long
     
        Declare Function TWAIN_GetCurrentResolution Lib "EZTW32.DLL" () As Long
     
     
        Dim THdl As Integer = 0
     
        Public Sub New(ByVal Hdl As Integer)
            THdl = Hdl
        End Sub
     
        ''' <summary>
        ''' récupération du résultat du scan
        ''' </summary>
        Public Function Scan() As Drawing.Image
     
     
            Dim Img As Drawing.Image = Nothing
            Try
     
                Dim Ret As Integer = 0
     
                'Paramètre du Scan
                If TWAIN_State() < 4 Then
                    MsgBox("Impossible de paramêtrer le scanner", MsgBoxStyle.Exclamation)
                Else
                    'parametres du scanner
                    TWAIN_SetCurrentUnits(0) 'DPI
                    TWAIN_SetCurrentResolution(600) 'en points par pouces
                    TWAIN_SetCurrentPixelType(2) ' Scan format 0 = B&W, 1 Grey, 2 RGB
                    TWAIN_SetBitDepth(8) ' Bit Depth 1, 2, 4, 8 but depends on Pixeltype
                    TWAIN_SetHideUI(1)
                End If
     
                'scan du document
                Ret = TWAIN_AcquireToClipboard(THdl, 32)
                Img = CType(Clipboard.GetDataObject.GetData(System.Windows.Forms.DataFormats.Bitmap), Bitmap)
     
            Catch ex As Exception
                Img = Nothing
            End Try
     
            Return Img
     
        End Function
        Public Sub ChoixScan()
     
            Try
     
                Dim Ret As Integer = 0
                'Fermeture de la source du scan
                TWAIN_CloseSource()
                TWAIN_LoadSourceManager()
                TWAIN_OpenSourceManager(THdl)
     
                Ret = TWAIN_SelectImageSource(THdl)
                If Ret = 1 Then
                    Ret = TWAIN_OpenDefaultSource(THdl)
                End If
     
                If TWAIN_State() < 4 Then
                    MsgBox("Impossible de paramêtrer le scanner", MsgBoxStyle.Exclamation)
                Else
                    'parametres du scanner
                    TWAIN_SetCurrentUnits(0) 'DPI
                    TWAIN_SetCurrentResolution(150) 'en points par pouces
                    TWAIN_SetCurrentPixelType(2) ' Scan format 0 = B&W, 1 Grey, 2 RGB
                    TWAIN_SetBitDepth(8) ' Bit Depth 1, 2, 4, 8 but depends on Pixeltype
                    TWAIN_SetHideUI(1)
                End If
     
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
     
        End Sub
     
        Public Sub Test()
     
            '************************************************
            'TWAIN_SetContrast (8) 
            'TWAIN_SetBrightness (8)
            'TWAIN_SetThreshold (8)
            'TWAIN_SetGamma (8)
            'TWAIN_SetShadow (8)
            'TWAIN_SetHighlight (8)
            '************************************************
     
            Dim TypDoc As Integer = 0
            TypDoc = 0  'Noir et Blanc
            TypDoc = 1  'Nuance de gris
            TypDoc = 2  'Couleur
     
            Dim Bit As Integer = 0
            Bit = 1  'Noir et Blanc
            Bit = 8  'Nuance de gris
            Bit = 8  'Couleur
     
            Dim fileName As String
            fileName = "D:\SCAN_DOC.pdf"
            'TWAIN_LogFile(1)
            TWAIN_SetHideUI(1)  'Cache l'interface utilisateur
            If TWAIN_OpenDefaultSource(THdl) = 1 Then
                'Call TWAIN_SelectFeeder(1)
     
                Dim Ret As Integer = TWAIN_GetCurrentResolution
     
                TWAIN_SetCurrentPixelType(TypDoc)
                TWAIN_SetBitDepth(Bit)
                TWAIN_SetCurrentResolution(Ret)
                'Call TWAIN_SetAutoScan(1)
                'Call TWAIN_SetRegion(0, 5, 3, 7)
                TWAIN_AcquireToClipboard(THdl, 32)
                'TWAIN_AcquireMultipageFile(THdl, fileName)
            End If
            'If TWAIN_LastErrorCode() <> 0 Then
            '    TWAIN_ReportLastError("Unable to scan.")
            'End If
     
            MsgBox("fin")
     
        End Sub
     
     
    End Class
    Merci pour votre aide

    Peut être un avis sur le message d'erreur.

    Cela peut se produire, car la signature PInvoke managée ne correspond pas à la signature cible non managée. Vérifiez que la convention d'appel et les paramètres de la signature PInvoke correspondent à la signature non managée cible.

  2. #2
    Inactif  
    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Janvier 2007
    Messages
    6 604
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet NTIC

    Informations forums :
    Inscription : Janvier 2007
    Messages : 6 604
    Par défaut
    Bonjour

    Tu n'as pas changé de mode 32 vers 64 bits par hasard ?

  3. #3
    Membre confirmé
    Inscrit en
    Mars 2009
    Messages
    87
    Détails du profil
    Informations forums :
    Inscription : Mars 2009
    Messages : 87
    Par défaut
    Bonjour,

    Je crois pas. J'ai juste changer la version du framework dans Compiler sous VS2010.

  4. #4
    Membre Expert

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2010
    Messages
    2 067
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Novembre 2010
    Messages : 2 067
    Par défaut
    pour la version du framework ne prend pas la v4 client profile mais l'autre v4 peut être et pour le cpu choisit AnyCpu

  5. #5
    Membre confirmé
    Inscrit en
    Mars 2009
    Messages
    87
    Détails du profil
    Informations forums :
    Inscription : Mars 2009
    Messages : 87
    Par défaut
    Bonjour,

    C'est déjà configurer de cette manière dans les options avancées de compilation.

  6. #6
    Inactif  
    Homme Profil pro
    Chef de projet NTIC
    Inscrit en
    Janvier 2007
    Messages
    6 604
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 64
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet NTIC

    Informations forums :
    Inscription : Janvier 2007
    Messages : 6 604
    Par défaut
    A tout hasard, normalise tes types de variables; par exemple,dans la fonction-ki-péte tu attends un Long et tu passes un Integer.

    Je ne sais comment VB.Net gère ça, mais il n'est pas impossible que le P/Invoke soit devenu chatouilleux là dessus.

    Tu compiles avec l'option STRICT (connais pas la syntaxe exact, n'utilisant pas VB.Net) ? si ce n'est pas le cas, je te suggère fortement de la mettre.

    Tu es sur que ton évolution de framework ne s'est accompagnée d'aucun changement de version de ta DLL Twain_* ?

  7. #7
    Membre éclairé
    Inscrit en
    Novembre 2006
    Messages
    257
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 257
    Par défaut Bonjour à tous!
    Je relance le sujet (VBA sur Access, il n'y a pas beaucoup de différence))car je n'arrive pas à faire choisir le Scanner par défaut quand il y en a plusieurs (un à plat et un à défilement) installés. Aucun ne se lance alors que le programme fonctionnait.
    Public Function AkTwain(akRes As Long, akType As Long, akChem, akdCon As Double)
    Dim hDIB As Long
    Dim hPal As Long
    Dim nPixTypes As Long
    Dim FileName As String
    Dim taskId As Integer
    Dim shellpar As String
    If Forms!Verrou!K2.Tag = "a" Then
    TWAIN_SetHideUI (0)
    Else
    TWAIN_SetHideUI (1)
    End If
    If (hPal <> 0) Then
    hPal = 0
    End If
    If (hDIB <> 0) Then
    TWAIN_FreeNative (hDIB)
    hDIB = 0
    End If
    If TWAIN_OpenDefaultSource() = 0 Then TWAIN_SelectImageSource (hDIB)
    If TWAIN_OpenDefaultSource() <> 0 Then
    TWAIN_SetCurrentResolution (akRes)
    TWAIN_NegotiatePixelTypes (akType)
    TWAIN_SetContrast (akdCon)
    hDIB = TWAIN_AcquireNative(0, 0)
    If Forms!Verrou!K2.Tag = "a" Then
    SendKeys "{Right}"
    Sleep (1000)
    SendKeys "{Enter}", False
    End If
    If hDIB <> 0 Then
    hPal = TWAIN_CreateDibPalette(hDIB)
    Else
    MsgBox "Aucune image n'a été scannée ou le transfert vers le fichier n'a pu se faire."
    Exit Function
    End If
    End If
    If hDIB <> 0 Then
    If TWAIN_WriteNativeToFilename(hDIB, "c:\J.bmp") < -1 Then
    MsgBox "Erreur d'écriture du fichier - Le dossier a-t-il été créé??"
    End If
    End If
    End Function

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

Discussions similaires

  1. Problème de migration vers .NET 4.5
    Par abasourdix dans le forum ASP.NET
    Réponses: 4
    Dernier message: 06/02/2013, 11h52
  2. Problème de perfs après simple migration en .Net 2.0
    Par Ideal_Du_Gazeau dans le forum C#
    Réponses: 0
    Dernier message: 23/02/2010, 18h29
  3. Migration VB.NET - Problème de suppression de fichiers
    Par Satare dans le forum Windows Forms
    Réponses: 2
    Dernier message: 21/05/2008, 16h55
  4. problème de class en C++ .Net
    Par swo.line dans le forum C++
    Réponses: 6
    Dernier message: 17/04/2008, 22h48
  5. Problème de migration asp.net 1.1 -> asp.net 2.0
    Par Avatarr dans le forum ASP.NET
    Réponses: 1
    Dernier message: 11/12/2007, 10h13

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