Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > Delay-Loaded Imports (DLLs)


Автор: stab 6.3.2004, 20:05
Насколько я понимаю такие библиотеки загружаются по требованию с помошью LoadLibrary(Ex), далее используется GetProcAddress, но по моим наблюдениям GetProcAddress не вызывается, возможно я ошибаюсь. Как вообще работает этот механизм? Каким образом Dependency Walker (тулса из SDK) показывает информацию о Delay-Loaded DLLs, ведь они не записываются в импорты? Не сканирует же он весь файл на наличие какой либо сигнатуры...

Автор: sergejzr 6.3.2004, 22:31
А для чего они нужны?

Автор: stab 6.3.2004, 22:40
Я пытаюсь разобраться во встроенной в линкер VC поддержке, как ей пользоваться знаю. Не могу понять каким образом Dependency Walker выводит список этих DLL.

Цитата

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/vccore/html/vcconSpecifyingDLLsForDelayLoading.htm

Visual C++ Concepts: Building a C/C++ Program  

Specifying DLLs to Delay LoadSee Also
Linker Support for Delay-Loaded DLLs
You can specify which DLLs to delay load with the /delayload:dllname linker option. If you do not plan to use your own version of a helper function, you must also link your program with Delayimp.lib.

The following is a simple example of delay loading a DLL:

// cl t.cpp user32.lib delayimp.lib  /link /DELAYLOAD:user32.dll
#include <windows.h>
// uncomment these lines to remove .libs from command line
// #pragma comment(lib, "delayimp")
// #pragma comment(lib, "user32")

int main()
{
   // user32.dll will load at this point
   MessageBox(NULL, "Hello", "Hello", MB_OK);
}
Build the DEBUG version of the project. Step through the code using the debugger and you will notice that user32.dll is loaded only when you make the call to MessageBox.

See Also
Linker Support for Delay-Loaded DLLs

Автор: stab 6.3.2004, 22:50
хм, понятно почему не вызывается GetProcAddress:

Цитата

The default linker behavior is to create a bindable import address table for the delay-loaded DLL. If the DLL is bound, the helper function will attempt to use the bound information instead of calling GetProcAddress on each of the referenced imports. If either the timestamp or the preferred address do not match those of the loaded DLL, the helper function will assume the bound import address table is out of date and will proceed as if it does not exist.

Автор: stab 6.3.2004, 22:54
отбой, решение найдено:

"...\Microsoft Visual Studio .NET 2003\Vc7\include\delayhlp.cpp"

Автор: Fantasist 8.3.2004, 22:27
А прокомментировать можно? А то с первого взгляда понятно не стало.

Автор: stab 10.3.2004, 16:12
Оказывается есть специальная таблица импорта для библиотек загружаемых по требованию. Что интересно и печально в документации по PE формату ни слова об этом (или я не там искал, может версия у меня древняя). Так вот в delayimp.h и delayhlp.cpp как раз таки можно нарыть описания структур и понять методику работы. В MSDN отрывочная информация имеется, при желании разобраться можно.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)