Помогите разобраться с dll-кой, никогда раньше не связывался, вот решил и...Что то не так.
В dll-ке функция и процедура. Процедура для проверки работаю с dll-кой или нет. Ф-ии в dll-ке и в проге делают одно и то же. В проге все путем, при вызове из dll получаю
Project raised exception class External SIGSEGVи потом приезжаю в winapi.inc на function GetCapture: HWND;
Result := WidgetSet.GetCapture;
Может кто подскажет, что не так делаю?
Значит сама dll:
- Код: Выделить всё
library dll_test;
{$mode objfpc}{$H+}
uses
Classes, Forms, Windows, Registry;
{$IFDEF WINDOWS}{$R dll_test.rc}{$ENDIF}
procedure HelloWorld(AForm : TForm);
begin
MessageBox(AForm.Handle, ('Hello world!'), pchar ('DLL Message Box'), MB_OK or MB_ICONEXCLAMATION);
end;
function NameLPTGet :TStrings;
var
Reg: TRegistry;
begin
result:=TStringList.Create;
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('\HARDWARE\DEVICEMAP\PARALLEL PORTS', True) then
if Reg.ReadString('\Device\Parallel0')<> '' then result.Add('LPT1');
if Reg.ReadString('\Device\Parallel1')<> '' then result.Add('LPT2');
if Reg.ReadString('\Device\Parallel2')<> '' then result.Add('LPT3');
Reg.CloseKey;
Reg.Destroy;
end;
exports
HelloWorld,
NameLPTGet;
begin
end.
Вот прога которая ее юзает.
- Код: Выделить всё
unit dll_demo;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
StdCtrls, Registry;
procedure HelloWorld(AForm : TForm); stdcall; external 'dll_test.dll';
function NameLPTGet :TStrings; stdcall; external 'dll_test.dll';
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
function GetLptName:TStrings;
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
HelloWorld(self);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ComboBox1.Items:= NameLPTGet;
ComboBox1.ItemIndex:=0;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ComboBox2.Items:= GetLptName;
ComboBox2.ItemIndex:=0;
end;
function TForm1.GetLptName:TStrings;
var
Reg: TRegistry;
begin
result:=TStringList.Create;
Reg := TRegistry.Create;
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('\HARDWARE\DEVICEMAP\PARALLEL PORTS', True) then
if Reg.ReadString('\Device\Parallel0')<> '' then result.Add('LPT1');
if Reg.ReadString('\Device\Parallel1')<> '' then result.Add('LPT2');
if Reg.ReadString('\Device\Parallel2')<> '' then result.Add('LPT3');
Reg.CloseKey;
Reg.Destroy;
end;
initialization
{$I dll_demo.lrs}
end.
С уважением...