Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "WinAPI";
Текущий архив: 2004.05.02;
Скачать: [xml.tar.bz2];

Вниз

Приложение + DLL   Найти похожие ветки 

 
nexxiss ©   (2004-03-10 12:30) [0]

Имеется DLL библиотека. Как мне получить в самом приложении адрес входа в определенную процедуру или функцию из этой библиотеки ?


 
Digitman ©   (2004-03-10 12:36) [1]


> Имеется DLL библиотека


как линкуется тобой ? статически ? динамически ?


 
YuRock ©   (2004-03-10 12:57) [2]

Если функция экспортируемая, то GetProcAddress


 
Игорь Шевченко ©   (2004-03-10 13:37) [3]

LoadLibrary +


> Если функция экспортируемая, то GetProcAddress


 
Klev   (2004-03-10 14:20) [4]

Если библиотека линкуется динамически
для этого надо использовать(как совершенно верно сказал  Игорь Шевченко ©   (10.03.04 13:37) [3]) LoadLibrary и если функция экспортируемая, то GetProcAddress:

The LoadLibrary function maps the specified executable module into the address space of the calling process.

Выдержка из Win32 programming reference:
HINSTANCE LoadLibrary(

   LPCTSTR lpLibFileName  // address of filename of executable module
  );


Parameters

lpLibFileName

Points to a null-terminated string that names the executable module (either a .DLL or .EXE file). The name specified is the filename of the module and is not related to the name stored in the library module itself, as specified by the LIBRARY keyword in the module-definition (.DEF) file.

If the string specifies a path but the file does not exist in the specified directory, the function fails.
If a path is not specified and the filename extension is omitted, the default library extension .DLL is appended. However, the filename string can include a trailing point character (.) to indicate that the module name has no extension. When no path is specified, the function searches for the file in the following sequence:

1. The directory from which the application loaded.
2. The current directory.
3. Windows 95: The Windows system directory. Use the GetSystemDirectory function to get the path of this directory.

Windows NT: The 32-bit Windows system directory. Use the GetSystemDirectory function to get the path of this directory. The name of this directory is SYSTEM32.

4. Windows NT: The 16-bit Windows system directory. There is no Win32 function that obtains the path of this directory, but it is searched. The name of this directory is SYSTEM.
5. The Windows directory. Use the GetWindowsDirectory function to get the path of this directory.
6. The directories that are listed in the PATH environment variable.



The first directory searched is the one directory containing the image file used to create the calling process (for more information, see the CreateProcess function). Doing this allows private dynamic-link library (DLL) files associated with a process to be found without adding the process"s installed directory to the PATH environment variable.
Once the function obtains a fully qualified path to a library module file, the path is compared (case independently) to the full paths of library modules currently loaded into the calling process. These libraries include those loaded when the process was starting up as well as those previously loaded by LoadLibrary but not unloaded by FreeLibrary. If the path matches the path of an already loaded module, the function just increments the reference count for the module and returns the module handle for that library.



Return Values

If the function succeeds, the return value is a handle to the module.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

LoadLibrary can be used to map a DLL module and return a handle that can be used in GetProcAddress to get the address of a DLL function. LoadLibrary can also be used to map other executable modules. For example, the function can specify an .EXE file to get a handle that can be used in FindResource or LoadResource.
Module handles are not global or inheritable. A call to LoadLibrary by one process does not produce a handle that another process can use ѕ for example, in calling GetProcAddress. The other process must make its own call to LoadLibrary for the module before calling GetProcAddress.

If the module is a DLL not already mapped for the calling process, the system calls the DLL"s DllEntryPoint function with the DLL_PROCESS_ATTACH value. If the DLL"s entry-point function does not return TRUE, LoadLibrary fails and returns NULL.
Windows 95: If you are using LoadLibrary to load a module that contains a resource whose numeric identifier is greater than 0x7FFF, LoadLibrary fails.

The GetProcAddress function returns the address of the specified exported dynamic-link library (DLL) function.

FARPROC GetProcAddress(

   HMODULE hModule, // handle to DLL module  
   LPCSTR lpProcName  // name of function
  );


Parameters

hModule

Identifies the DLL module that contains the function. The LoadLibrary or GetModuleHandle function returns this handle.

lpProcName

Points to a null-terminated string containing the function name, or specifies the function"s ordinal value. If this parameter is an ordinal value, it must be in the low-order word; the high-order word must be zero.



Return Values

If the function succeeds, the return value is the address of the DLL"s exported function.
If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

The GetProcAddress function is used to retrieve addresses of exported functions in DLLs.
The spelling and case of the function name pointed to by lpProcName must be identical to that in the EXPORTS statement of the source DLL"s module-definition (.DEF) file.
The lpProcName parameter can identify the DLL function by specifying an ordinal value associated with the function in the EXPORTS statement. GetProcAddress verifies that the specified ordinal is in the range 1 through the highest ordinal value exported in the .DEF file. The function then uses the ordinal as an index to read the function"s address from a function table. If the .DEF file does not number the functions consecutively from 1 to N (where N is the number of exported functions), an error can occur where GetProcAddress returns an invalid, non-NULL address, even though there is no function with the specified ordinal.

In cases where the function may not exist, the function should be specified by name rather than by ordinal value.

А вот и примерчик:
...............
Type
proc:Tprocedure(param1,param2,param3...:integer);
Var
hlib:dword;
proc1:proc;
begin
hlib:=Loadlibrary(pchar("Твоя.dll"));
@proc1:=GetProcAddress(hlib,pchar("Имя твоей функции"));

proc1(param1,param2,param3...);
end;


 
Игорь Шевченко ©   (2004-03-10 15:03) [5]

Klev   (10.03.04 14:20)

Я был бы очень признателен, если бы полная справка по функциям здесь не публиковалась.

С уважением,
Игорь Шевченко, ко-модератор WinAPI.


 
nexxiss ©   (2004-03-10 15:05) [6]

Спасибо за необходимую инфо. Возникнут вопросы, буду спрашивать.



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

Форум: "WinAPI";
Текущий архив: 2004.05.02;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.47 MB
Время: 0.042 c
14-1081759781
Lexer
2004-04-12 12:49
2004.05.02
Характеристика программиста


3-1080867791
kay
2004-04-02 05:03
2004.05.02
Table1, DBGrid1, значения в верхнем и нижнем регистрах.


11-1045034380
Un-man
2003-02-12 10:19
2004.05.02
OnIdle в KOL


3-1081229956
Russko
2004-04-06 09:39
2004.05.02
Ошибка при открытии БД


1-1081937636
antoniz
2004-04-14 14:13
2004.05.02
Как сделать полупрозрачный фон (заливку)





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский