DLL Questions Series, 3

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"?
Who is Participating?

Improve company productivity with a Business Account.Sign Up

alexoConnect With a Mentor Commented:
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.

LeschaAuthor Commented:
Oops, sorry... Naturally, it's the _third_ part of the series ;)
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.

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

** 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.
** 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).
LeschaAuthor Commented:
"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.
LeschaAuthor Commented:
Adjusted points to 100
LeschaAuthor Commented:
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.
It works with MS DLLs also.
Unfortunately the file is no longer there.  I'll search for a replacement...
LeschaAuthor Commented:
Thanks to all the Experts who participated in answering:

"nietod", "alexo".

Next part will be posted shortly.
LeschaAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.