![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Расскажите как объявлять вункции из dll [D7, XP]
KyRo © (2006-12-19 12:32:00)У меня есть dll Подскажите как объявлять функции из нее в своей программе .
Что значат вот эти параметры external,stdcall и.т.д
Иодскажите что бы использовать библиотеку обязательно ли ее регить в виндовс regsvr32 ?
Заранее благодарен.
Ega23 (2006-12-19 13:12:00) [21]
> И делаю то я все именно по документации и не выходит !
"Не верю!" (с)
KyRo (2006-12-19 13:08:00) [22]
> В документации наверняка есть примеры объявления и использования
> библ.функций.
> Зачем же слепо экспериментировать ?
Есть не спорю но там документация под Вижуал бейсик хотя сама библиотека написана на делфи.!!
И делаю то я все именно по документации и не выходит !
Вот и хочу найти в чем проблемма !
То ли я что то не так делаю , или чего то в ос не хватает или оборудование глючное что тож может быть !!
Сергей М. (2006-12-19 13:01:00) [23]В документации наверняка есть примеры объявления и использования библ.функций.
Зачем же слепо экспериментировать ?
KyRo (2006-12-19 12:51:00) [24]Спасибо.
Ну вроде я все правильно делаю объявляю
unit Ps1_Unt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, StdCtrls;
type
TPs1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
GroupBox1: TGroupBox;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
// а из программы ее можно вызывать так:
function myCoin_setup(mycoin_type:String):Boolean; external 'MyCommPort.dll';
function myComm_setup(myport_number:LongInt;myport_setting:String):Boolean; external 'MyCommPort.dll';
function myComm_status(myport_number:LongInt; myport_setting:String; mybuffer_size :LongInt;
myport_open :Boolean) :Boolean; external 'MyCommPort.dll';
function myComm_Open:Boolean; external 'MyCommPort.dll';
function myComm_Close:Boolean; external 'MyCommPort.dll';
function myComm_poll(mycoin_number:LongInt;mycredit_value:LongInt;mytype_count:String):Bo olean; external 'MyCommPort.dll';
вызываю
Bul:=myComm_Open;
и функция все время возвращает фалсе .
Эту библиотеку по документации надо регить. Я ее зарегил .
Можно ли как то проверить что библиотека нормально зарегилась в виндовсе и что программа обращается к ней ? Или если бы программа ее не находила она бы выдавала бы ошибку ?
Сергей М. (2006-12-19 12:40:00) [25]
> что бы использовать библиотеку обязательно ли ее регить
> в виндовс regsvr32 ?
"Регить в виндовс regsvr32" нужно только те библиотеки, которые являют собой полноценные серверыавтоматизации, о чем и говорит reg svr32
Ega23 (2006-12-19 12:37:00) [26]external
Before you can call routines defined in a DLL, you must import them. This can be done in two ways: by declaring an external procedure or function, or by calling the Windows API directly. Whichever method you use, the routines are not linked to your application until runtime. This means that the DLL need not be present when you compile your program. It also means that there is no compile-time validation of attempts to import a routine.
Object Pascal does not support importing of variables from DLLs.
Static loading
The simplest way to import a procedure or function is to declare it using the external directive. For example,
procedure DoSomething; external 'MYLIB.DLL';
If you include this declaration in a program, MYLIB.DLL is loaded once, when the program starts. Throughout execution of the program, the identifier DoSomething always refers to the same entry point in the same DLL.
Declarations of imported routines can be placed directly in the program or unit where they are called. To simplify maintenance, however, you can collect external
declarations into a separate “import unit” that also contains any constants and types required for interfacing with the DLL. (Delphi’s Windows unit is a good example.) Other modules that use the import unit can call any routines declared in it.
For more information about external declarations, see External declarations.
Dynamic loading through Windows API calls.
stdcall
When you declare a procedure or function, you can specify a calling convention using one of the directives register, pascal, cdecl, stdcall, and safecall
. For example,
function MyFunction(X, Y: Real): Real; cdecl;
...
Calling conventions determine the order in which parameters are passed to the routine. They also affect the removal of parameters from the stack, the use of registers for passing parameters, and error and exception handling. The default calling convention is register.
The register and pascal conventions pass parameters from left to right; that is, the leftmost parameter is evaluated and passed first and the rightmost parameter is evaluated and passed last. The cdecl, stdcall, and safecall conventions pass parameters from right to left.
For all conventions except cdecl, the procedure or function removes parameters from the stack upon returning. With the cdecl convention, the caller removes parameters from the stack when the call returns.
The register convention uses up to three CPU registers to pass parameters, while the other conventions pass all parameters on the stack.
The safecall convention implements COM error and exception handling.
The table below summarizes calling conventions.
Directive Parameter order Clean-up Passes parameters in registers?
register Left-to-right Routine Yes
pascal Left-to-right Routine No
cdecl Right-to-left Caller No
stdcall Right-to-left Routine No
safecall Right-to-left Routine No
The default register convention is the most efficient, since it usually avoids creation of a stack frame. (Access methods for published properties must use register.) The cdecl convention is useful when you call functions from DLLs written in C or C++, while stdcall and safecall are used for Windows API calls. The safecall convention must be used for declaring dual-interface methods. The pascal convention is maintained for backward compatibility. For more information on calling conventions, see Program control.
The directives near, far, and export refer to calling conventions in 16-bit Windows programming. They have no effect in 32-bit applications and are maintained for backward compatibility only.
novill (2006-12-19 12:36:00) [27]справку читать пробовал?