Please note! This method can only be applied to the _ stdcall call method output in C format!
1. Use the dumpbin tool of VC ++ to export the export function table in DLL to a certain definition (. Def) file.
Example:
Dumpbin videodecoder. dll/exprots/out: videodecoder. Def
2. Sort the exported. Def file into a function export file that matches the. Def number.
Example:
The content of the videodecoder. Def file is as follows:
Dump of file videodecoder. dll
File Type: DLL
Section contains the following exports for videodecoder. dll
0 Characteristics
3d49e48f time date stamp Fri Aug 02 09:46:55 2002
0.00 version
1 ordinal Base
11 Number of functions
11 Number of names
Ordinal hint RVA name
1 0 00010f60 _ tm_cleardecoderbuff @ 4
2 1 00010e80 _ tm_closedecoder @ 4
3 2 00010f00 _ tm_decodepicture @ 4
4 3 00010ed0 _ tm_decodepictureheader @ 4
5 4 00010fd0 _ tm_getfileend @ 4
6 5 00011030 _ tm_getuvalue @ 4
7 6 00011060 _ tm_getvvalue @ 4
8 7 00011000 _ tm_getyvalue @ 4
9 8 00010e10 _ tm_opendecoder @ 8
10 9 00010f30 _ tm_returntype @ 4
11 A 00010f90 _ tm_setfileend @ 8
Summary
2000. Data
1000. RDATA
1000. reloc
15000. Text
Follow these steps:
1> Add lib instructions
Library "videodecoder"; "XX" is the DLL name
Description "videodecoder library"
2> remove content other than the description of the exported function. Add "exprots" to the Lib description to describe the exported function.
Library "videodecoder"
Description "videodecoder library"
Exports
Ordinal hint RVA name
1 0 00010f60 _ tm_cleardecoderbuff @ 4
2 1 00010e80 _ tm_closedecoder @ 4
3 2 00010f00 _ tm_decodepicture @
4 3 00010ed0 _ tm_decodepictureh
5 4 00010fd0 _ tm_getfileend @ 4
6 5 00011030 _ tm_getuvalue @ 4
7 6 00011060 _ tm_getvvalue @ 4
8 7 00011000 _ tm_getyvalue @ 4
9 8 00010e10 _ tm_opendecoder @ 8
10 9 00010f30 _ tm_returntype @ 4
11 A 00010f90 _ tm_setfileend @ 8
3> place all functions at the beginning of the row, remove the "hint" and "RVA" data, leave the function serial number "ordinal", and add the "@" symbol before the serial number.
Form the format "_ export function name @ parameter byte and @ serial number" (the function symbol used to call and export in the _ stdcall method is "function name @ parameter byte and ").
Finally, the. Def file is generated as follows:
Library "videodecoder"
Description "videodecoder library"
Exports
Tm_cleardecoderbuff @ 4 @ 1
Tm_closedecoder @ 4 @ 2
Tm_decodepicture @ 4 @ 3
Tm_decodepictureheader @ 4 @ 4
Tm_getfileend @ 4 @ 5
Tm_getuvalue @ 4 @ 6
Tm_getvvalue @ 4 @ 7
Tm_getyvalue @ 4 @ 8
Tm_opendecoder @ 8 @ 9
Tm_returntype @ 4 @ 10
Tm_setfileend @ 8 @ 11
3. Use the Lib tool of VC ++ with/DEF :(. Def file name)/machine: ix86 (80 x86 machine) to output lib files in the VC ++ format.
Example:
LIB/DEF: videodecoder. DEF/machine: ix86
4. when using the Lib File Link, note that when some dynamic library dumpbin only has the function name, there is no "@ nn" parameter format, such as the DLL written by C ++ builder, only the function name is output, and an error will be reported during the link:
Error lnk2002: unresolved external symbol "functionname @ nn"
The system prompts that the function symbols introduced in the program cannot be identified. In this case, you only need to change the corresponding function name in the def file to the functionname @ NN method and recreate the function.
Lib, relink it.
In this way, the lib that meets the VC call method is created!
Reference: msdn2000
It is worth noting that! Borland C ++ builder has a good tool impdef that can directly output functions in the DLL to The. Def file. If you make a little modification, it can become a Def file that complies with VC!
Impdef XXX. Def XXX. dll
This method can only be applied to the _ stdcall call method output in the C format. I have demonstrated some errors! I used Borland C ++ and VC ++ for demonstration and found that:
In C ++ builder!
_ Cdecl is preceded by "_"
_ Stdcall: No feature. Only the function name is output.
_ Fastcall function with a "@" in front of output "@"
No "@ nn" suffix format!
In VC!
_ Cdecl: No feature. Only the function name is output.
_ Stdcall function outputs with a "_" suffix "@ nn"
_ Fastcall function outputs with a "@" suffix "@ NN
You only need to convert the function declaration format in the def file of BC to the format recognized by VC, you can use the Lib tool to generate Lib, and use the C lattice output (extern "C") is required! And don't forget to include "_" in the function declaration in the def file! :) Otherwise, the Link error of error lnk2001 will appear!
If you want CB to call the vc dll, change the def file to a format that complies with the cb call habits:
Use impdef to export the def file and modify
VC CB
@ Fastcall @ NN @ fastcall
Cdeclcall _ cdeclcall
Then implib
Stdcall unchanged
I found that this method can also adapt to C ++-style DLL compilation, but it can only be used in the same language development tool! :)