Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Doubts in Dll linking. 1

Status
Not open for further replies.

isaisa

Programmer
Joined
May 14, 2002
Messages
97
Location
IN
hi all,
i am not able to understand the concepts of how dll is getting linked to the calling application. Basically i came acroos some documents which states that the use of dll can be done at load time and at run time. i am not getting this concept of linking the dll at load time and at run time.

can some one explain me the internal working of how this dll gets loaded and getting linked [steps during the compilation of application who is calling dll function, linking steps ets.]. or links which will help me understanding the concepts.

Thanks in advance.
sanjay
 
1. create dll with source and header files.
2. compille and link it. Will result two files, one .lib and one .dll.

3. Use header files you have used in the dll in applications you make. Link them with the .lib which result in 2.

4. use application, but only with .dll resulted in 2. When using application you do not need the .lib file.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Thanks Ion Filipski for your help.
Sorry, I think i have not made my point clear in my previous post.
What i know about dynamic linking / late binding while writting C++ programs is the vtbl[virtual table creation internally by compiler] implementation internally. i would like to understand the internal implementation for dlls to acheive the dynamic linking.

Thanks,
sanjay
 
There is no difference when it is in a DLL or in the same file. A lot of "late bound virtual tables" you are using already from .DLL applications without thinking about what they are. For example WinAPI or ODBC API. There is C style OOP. For example
ShowWindow(hWnd, SW_SHOW);
this function invokes a function pointer from the virtual pointer of non documented structure HWND, and hWnd is the pointer to an instance of this structure. The C++ analog of calling would be:
hWnd->ShowWindow(SW_SHOW);
You can not call a function of HWND like this, but in MFC wrappers of WinAPI you can call a wrapper of this function like following:
m_pcWnd->ShowWindow(SW_SHOW);//CWnd::ShowWindow wrapper
On examples above you deal with virtual tables implicitly. So you do not know where virtual tables are and how they are represented. So am I. I do not know it exactly if ShowWindow is a virtual table function or not, but I you deal a lot with wirtual tables without knowing it. In example above you are not sure if there is a virtual table or not.
Other example, where you deal explicitly with virtual tables is when you are using COM or OLE2:
IDispatch* pDispatch;
CoCreateInstance(CLSID_XXXXX, .....&pDispatch....);
there pDispatch is a virtual table which represents a stub generated by OLE2/COM.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Thanks a lot for your explanation. The idea of dll is now clear. Thanks a lot again.

Sanjay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top