Accueil > > > DLL ET PCHAR
DLL ET PCHAR
Information sur la source
Description
Exemple d'une dll avec 2 Pchar en entrée et renvoyant un pchar qui est la concaténation des 2 Pchar en entrée pour Delphi.
Source
- Tout d'abord la dll:
- library JprStr;
-
- { Important note about DLL memory management: ShareMem must be the
- first unit in your library's USES clause AND your project's (select
- Project-View Source) USES clause if your DLL exports any procedures or
- functions that pass strings as parameters or function results. This
- applies to all strings passed to and from your DLL--even those that
- are nested in records and classes. ShareMem is the interface unit to
- the BORLNDMM.DLL shared memory manager, which must be deployed along
- with your DLL. To avoid using BORLNDMM.DLL, pass string information
- using PChar or ShortString parameters. }
-
- uses
- SysUtils,
- Types,
- Classes;
-
- {$R *.res}
- {H+}
-
- function JpConcAt( Pstr1 : Pchar; Pstr2 : Pchar;Pstr3 : Pchar):Pchar;stdcall;
- var
- str1,str2,str3:string;
- i:integer;
- chaine: array[0..39] of char;
- begin
- str1:=Strpas(Pstr1);
- str2:=Strpas(Pstr2);
- str3:=str1 + str2;
- strPLcopy(Pstr3,str3,40); // transformation String -> PChar
-
- for i:=0 to 39 do
- chaine[i]:=str3[i+1];
- result:=@chaine;// renvoie un Pchar
-
-
- end;
-
- exports
- JpConcAt;
-
- begin
- end.
-
-
- maintenant l'appel à partir d'un form contenant 2 TEdit(les 2 chaines à concaténer), 1 Tbutton, 1 Tedit (Résultat):
- unit AppelJpStr;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
-
- type
- TFrmAppelJpStr = class(TForm)
- Edit1: TEdit;
- Edit2: TEdit;
- Button1: TButton;
- Edit3: TEdit;
-
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- FrmAppelJpStr: TFrmAppelJpStr;
-
-
- implementation
-
- function JpConcAt( Pstr1 : Pchar ;Pstr2 : Pchar;Pstr3 :Pchar):Pchar;stdcall;external '.\Jprstr.dll';
-
- {$R *.dfm}
-
- Procedure TFrmAppelJpStr.Button1Click(Sender: TObject);
- var
- Chaine1:array[0..19] of char;
- chaine2:array[0..19] of char;
- chaine3:array[0..39] of char;
- str1,str2,str3:string;
- i:Integer;
- Pstr1,Pstr:Pchar;
- Pstr2:Pchar;
- Pstr3:Pchar;
- begin
- str1:=edit1.Text;
- str2:=edit2.Text;
- str3:='';
- // initialisation Pstr1
- for i :=0 to length(str1) do
- chaine1[i]:= str1[i+1];
- Pstr1:=@chaine1;
- // initialisation Pstr2
- for i :=0 to length(str2) do
- chaine2[i]:= str2[i+1];
- Pstr2:=@chaine2;
- //réservation pour Pstr3
- Pstr3:=strAlloc(40);
- // appel library
- JpConcat(Pstr1,Pstr2,Pstr3);
- str3:=strpas(Pstr3);
- edit3.Text:= str3;
- end;
-
- Nota: si les passages Pchar->String ou String ->Pchar ne marchent pas (ca arrive...?), procédez Pchar->Array of Char ->String ou String -> Array Of Char -> Pchar
Tout d'abord la dll:
library JprStr;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
Types,
Classes;
{$R *.res}
{H+}
function JpConcAt( Pstr1 : Pchar; Pstr2 : Pchar;Pstr3 : Pchar):Pchar;stdcall;
var
str1,str2,str3:string;
i:integer;
chaine: array[0..39] of char;
begin
str1:=Strpas(Pstr1);
str2:=Strpas(Pstr2);
str3:=str1 + str2;
strPLcopy(Pstr3,str3,40); // transformation String -> PChar
for i:=0 to 39 do
chaine[i]:=str3[i+1];
result:=@chaine;// renvoie un Pchar
end;
exports
JpConcAt;
begin
end.
maintenant l'appel à partir d'un form contenant 2 TEdit(les 2 chaines à concaténer), 1 Tbutton, 1 Tedit (Résultat):
unit AppelJpStr;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TFrmAppelJpStr = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Edit3: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
FrmAppelJpStr: TFrmAppelJpStr;
implementation
function JpConcAt( Pstr1 : Pchar ;Pstr2 : Pchar;Pstr3 :Pchar):Pchar;stdcall;external '.\Jprstr.dll';
{$R *.dfm}
Procedure TFrmAppelJpStr.Button1Click(Sender: TObject);
var
Chaine1:array[0..19] of char;
chaine2:array[0..19] of char;
chaine3:array[0..39] of char;
str1,str2,str3:string;
i:Integer;
Pstr1,Pstr:Pchar;
Pstr2:Pchar;
Pstr3:Pchar;
begin
str1:=edit1.Text;
str2:=edit2.Text;
str3:='';
// initialisation Pstr1
for i :=0 to length(str1) do
chaine1[i]:= str1[i+1];
Pstr1:=@chaine1;
// initialisation Pstr2
for i :=0 to length(str2) do
chaine2[i]:= str2[i+1];
Pstr2:=@chaine2;
//réservation pour Pstr3
Pstr3:=strAlloc(40);
// appel library
JpConcat(Pstr1,Pstr2,Pstr3);
str3:=strpas(Pstr3);
edit3.Text:= str3;
end;
Nota: si les passages Pchar->String ou String ->Pchar ne marchent pas (ca arrive...?), procédez Pchar->Array of Char ->String ou String -> Array Of Char -> Pchar
Conclusion
l'exemple fonctionne en Delphi 6 et Delphi 7
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
Comparez les prix

HTC Magic
Entre 429€ et 429€
|