Autor Beitrag
bumbumb
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Sa 14.01.06 12:25 
Hallo,
ich brauche ein kurzes Beispiel wie mann eine DLL durch drücken eines Buttons laden kann. Ist dieses eigenetlich möglich? Meine DLL heist bumbumb.dll. Sie soll also nur geladen werden wenn der Button angeklickt wurde.
Danke im Voraus
bumbumb

PS: Bitte mit Beispiel!!


Moderiert von user profile iconChristian S.: Topic aus VCL (Visual Component Library) verschoben am Sa 14.01.2006 um 12:44
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 14.01.06 12:44 
bumbumb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Sa 14.01.06 12:51 
Hallo,
das habe ich schon gemacht aber ich will beim Drücken es Buttons die Dll starten das habe ich nicht gefunden hast du ein BSP
danke
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 14.01.06 13:00 
Dann packst du halt den Code zum laden der DLL in das OnClick-Ereignis des Buttons...

_________________
Programmers never die, they just GOSUB without RETURN
bumbumb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Sa 14.01.06 13:11 
kannst du mir bitte bitte ein Bsp geben danke
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 14.01.06 13:14 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Procedure Button1Click(Sender: TObject);
var {halt alle Variablen, die du fürs laden brauchst}
begin
  {hier die DLL dynamisch laden}
end;


