Comment utiliser une DLL C++ dans Delphi 7

esquiro27 Messages postés 2 Date d'inscription jeudi 5 juin 2008 Statut Membre Dernière intervention 11 février 2012 - 11 févr. 2012 à 16:04
cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 - 13 févr. 2012 à 09:33
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 à convertir le code C++ fourni comme exemple en Delphi...

j'ai essayé quelques trucs mais en vain!!!

voici une description fournie avec la DLL:


[b]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 /////////////////////////////////b



Merci d'avance

3 réponses

cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
11 févr. 2012 à 17:30
Salut,

On peut voire ton essaie de traduction ?
Sauf erreur, la déclaration des fonctions devrait ressembler à ça :

function DBFtoDBF_Converter(hwnd: HWND; argc: Integer; argv: Array of String): Integer; stdcall; external 'toto.dll';
0
esquiro27 Messages postés 2 Date d'inscription jeudi 5 juin 2008 Statut Membre Dernière intervention 11 février 2012
11 févr. 2012 à 18:07
Merci pour ta réponse
voici mon code:

/////////////////////////////////////////
var
Form1: TForm1;
function DBFtoDBF_ConverterStr(hwn:HWND; params: pchar): Integer; stdcall; external 'dbf2dbf_d.dll';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var str:string;
begin

str:='CTT.dbf#BON.dbf#/overwrite=1#/SKIPDEL=1#/dBase3';
DBFtoDBF_ConverterStr(0,PChar(Str));

end;
/////////////////////////////////////////

au moment de l’exécution ce message d'erreur s'affiche:

access violation at adresse 1000B924 in module 'dbf2dbf_d.dll'. Write of address 0044F093

Merci pour votre aide
0
cs_rt15 Messages postés 3874 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 7 novembre 2014 13
13 févr. 2012 à 09:33
Ton code paraît tout à fait correct...

A tout hasard, tu as essayé l'autre fonction ?

function DBFtoDBF_Converter(hwnd: HWND; argc: Integer; argv: Array of PChar): Integer; stdcall; external 'dbf2dbf_d.dll';

...

procedure TForm1.Button1Click(Sender: TObject);
var
  lpArgv: Array[0..5] of PChar;
begin
  lpArgv[0]:= 'dbf2dbf';
  lpArgv[1]:= 'CTT.dbf';
  lpArgv[2]:= 'BON.dbf';
  lpArgv[3]:= '/overwrite=1';
  lpArgv[4]:= '/SKIPDEL=1';
  lpArgv[5]:= '/dBase3';
  DBFtoDBF_Converter(0, 6, lpArgv);
end;
0
Rejoignez-nous