Bonjour à tous,

j'ai un soucis avec un passage de paramètre PChar à une DLL (une dll maison).

Voici l'appel de la DLL:
Code DELPHI : 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
procedure Dll_ExcelToCSV(sCheminFicXl, sCheminFicCsv : string; fsFormAttente : TForm);
var
   MaDLL   : THandle;
   sCheminDll : string;
   MaProcedure : procedure (sCheminFicExcel, sCheminFicCSV: PChar;
                                       fsFormAttente : TForm;
                                       sSeparateur   : PChar = PChar(';');
                                       bTerminerParUnSeparateur : boolean = False;
                                       bPrendreEnComptePremiereLigne: boolean = False;
                                       bSeparateurSurLaPremiereLigne: boolean = True);
begin
   sCheminDll := Dll_TabXl;
   sCheminDll := sCheminApplication + sCheminDll;
   MaDLL      := yLoadLibrary(PChar(sCheminDll));
   if MaDLL = 0 then
      raise Exception.Create('Le fichier ' + sDll_TabXl + ' est introuvable.');
   @MaProcedure := GetProcAddress(MaDLL, 'ExcelToCsv');
   if @MaProcedure = nil then
      raise Exception.Create('Le fichier ' + sDll_TabXl + ' ne contient pas la fonction demandée.');
   try
      MaProcedure(PChar(sCheminFicXl), PCHAR(sCheminFicCsv), fsFormAttente, PChar(';'), False, False, True);
   finally
      FreeLibrary(MaDLL);
   end;
end;

Et voici la fonction dans la DLL:
Code DELPHI : 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
procedure ExcelToCsv(sCheminFicExcel, sCheminFicCSV: PChar;
                        fsFormAttente : TForm;
                        sSeparateur   : PChar = PChar(';');
                        bTerminerParUnSeparateur : boolean = False;
                        bPrendreEnComptePremiereLigne: boolean = False;
                        bSeparateurSurLaPremiereLigne: boolean = True);
var
sl : TStringList;
iLigne, iCol, iMax_col : integer;
s:string;
sMonSeparateur : string;
begin
//   showmessage('trace toto');
   try
      Application.ProcessMessages;
      Application.CreateForm(TmdTabXl, mdTabXl);
      CoInitialize(nil);
      lcidExcel := GetUserDefaultLCID;
      mdTabXl.EaModeleTabXl.Visible[lcidExcel] := True;
      if Assigned(fsFormAttente) then
         fsFormAttente.BringToFront;
      Application.ProcessMessages;
      mdTabXl.EaModeleTabXl.DisplayAlerts[lcidExcel] := False;
      mdTabXl.EaModeleTabXl.Connect;
      mdTabXl.EwbModeleTabXl.ConnectTo(mdTabXl.EaModeleTabXl.Workbooks.Open(VerifValiditePath(sCheminFicExcel),
              emptyparam, emptyparam, emptyparam, emptyparam,
              emptyparam, emptyparam, emptyparam, emptyparam,
              emptyparam, emptyparam, emptyparam, emptyparam,
              lcidExcel));
      mdTabXl.EwsModeleTabXl.ConnectTo(mdTabXl.EwbModeleTabXl.Worksheets[1] as _Worksheet);
      if FileExists(VerifValiditePath(sCheminFicCSV)) then
         if not MessageDlg('Le fichier ' + sCheminFicCSV + ' existe déjà. Voulez vous le remplacer ?', mtWarning, [mbYes, mbNo], 0) = mrYes then
         begin
            MessageDlg('Opération abandonnée', mtInformation, [mbOK], 0);
            exit;
         end;
      //initialisation de variable
      sl := TStringList.Create;
      iLigne    := 1;
      iCol      := 1;
      iMax_col  := 0;
      //détermination du nombre de colonnes
      while trim(mdTabXl.EwsModeleTabXl.Cells.Item[iLigne,iCol]) <> '' do
      begin
         inc(iMax_col);
         inc(iCol);
      end;
      //on parcours le fichier excel
      if not bPrendreEnComptePremiereLigne then
         iLigne := 2;
      //s := StrPas(sSeparateur);
      sMonSeparateur := ';' ;
      if bSeparateurSurLaPremiereLigne then
         sl.Append(sMonSeparateur);
      while trim(mdTabXl.EwsModeleTabXl.Cells.Item[iLigne,1]) <> '' do
      begin
         s := '';
         for iCol := 1 to iMax_col do
            s := s + mdTabXl.EwsModeleTabXl.Cells.Item[iLigne,iCol].Text + ifthen(iCol <> iMax_col, sMonSeparateur, ifthen(bTerminerParUnSeparateur, sMonSeparateur, ''));
         sl.Append(s);
         inc(iLigne);
      end;
      sl.SaveToFile(sCheminFicCSV);
      mdTabXl.EwbModeleTabXl.Close(True);
      mdTabXl.EaModeleTabXl.DisplayAlerts[lcidExcel] := True;
      mdTabXl.EaModeleTabXl.Quit;
   finally
      mdTabXl.EwsModeleTabXl.Disconnect;
      mdTabXl.EwbModeleTabXl.Disconnect;
      mdTabXl.EaModeleTabXl.Disconnect;
      if Assigned(mdTabXl) then
         FreeAndNil(mdTabXl);
   end;
 
end;

Le paramètre sSeparateur (initialisé à PChar(';') dans l'appel), je ne parviens pas à l'utiliser
si je vais
Code delphi : Sélectionner tout - Visualiser dans une fenêtre à part
s := sSeparateur;
j'ai une erreur d'accès à l'adresse XXXXXXXXX
idem si je fais:
Code delphi : Sélectionner tout - Visualiser dans une fenêtre à part
s := StrPas(sSeparateur);

PS: la bricole que j'ai fait avec sMonSeparateur, qui est une string, fonctionne. Sauf que je n'exploite pas le param de ma procédure.

Merci d'avance pour votre aide

juva