[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


DLL Questions Series, 3

Posted on 2000-02-16
Medium Priority
Last Modified: 2010-04-02
This is the second part of the series.
The Overview can be found at:
The previous parts can be found at:
(1) http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=10294050 
(2) http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=10295050 

This question is not hard, but it can in my opinion grow into an interesting discussion.

"Polite" programmists will provide an .H file for there DLL, and also a .LIB file. But if one doesn't, and only ships out a .DLL file,

1) How does the potential user of a DLL know what exports can he use from this DLL?
2) How can he create a LIB from this DLL? (This was already discussed in Part 2 of the series, but since "nietod" couldn't name any specific utilities, I repeat the question here).
3) What other things must a DLL creator do in order to qualify for being "polite"?
Question by:Lescha
  • 6
  • 5

Author Comment

ID: 2529953
Oops, sorry... Naturally, it's the _third_ part of the series ;)
LVL 12

Expert Comment

ID: 2530066
Hi Lescha:

1) You can use QuickView (right-click on the DLL and select Quick View) for a list of exported function names if you do not have the .H file, otherwise the .H file descrive all you need to know.

2) If by .LIB you mean a compiled library, I am not sure if you can do this. If you mean a .DEF file containing the list of exports you can create this from the QuickView report.

3) A 'polite' DLL creator really just needs to ensure that a user of the DLL can acess the functions within it. To that end a .H file is really all that is required, though providing a .DEF/.LIB(?) file is a courtesy that allows easy setup of early bound DLLs.

Unfortunately, in the abscence of a .H file, a DLL is essentially useless if you cannot determine the arguments (from the author) for each function it contains. It is essentially not possible to determine the arguments from the DLL directly.

LVL 11

Expert Comment

ID: 2530519
I answered several questions about this issue.  URLs below, cut-n-paste in a forthcoming comments.

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

LVL 11

Expert Comment

ID: 2530525
** Q.10032070 "View DLL's" (5 pts) **

> where I can obtain a free View DLL's (see for each *.DLL the functions with sintax, parameters, etc) ?

** Accepted Answer **

(Assuming a Win32 platform and C language)

You can get the list of names that a DLL exports but function parameters are a different thing.

The easiest way of getting the list of exported names is to QuickView the DLL.  QuickView comes with every Win32 platform so no need to look elswhere.

Look for the section "Export table" for the exported names.

Now, some issues:

1) How to determine if the name refers to a function or a variable?

Each entry in the export table has an address.  Look for the "Sections" part to see which section the address resides in.  The section's characteristics state if it contains executable code.

2) Why there are some entries without names?

A DLL can export functions by name or by ordinal number (or both).  Functions exported by ordinal number only need an import library or a DEF file to be called by name (you cannot infer the name from the DLL).

3) What about parameters?

Due to the way parameters are passed, you cannot infer the parameters from the DLL (unless it's C++).

However, sometimes you'll see entries like _FunctionName@8

That means that the function FunctionName() takes 8 bytes of paramteres.  There is no way (aside from disassembly) to know if it is two 4-byte longs, four 2-byte shorts, eight chars or any combination thereof (and I'm not even talking about pointers, floating point types or structs).

More than that, depending on the calling convention, the parameters may be pushed on the stack in a left-to-rigt order, right-to-left order or passed in registers.

If it's C++ code, the function name is mangled (compiler specific) and contains the number and types of the parameters in the name.
LVL 11

Expert Comment

ID: 2530531
** Q.10119315 "Getting Parameters to DLL functions" (10 pts) **

If I have a dll, with exported functions, but no .lib or .h file. Is it possible to work out what parameters thoses functions take, and therefore do a GetProcAddress.. and call them ?

any clues anyone ?

** Combined Answers **

The general answer is no.
If the DLL functions use the __stdcall convention, you can see how many BYTES the function expects to be pushed on the stack from it's name (the format is funcname@num).  Most arguments will be 32bit integers or pointers so you can guess the number of arguments as num/4.

Also, Borland C++ comes with an IMPLIB program that is supposed to generate import libraries from DLL files.

A brief search showed that it is downloadable from:
     ftp.cs.uregina.ca/pub/class/250/class/MASM Disks
(As part of the MASM package).

Author Comment

ID: 2532155
"rwilson": by .lib I mean a static library containing stubs of functions within the .dll. See discussion of this point in Part 2 of the Series.


For all:

I will increase the points for this question to 100 that will go to the Expert naming one of those utilities that "nietod" mentioned in Part 2: the one to create a .lib from .dll.

This question remains open, but I will post Part 4 shortly.

Author Comment

ID: 2532160
Adjusted points to 100

Author Comment

ID: 2532165
Oh, and for "alexo": this IMPLIB you mentioned for Borland C++, does it work also on .dll that is generated with Visual Studio?

If no, it's not quite relevant.
If yes, please lock the answer.
LVL 11

Expert Comment

ID: 2535082
It works with MS DLLs also.
Unfortunately the file is no longer there.  I'll search for a replacement...
LVL 11

Accepted Solution

alexo earned 400 total points
ID: 2535182
OK, Borland (Inprise) is giving away their C++ compiler.  AFAIK, implib is part of the package.  Even if not, sounds like a good deal to me.


Author Comment

ID: 2535954
Thanks to all the Experts who participated in answering:

"nietod", "alexo".

Next part will be posted shortly.

Author Comment

ID: 2535971
I forgot to mention the Expert named "rwilson". Sorry about that.

Closing question does not necessarily ends the discussion, so if anyone has anything to add - about politeness or other things - feel free to do that.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question