Solved

DLL Questions Series, 3

Posted on 2000-02-16
12
279 Views
Last Modified: 2010-04-02
This is the second part of the series.
The Overview can be found at:
http://www.experts-exchange.com/jsp/qShow.jsp?ta=cplusprog&qid=10294044 
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"?
0
Comment
Question by:Lescha
  • 6
  • 5
12 Comments
 
LVL 1

Author Comment

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

Expert Comment

by:rwilson032697
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.

Cheers,
Raymond.
0
 
LVL 11

Expert Comment

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

  http://www.experts-exchange.com/bin/Q.10032070
  http://www.experts-exchange.com/jsp/qShow.jsp?ta=cprog&qid=10119315 
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 11

Expert Comment

by:alexo
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.
0
 
LVL 11

Expert Comment

by:alexo
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).
0
 
LVL 1

Author Comment

by:Lescha
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.
0
 
LVL 1

Author Comment

by:Lescha
ID: 2532160
Adjusted points to 100
0
 
LVL 1

Author Comment

by:Lescha
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.
0
 
LVL 11

Expert Comment

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

Accepted Solution

by:
alexo earned 100 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.

  http://www.borland.com/bcppbuilder/freecompiler/
0
 
LVL 1

Author Comment

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

"nietod", "alexo".

Next part will be posted shortly.
0
 
LVL 1

Author Comment

by:Lescha
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.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Template syntax for variable length arrays 9 75
FMX StringGrid1->Canvas->FillRect Problem 3 170
IdTCPClient1->Disconnect(); not working 3 76
Best book to learn C++ 4 84
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
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.

840 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