Einzelnen Beitrag anzeigen

Benutzerbild von RWarnecke
RWarnecke

Registriert seit: 31. Dez 2004
Ort: Stuttgart
4.408 Beiträge
 
Delphi XE8 Enterprise
 
#3

AW: Kommunikation zwischen DLL und Hauptprogramm

  Alt 10. Dez 2012, 18:39
Delphi-Quellcode:
library Project3;

{ 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
  System.SysUtils,
  System.Classes,
  Unit3 in 'Unit3.pas';

{$R *.res}

function TestSub(Number1, Number2: Integer): Integer;
var
  MyClass : IMath;
begin
  Result := MyClass.Sub(Number1, Number2);
end;

exports
  TestSub;

begin
end.
Das Problem war, dass das Interface nicht an die DLL übergeben wurde. Ich habe die obenstehende Funktion einfach um den Parameter MyIntf: IMath erweitert und die lokale Variable entfernt. Wenn ich jetzt die erstellte Klasse MyClass an die DLL-Funktion übergebe, funktioniert der Aufruf der Funktion TestSub.

Erst wenn ich das MyClass.Free in der Unit2 durch MyClass := nil; ersetze, bekomme ich nichtmehr die folgende Fehlermeldung :
---------------------------
Project2
---------------------------
Access violation at address 00000000. Read of address 00000000.
---------------------------
OK
---------------------------
Rolf Warnecke
App4Mission

Geändert von RWarnecke (10. Dez 2012 um 18:41 Uhr)
  Mit Zitat antworten Zitat