有DLL 文件如何制作LIB文件?

happycoders 2003-08-23 06:02:10
...全文
154 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
kangfx 2003-09-08
  • 打赏
  • 举报
回复
谢谢dll2lib
功名半纸 2003-09-01
  • 打赏
  • 举报
回复
http://www.csdn.net/develop/read_article.asp?id=15689
有我很详细的解说!;)
caomuyong1 2003-08-31
  • 打赏
  • 举报
回复
兄弟,直接去网上找工具软件吧,好多呀。
nscboy 2003-08-31
  • 打赏
  • 举报
回复
http://www.vckbase.com/document/viewdoc.asp?id=613
hacke 2003-08-29
  • 打赏
  • 举报
回复
TDump.exe-Delphi 4 和 C++ Builder 3 提供

Impdef.exe 和 Implib.exe - C++ Builder 3提供

DumpBin.exe-VC5.0提供

Lib.exe-VC5.0提供
lgs 2003-08-26
  • 打赏
  • 举报
回复
注意,MS与Borland的的开发工具编译出来的Obj及Lib格式是不相同的;一个是COFF格式,一个是OMF格式,不可混用
lgs 2003-08-26
  • 打赏
  • 举报
回复
注意,MS与Borland的的开发工具编译出来的Obj及Lib格式是不相同的;一个是COFF格式,一个是OMF格式,不可混用
Kivic 2003-08-25
  • 打赏
  • 举报
回复
dll2lib工具,网上到处都有
Healer 2003-08-23
  • 打赏
  • 举报
回复
lihai:)
李_军 2003-08-23
  • 打赏
  • 举报
回复

常用工具:

TDump.exe-Delphi 4 和 C++ Builder 3 提供

Impdef.exe 和 Implib.exe - C++ Builder 3提供

DumpBin.exe-VC5.0提供

Lib.exe-VC5.0提供
李_军 2003-08-23
  • 打赏
  • 举报
回复
VC中的调用格式:

extern "C" __declspec(dllimport) int __stdcall ShowDialog( HWND hwnd,char* Msg );

.如带有__stdcall,则要求Lib文件中对应函数名称分裂,可有以下步骤生成Lib文件:

.用Impdef.exe生成def文件,格式为:Impdef def文件名 dll文件名

.手工调制def文件参数,如ShowDialog改为ShowDialog@8

.用Lib.exe生成lib文件,格式为:Lib /def:def文件名

.如声名中无__stdcall,默认调用格式仍为stdcall,但不要求名称分裂,用以下批处理文件MkLib.bat可生成Lib文件:

@echo off

if %1.==. goto error

impdef %1.def %1.dll

lib /def:%1.def

goto end

:error

echo Usage: MkLib DllName

echo Note: Don't add extension ".dll" to parameter "DllName"

:end
思危 2003-08-23
  • 打赏
  • 举报
回复
不错,收藏
approach 2003-08-23
  • 打赏
  • 举报
回复
http://support.microsoft.com/support/kb/articles/Q131/3/13.asp
------------------------------------------------------------
HOWTO: Create 32-bit Import Libraries Without .OBJs or Source
The information in this article applies to:
The Microsoft Library Manager (LIB.EXE), when used with:
Microsoft Visual C++, 32-bit Editions 2.0
Microsoft Visual C++, 32-bit Editions 2.1
Microsoft Visual C++, 32-bit Editions 4.0
Microsoft Visual C++, 32-bit Editions 5.0
This article was previously published under Q131313
SUMMARY
This article explains how to create an import library given a .DLL for which you have no source code or object modules. There is no 32-bit utility that can create an import library from a .DLL, as there was with 16-bit versions of Visual C++.

NOTE: This method may not work with DLLs generated with non-Microsoft development tools.
MORE INFORMATION
Normally, when building a .DLL or any target that exports functions or data items, an import library (and exports file) is generated as part of the linking process. But in the case of a third-party .DLL that does not ship with an import library, you may need to generate an import library in order to use the .DLL successfully using load-time dynamic linking. An import library is not needed for run-time dynamic linking.

