If a DLL written in VC ++ is to be called by a program written in other languages, the function call method should be declared as _ stdcall. WINAPI adopts this method, the default call method of C/C ++ is _ cdecl. The _ stdcall method is different from the _ cdecl method for generating symbols for function names. If the C compilation method is used (the function must be declared as extern "C" in C ++), __stdcall indicates that the name of the output function must be underlined, add the "@" symbol and the number of bytes of the parameter, for example, "_ functionname" @ "number". The _ cdecl call Convention only underscores the name of the output function, such as _ functionname. If we do not use the. def file to declare the function name, but want to directly call the _ stdcall function,In addition, if C ++ is used for compilation, We need to get the compiled name of the function so that we can call it in other programs. We need to use the dumpbin tool provided by. Microsoft COFF binary file dump (DUMPBIN. EXE) displays information about common object file formats (COFF) binary files. You can use DUMPBIN to check COFF object files, standard COFF object libraries, executable files, and dynamic link libraries (DLL. Here is an example to illustrate:1. Create a C ++ DLL project in VS, such as dpSampleThe header file dpSample. h we write as follows 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src =" http://www.bkjia.com/uploads/allimg/131228/1R2005c4-0.gif "align =" top "/>#include <string>
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src =" http://www.bkjia.com/uploads/allimg/131228/1R2005c4-0.gif "align =" top "/> # include" stdio. h"
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src =" http://www.bkjia.com/uploads/allimg/131228/1R2005c4-0.gif "align =" top "/>
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src =" http://www.bkjia.com/uploads/allimg/131228/1R2005c4-0.gif "align =" top "/>
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src =" http://www.bkjia.com/uploads/allimg/131228/1R2005c4-0.gif "align =" top "/> using namespace std;
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src =" http://www.bkjia.com/uploads/allimg/131228/1R2005c4-0.gif "align =" top "/>
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src =" http://www.bkjia.com/uploads/allimg/131228/1R2005c4-0.gif "align =" top "/> # ifndef DPSAMPLE_H
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src =" http://www.bkjia.com/uploads/allimg/131228/1R2005c4-0.gif "align =" top "/> # define DPSAMPLE_H
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src =" http://www.bkjia.com/uploads/allimg/131228/1R2005c4-0.gif "align =" top "/>
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src =" http://www.bkjia.com/uploads/allimg/131228/1R2005c4-0.gif "align =" top "/>__ declspec (dllexport) void _ stdcall dumpbinTest (string src );
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src =" http://www.bkjia.com/uploads/allimg/131228/1R2005c4-0.gif "align =" top "/>
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src =" http://www.bkjia.com/uploads/allimg/131228/1R2005c4-0.gif "align =" top "/>
650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php? Refimg = "+ this. src) 'src =" http://www.bkjia.com/uploads/allimg/131228/1R2005c4-0.gif "align =" top "/> # After endif defines the function, we generate the DLL file dpSample. dll2. Go to the VS command line (Visual Studio command prompt)Enter the path where dpSample. dll is located and enter the command dumpbin/all dpSample. dll> dump.txtto enter the dump.txt file of the available information in dpsample.dll.3. Analyze the dump fileWhen we open the dump.txt file, we will find that the file itself is messy and contains a lot of content. Here we do not need to analyze it one by one row. We can directly Ctrl + F to find the original function name. In this example, It is dumpbinTest. the result is roughly as follows: Section contains the following exports for dpSample. dll
00000000 characteristics
4B307976 time date stamp Tue Dec 22 15:47:02 2009
0.00 version
1 ordinal base
1 number of functions
1 number of names
Ordinal hint RVA name
1 0 00011005? DumpbinTest @ YGXV? $ Basic_string @ DU? $ Char_traits @ D @ std @ V? $ Allocator @ D @ 2 @ std @ Z = @ ILT + 0 (? DumpbinTest @ YGXV? $ Basic_string @ DU? $ Char_traits @ D @ std @ V? $ Allocator @ D @ 2 @ std @ Z ">? DumpbinTest @ YGXV? $ Basic_string @ DU? $ Char_traits @ D @ std @ V? $ Allocator @ D @ 2 @ std @ Z) and the code in the final bracket is the name of our function after C ++ compilation !! Now we can use this function name in other programs to call this function.
This article is from the "harmonious HeXen" blog, please be sure to keep this source http://hexen.blog.51cto.com/1110171/247547