Das ist daran so schwer?
Jetzt musst du nur noch anhand des Tutorials die DLL drin dynamisch laden.
Wie du das OnClick-Ereignis in Delphi erstellst weißt du ja wahrscheinlich.

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
bumbumb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Sa 14.01.06 13:15 
kannst du mir nicht eben den Code darein schreiben damit ich das weis es ist meine 1te dll danke
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 14.01.06 13:28 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
Procedure Button1Click(Sender: TObject);
var DLLfunction = function(a,b: integer): integer;  //Das ist die Funktion, die später ausgeführt werden kann. Natürlich musst du die Parameter an deine DLL anpassen
FuncPtr: TFarProc; //Das ist der Pointer auf die DLLfunction. Verwendest du mehrere Methoden in deiner DLL, die du laden möchtest, dann musst du mehrere Methoden hier als Variable deklarieren (Bsp ist DLLfunction, weitere wären dann z.B. DLLfuntion2 oder solche Scherze
DLLHandle: THandle; //Das ist das Handle auf die DLL
begin
  DLLHandle := LoadLibrary(PChar({hier den Dateinamen einsetzen});//Die DLL wird hier in den Speicher geladen
  if DLLHandle = nil then begin//wenn die DLL nicht geladen werden konnte ist das Handle nil
    Showmessage('Die DLL konnte nicht gefunden werden');
    exit; //Vorgang abbrechen, da die DLL nicht geladen wurde
  end;
  FuncPtr := GetProcAddress(DLLHandle, 'berechne');//Hier erhält man den Pointer auf die Funktion 'berechne'. Du musst den Namen halt auf deine Methode(n) anpassen
  if FuncPtr <> nil then begin
    @DLLFunction := FuncPtr;//hier wird der Methode DLLfunction die entsprechende DLL-Methode zugewiesen.
  end;
end;


Du hättest das aber auch mit der DF- Suche erreichen können, ich hab mal danach gesucht und viele brauchbare treffer bekommen: Suche in der Entwickler-Ecke DLL DYNAMISCH LADEN

_________________
Programmers never die, they just GOSUB without RETURN
bumbumb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Sa 14.01.06 13:38 
Titel: Fehler
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
procedure TForm1.DruckenClick(Sender: TObject);
var pat:integer;
  DLLfunction = procedure Printpage(AktNr: integer); stdcall; // ist doch richtig oder bei mir ist es eine Procedure
  FuncPtr: TFarProc; //Das ist der Pointer auf die DLLfunction. Verwendest du mehrere Methoden in deiner DLL, die du laden möchtest, dann musst du mehrere Methoden hier als Variable deklarieren (Bsp ist DLLfunction, weitere wären dann z.B. DLLfuntion2 oder solche Scherze
  DLLHandle: THandle; //Das ist das Handle auf die DLL
begin
        DLLHandle := LoadLibrary(PChar(r);//Die DLL wird hier in den Speicher geladen
  if DLLHandle = nil then begin//wenn die DLL nicht geladen werden konnte ist das Handle nil
    Showmessage('Die DLL konnte nicht gefunden werden');
    exit; //Vorgang abbrechen, da die DLL nicht geladen wurde
  end;
  FuncPtr := GetProcAddress(DLLHandle, 'printpage');//Hier erhält man den Pointer auf die Funktion 'berechne'. Du musst den Namen halt auf deine Methode(n) anpassen
  if FuncPtr <> nil then begin
    @DLLFunction := FuncPtr;//hier wird der Methode DLLfunction die entsprechende DLL-Methode zugewiesen.
  end;

//Fehler er sagt jetzt , oder : erwartet aber = gefunden was ist falsch
 
end;


Moderiert von user profile iconGausi: Beitragsformatierung überarbeitet.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 14.01.06 13:44 
user profile iconalias5000 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
var DLLfunction : function(a,b: integer): integer;					


Das muss geändert werden, war ein schreibfehler.

_________________
Programmers never die, they just GOSUB without RETURN
bumbumb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Sa 14.01.06 13:48 
aber es wird meine procedure nicht aufgerufen was kann das sein?
bumbumb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Sa 14.01.06 13:52 
ok wie wird jetzt die Funktion in der DLL aufgerufen? Help danke
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 14.01.06 14:13 
Dann schreibst du im Button1CLick einfach(jetzt nach meinem Bsp):
ausblenden Delphi-Quelltext
1:
DLLFunction(1,2);					


Um die Funktion auch in anderen Prozeduren verwenden zu können, musst du die Variable DLLfunction global deklarieren. (also z.B. unter oder über implemetation)

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
bumbumb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Sa 14.01.06 14:26 
er stürzt wenn ich das so mache total ab.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm1.DruckenClick(Sender: TObject);
var pat:integer;
DLLfunction : procedure (AktNr: integer); stdcall; //** Ist das so richtig oder muß hier noch der Name der Procedure stehen????????????ßßß
FuncPtr: TFarProc; //Das ist der Pointer auf die DLLfunction. Verwendest du mehrere Methoden in deiner DLL, die du laden möchtest, dann musst du mehrere Methoden hier als Variable deklarieren (Bsp ist DLLfunction, weitere wären dann z.B. DLLfuntion2 oder solche Scherze
DLLHandle: THandle; //Das ist das Handle auf die DLL
begin
   DLLHandle := LoadLibrary(PChar(r));//Die DLL wird hier in den Speicher geladen
   if DLLHandle = nil then begin//wenn die DLL nicht geladen werden konnte ist das Handle nil
    Showmessage('Die DLL konnte nicht gefunden werden');
    exit; //Vorgang abbrechen, da die DLL nicht geladen wurde
  end;
  FuncPtr := GetProcAddress(DLLHandle, 'printpage');//Hier erhält man den Pointer auf die Funktion 'berechne'. Du musst  den Namen halt auf deine Methode(n) anpassen
  if FuncPtr <> nil then begin
    @DLLFunction := FuncPtr;//hier wird der Methode DLLfunction die entsprechende DLL-Methode zugewiesen.
  end;
   DLLFunction(1122121);

end;


Moderiert von user profile iconGausi: Beitragsformatierung überarbeitet.
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 14.01.06 14:34 
Wo hängt es denn, wo stürtzt er ab?
Stürzt er nicht mehr ab, wenn du die letzte Zeile weglässt?

_________________
Programmers never die, they just GOSUB without RETURN
bumbumb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Sa 14.01.06 14:35 
ja so ist es wenn ich die letzte zeile weglasse geht es aber dann wird ja die Procedure nicht mehr aufgerufen ???
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 14.01.06 14:52 
Dann ist es aber auch möglich, dass in der DLL-Prozedur n Fehler drinnen ist, wenn du die Source mal zeigst, können wir dir vllcht helfen

Gruß alias5000

_________________
Programmers never die, they just GOSUB without RETURN
bumbumb Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Sa 14.01.06 14:54 
Hallo,
ihr seit so net hier ist der Code der Dll Vielen Dank

ausblenden volle Höhe Delphi-Quelltext
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:
library peine;

{ Wichtiger Hinweis zur DLL-Speicherverwaltung: ShareMem muss sich in der
  ersten Unit der unit-Klausel der Bibliothek und des Projekts befinden (Projekt-
  Quelltext anzeigen), falls die DLL Prozeduren oder Funktionen exportiert, die
  Strings als Parameter oder Funktionsergebnisse übergeben. Das gilt für alle
  Strings, die von oder an die DLL übergeben werden -- sogar für diejenigen, die
  sich in Records und Klassen befinden. Sharemem ist die Schnittstellen-Unit zur
  Verwaltungs-DLL für gemeinsame Speicherzugriffe, BORLNDMM.DLL.
  Um die Verwendung von BORLNDMM.DLL zu vermeiden, können Sie String-
  Informationen als PChar- oder ShortString-Parameter übergeben. }

  

uses
  Windows,
  Messages,
  SysUtils,
  Variants,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  DB,
  DBTables,
  StdCtrls,
  ExtCtrls,
  Printers,
  Mask,
  StrUtils,
  jsbarcode,
  BarHL,
  Menus,
  jpeg,
  GraphicEx,
  WinSkinData,
  Grids;

{$R *.res}
{$I strd}
{$I fob}
{$I text_out}
{$I blk_codr}

{$I Taktmarke}
{$I barcode}




procedure PrintPage(AktNr:integer);
var
zeile,spalte:integer;
HaktNr,HPatNr,Nummer:string;
Margins: TMargins;
begin
Printer.BeginDoc;
GetPrinterMargins(Margins);
// Eindruck des Fob's
fob_out(1.77,1.37,Margins.Left,Margins.Top,'c:\59750_1.tif');
//        X    Y   DR Links     DR Oben    Dateiname des Fob's
// Klarschrift
text_out(10,2.0,'Arial',12,0,Margins.Left,Margins.Top,Copy(InTToStr(AktNr+1000000),2,6));
//        X  Y   Font   Sz Ro   DR Links     DR Oben                  Inhalt      (Angabe X,Y in cm)
// Blockcode mit Änderung der Ziffernfolge
Nummer:=Copy(IntToStr(AktNr+1000000),2,6);
HaktNr:=Copy(Nummer,1,1)+Copy(Nummer,3,1)+Copy(Nummer,5,1);
HPatNr:=Copy(Nummer,2,1)+Copy(Nummer,4,1)+Copy(Nummer,6,1);
block_codr(9,12.3,1.8,0.35,0.15,0.508,2.54,Margins.Left,Margins.Top,Copy(IntToStr(StrToInt(HaktNr)+1000),2,3));
block_codr(9,12.3,2.2,0.35,0.15,0.508,2.54,Margins.Left,Margins.Top,Copy(IntToStr(StrToInt(HPatNr)+1000),2,3));
//         T  X    Y                        DR Links      DR Oben                           Inhalt





for zeile:=0 to 1 do
  for spalte:=0 to 6 do
    begin
      // Klarschrift neben Barcode
      text_out(0.56+Spalte*2.7,27.6+Zeile*1.65,'Arial',10,270,Margins.Left,Margins.Top,Copy(IntToStr(AktNr+1000000),2,6));
      //  Barcode eindrucken
      taktmarke(1.4+Spalte*2.7,24.1+1*1.7,0.35,0.15,Margins.Left,Margins.Top);
      barcode(true,1.4+Spalte*2.7,26.1+Zeile*1.7,1.4,0.9,CODE25i,false,SC0,Margins.Left,Margins.Top,Copy(IntToStr(AktNr+1000000),2,6));
       //      BMP?      X               Y        BB  BH  BCType Klars    DR Links     DR Oben            Inhalt
      //                                                         sichtbar
    end;
  Printer.EndDoc;
    //Printer.NewPage;
end;
exports
  PrintPage;
end.


Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Sa 14.01.06 14:54 
Die Function erwartet bestimmt zwei Parameter
ausblenden Delphi-Quelltext
1:
2:
DLLFunction(1122121);
DLLFunction(112,2121);


Edit - war Quatsch bin noch von der Oberen Function ausgegangen.


Zuletzt bearbeitet von Blackheart666 am Sa 14.01.06 14:58, insgesamt 1-mal bearbeitet
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 14.01.06 14:56 
Kleine Bemerkung am Rand, würdest du bitte die Delphi Tags oben benutzen, wenn du Source-Code postest?

_________________
Programmers never die, they just GOSUB without RETURN