![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
|
|
#1
|
|||
|
|||
|
Доброго всем настроения.
Народ помогите разораться в ошибке. Вроде как все правильно делаю. вот исходники: FunDll Код:
library FunDll;
uses
SysUtils,
dialogs,
Classes;
{$R *.res}
procedure ShowMessage(text: string); stdcall; export;
begin
ShowMessage(text);
end;
function Summ(x: integer; y: integer):integer; stdcall; export;
begin
result:=x+y;
end;
exports
ShowMessage,
Summ;
end. Prog Код:
unit uProgMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TSumm = function (x: integer; y: integer ): integer;
TShowMgs = procedure (text: string);
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const
s: string = 'Welcome';
var
dllHandle: THandle;
ShowMsg: TShowMgs;
begin
@ShowMsg:=nil;
dllHandle:=LoadLibrary('FunDll.dll');
if dllHandle=0 then
exit;
@ShowMsg:=GetProcAddress(dllHandle,'ShowMessage');
if @ShowMsg = nil then
exit;
// здесь пробывал задавать явно текст т.е. ShowMsg('Welcome');
ShowMsg(s);
FreeLibrary(dllHandle);
end;
end.
procedure TForm1.Button2Click(Sender: TObject);
var
dllHandle: THandle;
Sum: TSumm;
begin
@Sum:=nil;
dllHandle:=LoadLibrary('FunDll.dll');
if dllHandle=0 then
exit;
@Sum:=GetProcAddress(dllHandle,'Summ');
if @Summ = nil then
exit;
showmessage(inttostr(sum(4,6)));
FreeLibrary(dllHandle);
end;
end.выдает ошибку . Не могу понять в чем ошибка. по ходу ругается на переполнение Стека. Вроде все правильно делаю. |
|
#2
|
|||
|
|||
|
В обеих функциях?
Если только в ShowMessage (или как там она), то надо и в прогу и в либу в uses добавть ShareMem. Только в этом случае тебе еще придется тащить за собой bormm.dll (что-то типа того). Или перепиши на использование PChar. Т.к. по коду все вроде правильно. |
|
#3
|
|||
|
|||
|
да в обех функциях
|
|
#4
|
||||
|
||||
|
Ну не так нужно делать!
Во-первых, нужно объявить нормально функции в секции exports: Код:
exports ShowMessage name 'ShowMessage', Summ name 'ShowMessage'; Во-вторых, правильное объявление должно быть: Код:
type TSumm = function (x: integer; y: integer ): integer;stdcall; TShowMgs = procedure (text: string);stdcall; // Как в библиотеке объявлено так должно быть объявлено и в программе!!! В-третьих правильный вызов: Код:
procedure TForm1.Button2Click(Sender: TObject);
var
dllHandle: THandle;
Sum: TSumm;
begin
@Sum := nil;
dllHandle := LoadLibrary(PChar('FunDll.dll'));
if dllHandle < 32 then // Ошибок загрузки DLL 32 штуки!!
exit;
@Sum := GetProcAddress(dllHandle, PChar('Summ'));
if @Summ = nil then
exit;
showmessage(inttostr(sum(4, 6)));
FreeLibrary(dllHandle);
end;
|
|
#5
|
|||
|
|||
|
Цитата:
с функцией сложение получилось спасибо понял в чем была ошибка, а вот с процедурой отображения текста все таже ошибка, но я думаю тут уже ошибка моя где то в самой процедуре. Хотя если статически загружить все отлично работает. пробывал вот так в dll Код:
procedure ShowMessage(text: pchar); stdcall; export; begin ShowMessage(text); end; Код:
TShowMgs = procedure (text: pchar);stdcall;
...
procedure TForm1.Button2Click(Sender: TObject);
var
dllHandle: THandle;
ShowMsg:TShowMgs;
begin
@ShowMsg:=nil;
dllHandle:=LoadLibrary(PChar('FunDll.dll'));
if dllHandle<32 then
exit;
@ShowMsg:=GetProcAddress(dllHandle,Pchar('ShowMessage'));
if @ShowMsg=nil then
exit;
ShowMsg(pchar('Welcome'));
FreeLibrary(dllHandle);
end;все равно ошибка. буду думать. |
|
#6
|
||||
|
||||
|
В чем ошибка? Покажи скрин. Или попробуй конвертни PChar в String с помощью StrPas.
|