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

C# Discussion :

Importatation de dll c++ en c#


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 40
    Par défaut Importatation de dll c++ en c#
    Bonjour

    Voila j'ai une dll en c++ que je dois utilisé dans un projet en c# et donc j'essai d'importer les fonctions avec

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
    Le probleme certaine type de variable ne marche pas en c# donc je suis coincé (toute avec la meme erreur : L es pointeurs et les mémoires tampons de taille fixe ne peuvent être utilisés que dans un contexte unsafe)

    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
    using System;
    using System.Collections.Generic;
    using System.Management; // need to add System.Management to your project references.
    using System.Runtime.InteropServices;
    
    namespace ConsoleApplication1
    {
        class PlatformInvokeTest
        {
            ushort HP45E_RESOLUTION;
            ushort HP45E_TRIGGER_OFFSET;
            ushort HP45E_AUX_OUTPUT;
            ushort HP45E_QUEUE_DEPTH;
            ushort HP45E_SUB_SAMPLE;
            ushort HP45E_JET_MASKING;
            ushort HP45E_HEAD_HEIGHT;
            public struct HP45E_CARTRIDGE_PROFILE_STRUCT
            {
                ushort voltage; // cartridge voltage, 0.1 volt units, Range 70 to 112 (7.0 to 11.2)
                ushort pulseWidth; // pulse width, 0.1 microsecond units, Range 19 to 25 (1.9 to 2.5)
                ushort temperature; // degrees C, Range 30 to 70
            }
            public struct HP45E_CONFIGURATION
            {
                ushort VerticalResolutionDPI; // printhead resolution
                ushort HorizontalResolutionDPI; // transport resolution
                ushort NumberOfPrintheads; // up to 4 printheads may be attached
                ushort Head1Height; // height of each printhead in pixels
                ushort Head2Height;
                ushort Head3Height;
                ushort Head4Height;
             };
    
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern bool HP45E_ProbePrinter(ushort index,
                List<char>PrinterName);
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern HandleCollector HP45E_OpenPrinter( List<char>PrinterName,
                List<HP45E_CONFIGURATION> pPrinterConfig);
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern void HP45E_ClosePrinter(int PrinterHandle);
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_GetPrinterParameter(HandleCollector PrinterHandle,
                ushort ParameterIndex,
                void *pParameter,
                ushort HeadNumber = 0);
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_SetPrinterParameter(HandleCollector PrinterHandle,
                ushort ParameterIndex,
                void *pParameter,
                ushort HeadNumber = 0);
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_PrintDocumentPage( HandleCollector PrinterHandle,
                ulong HorizontalWidth, // in pixels
               List<ulong> pBitmappedBuffer, // 1-bit per pixel image
                ulong Head1Offset, // Vertical offset in pixels
                ulong Head2Offset, // Vertical offset in pixels
                ulong Head3Offset, // Vertical offset in pixels
                ulong Head4Offset, // Vertical offset in pixels
                ulong Timeout ); // timeout in msecs
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_CanvasBegin( HandleCollector PrinterHandle, // as returned from open call
                ulong VerticalHeight, // in pixels
                ulong HorizontalWidth); // in pixels
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_CanvasWrite( HandleCollector PrinterHandle, // as returned from open call
                ulong VerticalOffset, // in pixels
                ulong HorizontalOffset,// in pixels
                ulong VerticalHeight, // in pixels
                ulong HorizontalWidth, // in pixels
                List <char> pBitmappedBuffer); // 1-bit per pixel image
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]        
            public static extern HandleCollector HP45E_LoadFontXFT( HandleCollector PrinterHandle, // as returned from open call
                List <char> filename); // full pathname to XFT font file
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_CanvasWriteStr( HandleCollector PrinterHandle, // as returned from open call
                HandleCollector FontHandle, // as returned from HP45E_LoadFont
                List <char> printString, // pointer to string to print
                ulong VerticalOffset, // in pixels
                ulong HorizontalOffset); // in pixels
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_CanvasPrint ( HandleCollector PrinterHandle, // as returned from open call
                ulong Head1Offset, // Vertical offset in pixels
                ulong Head2Offset, // Vertical offset in pixels
                ulong Head3Offset, // Vertical offset in pixels
                ulong Head4Offset, // Vertical offset in pixels
                ulong Timeout ); // timeout in msecs
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_CanvasPrintExt2 ( HandleCollector PrinterHandle, // as returned from open call
                ulong Head1Offset, // Vertical offset in pixels
                ulong Head2Offset, // Vertical offset in pixels
                ulong Head3Offset, // Vertical offset in pixels
                ulong Head4Offset, // Vertical offset in pixels
                ulong Timeout, // timeout in msecs
               List<float> pTransportSpeedIPS); // Returned transport speed
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_WaitForPrintComplete( HandleCollector PrinterHandle, // as returned from open call
                ulong Timeout); // Timeout in msecs
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern void HP45E_Reset( HandleCollector PrinterHandle );
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern void HP45E_ResetPrintData(HandleCollector PrinterHandle );
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern void HP45E_ResetPrintQueue(HandleCollector PrinterHandle );
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_GetStatus( HandleCollector PrinterHandle, // as returned from open call
               List <char> pStatusMessage); // returned text message
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_ActivatePens( HandleCollector PrinterHandle );
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_DeactivatePens( HandleCollector PrinterHandle );
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_SelectPens( HandleCollector PrinterHandle, // as returned from open call
                ulong bmPensSelect ); // bit mapped pens selector
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_GetInkRemaining( HandleCollector PrinterHandle, // as returned from open call
                ushort headIndex, // zero-based index of head number
                List<short>remainingPen1, // returned SHORT
                List<short>remainingPen2,
                List<short>remainingPen3,
                List<short>remainingPen4 );List<short>
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_ResetInkCartridge( HandleCollector PrinterHandle, // as returned from open call
                ushort headIndex, // zero-based index of head number
                ushort penIndex); // zero-based index of pen number
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern int HP45E_QueueOutputToggle( HandleCollector PrinterHandle, // as returned from open call
                ushort headIndex, // zero-based index of head number
                ushort outputBitmask, // bit 0 = new state of output
                ushort toggleTimeMS, // time in milliseconds (0=permanent)
                ushort syncOption = 0, // 0 = immediate
                ushort syncDelay = 0 ); // synchronize delay (time or distance)
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern FILETIME* HP45E_OpenLogFile( List<char>filename); // filename including full path;
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern void HP45E_CloseLogFile( );
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern ulong HP45E_TestUSB( HandleCollector PrinterHandle); // as returned from open call
            [DllImport("C:/Users/Eren/Desktop/XIJET_API.dll")]
            public static extern double HP45E_GetVersionAPI( );
            public static void Main()
            {
                HP45E_GetVersionAPI();
            }
        }
    }
    Quelqu'un à une idée de comment le résoudre?
    J'ai trouvé ce lien mais malheureusement je ne le comprend pas trop

    http://msdn.microsoft.com/fr-fr/libr...vs.110%29.aspx

    Autre question j'ai remplacé HANDLE par HandleCollector, est ce bon?
    De meme pour FILE par FileTime

    PJ. La documentaiton constructeur

    N.B. ma coloration bug désolé que je met [code] ou [code=c#]
    Images attachées Images attachées

  2. #2
    Membre averti
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    40
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 40
    Par défaut
    UP Edit (merci)

Discussions similaires

  1. [CR] Infos sur l'utilisation de dll
    Par step dans le forum SAP Crystal Reports
    Réponses: 11
    Dernier message: 09/08/2002, 11h35
  2. Declarer une dll Delphi ?
    Par DelphiCool dans le forum C++Builder
    Réponses: 2
    Dernier message: 26/07/2002, 10h07
  3. Débug de DLL
    Par Bayard dans le forum C++Builder
    Réponses: 3
    Dernier message: 22/07/2002, 15h08
  4. Equivalent à ExeName pour une DLL
    Par Smortex dans le forum Langage
    Réponses: 7
    Dernier message: 16/07/2002, 21h07
  5. Réponses: 2
    Dernier message: 20/03/2002, 23h01

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