News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

dll, lib and dynamic relocation

Started by pavellus, July 04, 2006, 04:36:10 PM

Previous topic - Next topic

pavellus

(see last post)
I don't know how windows manage dll libraries. Is a possibility to list all dll's that are loaded by system ?
How programs are linking with dll's ?
Is in network a simple picture depicting dynamic linking ?

jamesb1979

Quote from: pavellus on July 04, 2006, 04:36:10 PMI don't know how windows manage dll libraries. Is a possibility to list all dll's that are loaded by system ?

I don't know either, but there might be some clues in books like Inside Microsoft Windows by the authors at http://www.sysinternals.com. Possibly there could be some advanced techniques like writing a device driver that snoops inside protected OS memory regions and does some poking around, but that would require a knowledge of the in-memory layout of the kernel. Very difficult.

Quote from: pavellus on July 04, 2006, 04:36:10 PMHow programs are linking with dll's ?

What do you mean exactly? How linking works generally, or what DLLs a program will load or indicates that it might need? This information can be found by looking inside a PE file. For details on the PE file format take a look at http://msdn.microsoft.com/msdnmag/issues/02/02/PE/ and http://msdn.microsoft.com/msdnmag/issues/02/03/PE2/. For information on the linking process itself, object file formats, EXE formats and more, take a look at Linkers and Loaders by John Levine http://linker.iecc.com/. The draft manuscript of the book and sample code are free to download. I have the hard copy and it sheds a great deal of light on this mysterious topic!


Quote from: pavellus on July 04, 2006, 04:36:10 PMIs in network a simple picture depicting dynamic linking ?

If I understand the question correctly, that question is answered at least partially by the Linkers and Loaders book which you can download.

A very fascinating subject, have fun!

hutch--

A DLL by its original design is dynamically loaded at run time by a number of system calls. LoadLibrary() loads the DLL into memory, GetProcAddress() gets the starting address of the function you require which you then call when you need it. More commonly the DLL is loaded at startup and resides in memory for the duration of the EXE running but it is not as flexible.

A DLL is effectively a working binary file and it differs from an EXE file only in that it does not have a starting address so it will not run by itself but must be called by another program, generally a seperate process. When it is called, the DLL is mapped into the same memory space as the caller and its function can be called by the caller until it is unloaded from memory.

Used properly it is a very efficient system in that you cal load and unload bits of binary code as you need it and it was the method that the early versions of Windows used so they would run on machine with very limited amounts of memory.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jamesb1979

I've probably misinterpreted the question. Are you looking for details on how to use DLLs or more technical stuff like the format of PE/DLL files and how linking works at the OS level?

Hutch has answered the question of DLLs. The good thing about LoadLibrary() and GetProcAddress() is that it allows for second thoughts and it's very flexible. On the other hand it is possible to link the EXE to the DLLs "LIB" file and the DLL automagically gets loaded and calling functions from the DLL is just like calling functions from static link libraries.

pavellus

Thank You :)
I am reading http://linker.iecc.com/. link. It is very good.

Clarification: I am looking for simple scheme or description how dynamic linker (or even static) fills addresses to external functions located in dll library.
Maybe above documentation will answer this question.

ToutEnMasm


For sample scheme,definition of what is a static link or a dynamic link is useful.
Dll have the the adress of the functions in them.
You perform a dynamic link when you search the adress of the function in the dll.
GetProcaddress make that.
You perform a static link,when you use a library to connect to the function in the dll.The adress is in the library and you use invoke following by the name of the function.You have to put the include files and libraries in the source files.

The dynamic link couldn't failed.The static link could failed because when you modify the dll the adresses changes into the library.In this case you have to take the new library and recompile your program.
                                   
                        ToutEnMasm


pavellus

I get unresolved external symbol message. How could i check in which library CreateGLWindow is defined?

I try to invoke CreateGLWindow, but there is no definition in opengl32.lib and gnu32.lib.

mnemonic

#7
pavellus,

according to this site (which was the second result when searching for "CreateGLWindow" on google :wink) you have to provide that function yourself.
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way

pavellus

ok, but in the future, if i have function with given name X and i consider that this function is defined in a library, how could i find this file?

I added the following three libraries in my asm and i get unresolved ... message too :/
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glaux.lib")

includelib opengl32.lib
includelib glu32.lib
includelib gdi32.lib
includelib glaux.lib

Quote from: mnemonic on August 25, 2006, 02:40:33 PM
pavellus,

according to this site (which was the second result when searching for "CreateGLWindow" on google :wink) you have to privide that function yourself.

PBrennick

pavellus,
I have a program called Total Commander.  Using this program, I just browse to the include directory in masm32.  I then do a global search of all the include files searching for the specific function I need.  I am sure there are other ways, but to answer your question; search all the include files.  Doing this will tell you which .inc and .lib files you need to load in order to access the necessary DLL.

Paul
The GeneSys Project is available from:
The Repository or My crappy website

mnemonic

Quote from: pavellus on August 25, 2006, 02:50:31 PM
I added the following three libraries in my asm and i get unresolved ... message too :/

You have to implement that function yourself.
That means that you have to write it actually yourself. It is not a prebuilt function included in some DLL.
Go back to the site that I gave you the link to, scroll down and you will see it with your own eyes.

:wink
Be kind. Everyone you meet is fighting a hard battle.--Plato
-------
How To Ask Questions The Smart Way