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

Langage Delphi Discussion :

Aide pour utiliser une DLL C++ dans D7


Sujet :

Langage Delphi

  1. #1
    Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Février 2012
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Bâtiment

    Informations forums :
    Inscription : Février 2012
    Messages : 3
    Points : 3
    Points
    3
    Par défaut Aide pour utiliser une DLL C++ dans D7
    Salut tout le monde!


    Je cherche à intégrer une DLL C++ dans mon application en D7, afin d'utiliser une fonction de conversion dont j'ai vraiment besoin!!!

    Mon PB c'est que je ne sais vraiment pas comment faire...

    et je n'arrive pas à translater le code fourni comme exemple en Delphi...

    voici une description fournie avec la DLL:


    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
    165
    166
    If you want to add a possibility to convert DBF files in your application
    you could use our library for this purpose.
     
    There are only two functions:
     
    int		DBFtoDBF_Converter(HWND hwnd, int argc, char *argv[]);
     
    	It accepts three parameters.
    	The first  "hwnd" must be NULL. It is not used.
    	The second "argc" must be equal to number of parameters.
    	The third  "argv" contains parameters.
     
    int		DBFtoDBF_ConverterStr(HWND hwnd, char *params);
     
    	It accepts two parameters.
    	The first  "hwnd" must be NULL. It is not used.
    	The second "params" contains parameters which are delimited with sign #, 
    	for example: source.dbf#target.dbf#/dBase3#/overwrite=1
     
    The functions return:
    	0 - success
    	1 - not recognized a source file
    	2 - not recognized a target file or folder
    	3 - cannot open one or more source dbf files
     
    Drive:\Path\FileName1.dbf   Source DBF file 
    Drive:\Path\FileName1.dbf   Target DBF file 
    Drive:\Path\                Target DBF folder
     
    /OVERWRITE=1                Overwrite existing file.  (default)
    /OVERWRITE=0                Do not overwrite existing file. (Append to existing file). 
     
    /SKIPDEL=1                  Skip records marked as deleted. 
    /SKIPDEL=0                  Do not skip records marked as deleted. 
     
    /RECALL=1                   Remove a deleteion mark from the output file.
    /RECALL=0                   Keep a deletion mark in the output file. (default)
     
    /DBASE3                     Convert to dBase III format. 
    /DBASE4                     Convert to dBase IV format. 
    /FOXPRO                     Convert to FoxPro format. 
    /VFP                        Convert to Visual FoxPro format. 
    /LEVEL7                     Convert to dBase Level 7 format. 
     
    /BLOCKSIZE=?????            Set blocksize for memo fields.
    Example:
    /BLOCKSIZE=128 
     
    /RECORDS=0                  Do not export records of the table.
     
        Output codepage
    /ASIS                       Codepage as is.  (default)
    /ANSI                       Convert to ANSI codepage. 
    /OEM                        Convert to OEM codepage. 
     
        Source codepage
    /SOURCE=ANSI
    /SOURCE=OEM
     
    /FILTER=condition           It allows you to convert records which satisfy the condition. 
     
    /CHANGETYPE:FIELD=TYPE(LENGTH,WIDTH)	
    							Set field type in the output file
     Example:							
      /CHANGETYPE:FIELDNAME1=N(10,2)
      /CHANGETYPE:FIELDNAME2=C(128)
      /CHANGETYPE:FIELDNAME3=D(8)
      /CHANGETYPE:FIELDNAME4=M
     
     
    ////////////////////// sample1.cpp ////////////////////////////
    //parameters in the command line
    //
    //sample1.exe source.dbf target.dbf ...
    //
     
    #include <windows.h>
     
    int __declspec(dllexport)   __stdcall   DBFtoDBF_Converter(HWND hwnd, int argc, char *argv[]);
     
     
    int
    main(int argc, char *argv[])
    {
        return DBFtoDBF_Converter(NULL, argc, argv);
    }
     
    //
    ////////////////////// sample1.cpp ////////////////////////////
     
     
     
    ////////////////////// sample2.cpp ////////////////////////////
    //parameters in the source code
    //
    //sample2.exe
    //
     
    #include <windows.h>
     
    int __declspec(dllexport)   __stdcall   DBFtoDBF_Converter(HWND hwnd, int argc, char *argv[]);
     
    int
    main()
    {
        int     n=0;
        char    *params[10];
     
        params[n++]=strdup(__argv[0]);
        params[n++]=strdup("source.dbf");
        params[n++]=strdup("target.dbf");
        params[n++]=strdup("/ansi");
        params[n++]=strdup("/overwrite=1");
     
        return DBFtoDBF_Converter(NULL, n, params);
    }
     
    //
    ////////////////////// sample2.cpp ////////////////////////////
     
    //////////////////////// net.cpp //////////////////////////////
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
     
    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            [DllImport("dbf2dbf_d.dll", CharSet = CharSet.Ansi)]
            
            static extern void DBFtoDBF_Converter(string hwnd, int argc, string[] argv);
     
            public Form1()
            {
                InitializeComponent();
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
     
                    int    n=6;
                    string[] parms = new string[] 
                    { 
                    "dbf2dbf", 
                    "/OVERWRITE=1", 
                    "/SKIPDEL=1", 
                    "/ASIS", 
                    "C:\\in.dbf", 
                    "C:\\out.dbf"
                    };
     
                    DBFtoDBF_Converter(null, n, parms);
            }
        }
    }
    /////////////////////// net.cpp ////////////////////////////////

    Merci d'avance

  2. #2
    Expert éminent sénior

    Avatar de Nono40
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2002
    Messages
    8 640
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 57
    Localisation : France, Loir et Cher (Centre)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2002
    Messages : 8 640
    Points : 19 104
    Points
    19 104
    Par défaut
    utilise la déclaration statique des dlls, le plus simple dans ton cas.

    Tu dois ajouter dans une unités la déclaration des procédures de la dll avec leur lien.

    Je te consille de n'utiliser que la seconde foncton, le Char *Argv[] (tableau de chaine à zéro terminal) va être une merde à utiliser en Delphi. La deuxième utilise une simple chaine ou tu ajoute des '#' pour séparer les lignes.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    // int __declspec(dllexport)   __stdcall   DBFtoDBF_ConverterStr(HWND hwnd, char *params);
    // Attention pour Delphi<=2007 c'est
      function DBFtoDBF_ConverterStr( hwnd:Thandle;params :PChar ):Integer; stdcall; external 'dbf2dbf_d.dll';
    // Attention pour Delphi>=2009 c'est
      function DBFtoDBF_ConverterStr( hwnd:Thandle;params :PAnsiChar ):Integer; stdcall; external 'dbf2dbf_d.dll';
    Pour sont utilisation, exemple :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    Var
      Chaine : String;
      Retour : Integer;
    Begin
      Chaine := 'source.dbf#target.dbf#/dBase3#/overwrite=1';
      Retour := DBFtoDBF_ConverterStr(0,PChar(Chaine));
      Case Retour Of
       0: //Ok
       //etc
      End;
    End;
    Je précise que je n'ai pas testé, mais vu la déclaration de la dll en C et son utilisation ça doit être comme cela;

Discussions similaires

  1. Aide pour utiliser une fonction dans un "case"
    Par lcoulon dans le forum Débuter
    Réponses: 2
    Dernier message: 15/10/2009, 22h17
  2. [COM] Comment utiliser une dll DotNet dans un projet win32 ?
    Par Marmottoc dans le forum API, COM et SDKs
    Réponses: 8
    Dernier message: 05/05/2006, 15h58
  3. [Langage]Comment utiliser une dll .NET dans VB6?
    Par BouB dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 13/04/2006, 14h20
  4. [JNI] Difficultés pour utiliser une DLL
    Par etiennegaloup dans le forum Entrée/Sortie
    Réponses: 10
    Dernier message: 15/08/2005, 21h29

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