Autor Beitrag
Jeremy
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 99

Fedora Core 1
K3 Ent
BeitragVerfasst: Fr 02.01.04 10:52 
Hallo Leute!!
Ich Hab da ein problem vieleicht kann mir eine(r) mir da helfen. Die Dll lädt ohne problem, aber FreeLibrary(Handle) führt zu ein zugriffs verletzung. Wenn ich FreeLibrary weg las kommt die zugriffs verletzung beim schließen des progs.

Hier ist das code vom Haupt prog:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
procedure TForm1.Button1Click(Sender: TObject);
var
 Handle: THandle;
 D4: TProc;
begin
 Handle := LoadLibrary('.\Lib\dice.dll');
  if Handle = 0 then
   begin
    ShowMessage('Dice.dll not found!');
    Exit;
   end;
  D4 := GetProcAddress(Handle, 'd4');
  Edit1.Text := IntToStr(D4);
  FreeLibrary(Handle);
end;


und der dll-code:
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:
library dice;

uses
  SysUtils,
  Classes,
  ShareMem;

{$R *.res}
Function d4(): Byte;
 begin
  Randomize;
  d4 := random(3) + 1;
 end;
Function d6(): Byte;
 begin
  Randomize;
  d6 := random(5) + 1;
 end;
Function d8(): Byte;
 begin
  Randomize;
  d8 := random(7) + 1;
 end;
Function d10(): Byte;
 begin
  Randomize;
  d10 := random(9) + 1;
 end;
Function d12():Byte;
 begin
  Randomize;
  d12 := random(11) + 1;
 end;
Function Attribute(): Byte;
 var a, b, c: Byte;
 begin
  randomize;
  a := random(5) + 1;
  b := random(5) + 1;
  c := random(5) + 1;
  Attribute := a+b+c;
 end;
Function d20(): Byte;
 begin
  Randomize;
  d20 := random(19) + 1;
 end;
Function percentile(): Byte;
 begin
  Randomize;
  percentile := random(99) + 1;
 end;
Exports
 d4 index 1 Name 'd4',
 d6 index 2 Name 'd6',
 d8 index 3 Name 'd8',
 d10 index 4 Name 'd10',
 d12 index 5 Name 'd12',
 Attribute index 6 Name 'Attibute',
 d20 index 7 Name 'd20',
 percentile index 8 Name 'Percentile';
begin
end.


Wäre doch lieb wenn mann mir erklären könnte was ich falsche gemacht habe.

Jeremy

_________________
Jede ende hat ne anfang genau wie umgekehrt und windows ist der teurste mull den man kaufen kann!!!
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Fr 02.01.04 11:05 
Lass mal Sharemem weg. Du brauchst es nur dann, wenn Du längere Strings übergeben willst, aber das ist ja nicht der Fall..
Jeremy Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 99

Fedora Core 1
K3 Ent
BeitragVerfasst: Fr 02.01.04 11:31 
Titel: Danke
Vielen Dank!! Da hab ich ShareMem entfernt von der DLL und der Haupt prog, und da lief alles glatt. Aber nur noch eine frage aus LernGier (ich will nicht nur wissen wie es geht sonder auch WARUM es geht), Warum fürhte ShareMem zu ein zugriffs verletzung???

Jeremy

_________________
Jede ende hat ne anfang genau wie umgekehrt und windows ist der teurste mull den man kaufen kann!!!
tomtom62
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 278

WIN 2000, XP prof
D5 prof.
BeitragVerfasst: Fr 02.01.04 12:16 
Sorry, könnte jetzt da was Interessantes "blubbern", aber ich weiss es nur aus eigener Erfahrung. :wink:

Wenn ich sowas wie Sharemem benötige, dann nehme ich FastSharemem, das kommt ohne sharemem.dll aus und erscheint mir stabiler.

Gibts bei den Downloads in der Borland Community..
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 02.01.04 13:54 
Die Unit ShareMem ersetzt den normalen Speichermanager von Delphi. Aus diesem Grund muss die Unit als erstes in den Uses eingebunden werden, das war bei dir nicht der Fall, zu mindest in der DLL nicht, da kam sie als letztes.
Jeremy Threadstarter
ontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 99

Fedora Core 1
K3 Ent
BeitragVerfasst: Fr 02.01.04 15:39 
Danke für dein antwort Lucky es war sehr erleuchtend. Nur noch wegen den beitrag von tomtom, welche IST besser zu benutzen, ShareMem oder FastShareMem?? In deinen mein jedenfalls??

Jeremy

_________________
Jede ende hat ne anfang genau wie umgekehrt und windows ist der teurste mull den man kaufen kann!!!