Franziscko
07-08-2008, 11:33
Ciao a tutti, è la prima volta che posto in questa sezione, ho uno stupido problema che non riesco a risolvere, ma inizio dagli...inizi!:D
La mia esperienza si basa sul Basic del mitico ZX Spectrum, poi col 486 ho usato il Qbasic, infine sono passato al Turbo Pascal, non appena ho visto gli 'oggetti' mi sono fermato, intanto è arrivato windows e con esso Delphi, ora uso Delphi 7, sono totalmente autodidatta, cerco di capire come funziona qualcosa dai listati che trovo e dagli esempi, non capisco un acca di oggetti, almeno per quanto riguarda crearli, ma dagli esempi dell'help riesco un po' a far funzionare quel che mi serve, non senza sbattere la testa per soluzioni a volte semplicissime. Programmo per diletto, niente altro. Credo di essere il peggior programmatore qui dentro!!:cry:
Bene, ora che conoscete le mie qualità :read: , vediamo se potete aiutarmi.
Vorrei cominciare ad usare le .dll per non scrivere sempre le stesse cose, ed ho trovato alcuni esempi, ma non me ne funziona nemmeno uno.
Mi spiego: la .dll viene creata, la richiamo e funziona, ricevo la stringa interessata, solo che al momento poi di chiudere l'eseguibile, Delphi mi dà questo errore: INVALID POINTER OPERATION, mentre se uso l'eseguibile da solo senza delphi, quando lo chiudo ricevo questo errore: RUNTIME ERROR 217 AT 00413DB4.
Questo è il listato della dll che, ripeto, è un esempio trovato in rete.
library DLLFile;
{ 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
ShareMem,
SysUtils,
Classes;
{$R *.res}
function GetCurrentTime: string; stdcall;
begin
result := PAnsiChar(TimeToStr(Now));
end;
function GetCurrentDate: string; stdcall;
begin
result := DateToStr(Now);
end;
exports
GetCurrentTime,
GetCurrentDate;
end.
Questo è invece il listato che richiama la dll, fatot da me, tanto per provarlo:
unit Unit1;
interface
uses
ShareMem, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
function GetCurrentTime: string; stdcall External 'DLLFile.dll';
function GetCurrentDate: string; stdcall External 'DLLFile.dll';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption := GetCurrentTime;
label2.Caption := GetCurrentDate;
end;
end.
Dimenticavo: se lancio l'eseguibile e non premo il pulsante, cioè non richiamo la funzione, l'errore c'è lo stesso, come se fosse quindi nel caricare o scaricare la dll (avrò sparato una scemenza...:D ).
Grazie a chi potrà aiutarmi.
Ciao.:)
La mia esperienza si basa sul Basic del mitico ZX Spectrum, poi col 486 ho usato il Qbasic, infine sono passato al Turbo Pascal, non appena ho visto gli 'oggetti' mi sono fermato, intanto è arrivato windows e con esso Delphi, ora uso Delphi 7, sono totalmente autodidatta, cerco di capire come funziona qualcosa dai listati che trovo e dagli esempi, non capisco un acca di oggetti, almeno per quanto riguarda crearli, ma dagli esempi dell'help riesco un po' a far funzionare quel che mi serve, non senza sbattere la testa per soluzioni a volte semplicissime. Programmo per diletto, niente altro. Credo di essere il peggior programmatore qui dentro!!:cry:
Bene, ora che conoscete le mie qualità :read: , vediamo se potete aiutarmi.
Vorrei cominciare ad usare le .dll per non scrivere sempre le stesse cose, ed ho trovato alcuni esempi, ma non me ne funziona nemmeno uno.
Mi spiego: la .dll viene creata, la richiamo e funziona, ricevo la stringa interessata, solo che al momento poi di chiudere l'eseguibile, Delphi mi dà questo errore: INVALID POINTER OPERATION, mentre se uso l'eseguibile da solo senza delphi, quando lo chiudo ricevo questo errore: RUNTIME ERROR 217 AT 00413DB4.
Questo è il listato della dll che, ripeto, è un esempio trovato in rete.
library DLLFile;
{ 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
ShareMem,
SysUtils,
Classes;
{$R *.res}
function GetCurrentTime: string; stdcall;
begin
result := PAnsiChar(TimeToStr(Now));
end;
function GetCurrentDate: string; stdcall;
begin
result := DateToStr(Now);
end;
exports
GetCurrentTime,
GetCurrentDate;
end.
Questo è invece il listato che richiama la dll, fatot da me, tanto per provarlo:
unit Unit1;
interface
uses
ShareMem, Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
function GetCurrentTime: string; stdcall External 'DLLFile.dll';
function GetCurrentDate: string; stdcall External 'DLLFile.dll';
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption := GetCurrentTime;
label2.Caption := GetCurrentDate;
end;
end.
Dimenticavo: se lancio l'eseguibile e non premo il pulsante, cioè non richiamo la funzione, l'errore c'è lo stesso, come se fosse quindi nel caricare o scaricare la dll (avrò sparato una scemenza...:D ).
Grazie a chi potrà aiutarmi.
Ciao.:)