Witam,
Podobny temat pojawił się już ale nie rozwiązał on mojego problemu.
Do konktretów, kod biblioteki:
library testLib;
{ ... long comment... }
uses
SysUtils,
Classes,
Forms,
frmTest in 'frmTest.pas' {FormTest};
{$R *.res}
function _Test_Form(dbFile : PChar) : integer; stdcall;
begin
FormTest := TFormTest.Create(nil); // Create(Application);
FormTest.dbFile := String(dbFile);
Result := FormTest.ShowModal;
FormTest.Free;
end;
exports
_Test_Form;
begin
end.
FormTest zawiera Memo i w OnShow wykonuje: Memo1.Text := dbFile;
I procedura w aplikacji Host (wywołującej):
type
TTestProc = function(dbFile : PChar) : integer;
[...]
procedure TForm1.Button1Click(Sender: TObject);
var
dll : THandle;
TestProc : TTestProc; // function(dbFile : PChar) : integer;
begin
dll := LoadLibrary('testlib.dll');
try
@TestProc := GetProcAddress(dll,'_Test_Form');
if @TestProc = nil then raise Exception.Create('Function not loaded!');
TestProc('abcdefgh');
finally
FreeLibrary(dll);
end;
end;
I czy wpiszę w linijce: TestProc('abcdefg'); czy TestProc(PChar(Edit1.Text)); to w Memo z formy w dll dostaje 3 krzaczki :| dodawanie ShareMem na początku uses nie pomaga :( w dodatku przy zamykaniu formy z biblioteki dostaję AV :/