There are two ways to create an import library given a .DLL:
Create a .DEF file for use with the LIB /DEF: command.
Stub out functions, and use the .OBJ files created to mimic the import/export relationships. Then use the LIB /DEF: command to create the import library.
Creating a .DEF file
The only time you can use a .DEF file to create an import library from a .DLL for which you do not have the source code or object modules is if the .DLL exports functions via a C interface. Specifically, the functions need to have been declared to use the C calling convention. This is specified by the _cdecl attribute, normally used in the prototype for the function. Note that if no attribute is specified, _cdecl is the default when /Gz (_stdcall is the default) or /Gr (_fastcall is the default) is not specified on the CL command line. The reason for this limitation is based on an assumption made by the LIB utility that all names are automatically exported without a leading underscore. This is only true for _cdecl function names.

Given a .DLL with functions exported via a C interface, you can create an import library by following these steps:
Use DUMPBIN /EXPORTS <.DLL file name> to obtain the list of exported symbols for the .DLL in question. The symbols appear in the "name" column of the table whose headings are "ordinal hint name."
Create a .DEF file that contains an EXPORTS section with the names of the functions listed in the "name" column of the DUMPBIN output.
For _cdecl functions, the symbol appears just as it would when used in the calling program. Just place this symbol in the EXPORTS section of the .DEF file.
Use LIB /DEF:<.DEF file name> to generate the import library and exports file. The base name of the import library will be the base name of the .DEF file. Use /OUT: to control the output library name.
Stubbing Out Functions
For exported functions that use calling conventions other than C, the situation is a little more complex. This is especially true when you consider C++ functions and the more complex name decoration schemes involved. To use this method, you must at least have the header file that describes the .DLL's interface.

To create stubbed functions from prototypes in a header file:
When "__declspec(dllimport)" is used in a prototype or declaration, change it to "__declspec(dllexport)."
For functions that do not return a value, for C functions in C source, and for C functions in C++ source code (used with the 'extern "C"' construct), replace the semicolon that terminates the function prototype with a matched pair of curly braces ("{}").
For C++ functions (global or member) that return a value, you must create a dummy body for the function, and return a dummy value of the proper type. (Not having a return statement in the function is illegal.) This goes for class member functions, as well. Keep in mind that the purpose of this procedure is to trick the LIB utility into generating the correct import library, so these dummy bodies have no effect.
For C++ classes, you can stub out the member functions by using the prototypes in the class declaration, as long as you disable function inlining when you compile.
Function arguments are usually just specified by type in a header file. For example, Geta(int). A dummy argument identifier must be specified when adding the dummy function body Geta(int x). Otherwise the error C2055 is generated.
Example
If the header file that describes MYDLL.DLL looks like: // mydll.H

extern "C" __declspec(dllimport) void _stdcall Function(void);

class __declspec(dllimport) CMyClass {
int a;
long b;
public:
int Geta(int);
long Getb();
CMyClass();
};

The dummy source file you use to build the import library should look like: // mydll.CPP

extern "C" __declspec(dllexport) void _stdcall Function(void) {}

class __declspec(dllexport) CMyClass {
int a;
long b;
public:
int Geta(int x) {return 111;}
long Getb() {return 111;}
CMyClass() {}
};

Once the functions are stubbed out, all you need to do is compile the source file into an .OBJ file:
CL /c /Ob0 mydll.CPP

NOTE: Disabling function inlining is required to force generation of symbols for the functions defined in CMyClass. If function inlining were enabled, the compiler would notice that there are no references to the member functions in the translation unit, so it would discard the function bodies. See the discussion on inline function expansion under Optimizations in the Visual C++ CL Command line reference.

Once you have .OBJ files, you can use LIB /DEF: to create the import library (.LIB) and exports file (.EXP):
LIB /DEF: mydll.OBJ

For more information on the LIB command, consult the "LIB Reference" in the Visual C++ Books Online.

Also, see the following article in the Microsoft Knowledge Base:
140485 Exporting PASCAL-Like Symbols in 32-bit DLLs

xtmzl 2003-08-23
  • 打赏
  • 举报
回复
编译出了 DLL 的同时,不就有了LIB了吗。

如果只有一个dll,你想得到lib,就找发布这个dll的人了。
不然。没有其它的办法了。
up

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