Вниз
Скачать: CL | DM;

Вызов функции из dll   Найти похожие ветки 

← →
Vsr   (2005-07-27 14:28) [0]

Доброго времени суток! В приложении есть две функции: одна сохраняет настройки в реестр, другая их считывает. Решил перенести их в библиотеку.

library cd;
....
function ReadOptionFromRegistry(Option : TRadioButton; SubKey : PChar; Node: PChar) : boolean;
var    R : TRegistry;
      StateInt : byte;
      St : boolean;
begin
   R:=TRegistry.Create;
   try
       result:=R.OpenKey(SubKey,false);
if not result then exit;
       if R.ValueExists(Node) then begin
       StateInt:=R.ReadInteger(Node);
       Move(StateInt,St,1);
       Option.Checked:=St;
       end;
   finally
       R.Free;
   end;
end;

В момент вызова библиотеки на строке LibHandle := LoadLibrary(PChar("cd.dll")); ловлю exception "Cannot create application object in a shared object or library"

procedure TForm2.FormActivate(Sender: TObject);
var ReadOptionFromRegistry: TReadOptionFromRegistry;
begin
try
LibHandle := LoadLibrary(PChar("cd.dll"));
   if LibHandle = 0 then
     raise Exception.Create("Unable to Load   DLL  ...")
   else
   begin
     try @ReadOptionFromRegistry := GetProcAddress(LibHandle, "ReadOptionFromRegistry");
       if @ReadOptionFromRegistry <> nil then
       if ReadOptionFromRegistry(RadioButton1, PChar("Software\CDLibrary\Options"), PChar("CommonName")) then
         begin
           RadioButton1.Checked:=RadioButton1.Checked;
         end;

     except
       on E: Exception do
         ShowMessage("Exception error: " + E.Message);
     end;
   end;
finally
   FreeLibrary(LibHandle);
   end;
end;

Понимаю, что в длл взяться Application неоткуда. А вот как передавать указатель на него, что-то не могу понять. Помогите разобраться.


← →
han_malign ©   (2005-07-27 14:53) [1]

uses Forms из DLL убери


← →
Vsr   (2005-07-27 15:01) [2]

:-(
не помогло


← →
evvcom ©   (2005-07-27 15:04) [3]


> Решил перенести их в библиотеку.

И нафига? Build with runtime packages - галка естественно не стоит?



Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.026 c
8-1112975467
dimon__
2005-04-08 19:51
2005.08.14
SampleGrabber не работает


1-1122290833
chili
2005-07-25 15:27
2005.08.14
Бинарные файлы


3-1120494973
Michael5
2005-07-04 20:36
2005.08.14
Помогите подключить БД Акцесс в приложении, мелочь осталась!


3-1120721303
Lexa
2005-07-07 11:28
2005.08.14
При открытии базы *.mdb создается файл *.ldb


14-1122140424
X9
2005-07-23 21:40
2005.08.14
2 компа + 2 сет.платы + витая пара = troubles




   Наверх