Convert an EXE file to a DLL file in VC

Source: Internet
Author: User

Convert an EXE file to a DLL file in VC



Speaking of the method here, we have to say that VC is the function of each file generated in it:

. DSP engineering file, in text format, cannot be lost or damaged
When the. DSW workspace file is lost or damaged, you can click. DSP file to open the project and the. DSW file is automatically rebuilt.
. CLW classwizard information file, INI format, classwizard can be deleted and rebuilt if a problem occurs
. Map image information file. If you do not know the function export sequence when compiling the dll Write. Def file, you can select it on the prject/settings/link page.
"Generate mapfile", re-build, use notepad or other similar programs to open the generated. map file, which shows the function export table
. I enter Cl *** in the command line environment ***. CPP/P (note that the parameter P is case sensitive), which is generated in the program folder. I file, open it with notepad or other similar programs, you can see. results of the CPP file after preprocessing. NCB does not compile the browsing file. When the function is automatically completed (the list of member variables is automatically displayed), you can delete it and re-build it automatically.
Others:
. APS resource auxiliary file, in binary format
. Opt development environment parameters (such as tools

Location) File
. PLG compilation information (such as error and warning information) file, in HTML Format
. PCH pre-compiled files can speed up compilation, but the file size is very large.
. PDB Records Program-related data and debugging information
. Exp DLL information file, generated only when the DLL is compiled
. BSC is used to browse project information.
"Generate browse info file" is removed from the prject/settings/link page ",
Prohibit generation of. bsc files to accelerate compilation. However, if source browser is used
This file is required.
The other files that are useful to us today are the *. DSP file, which stores some configuration information of the project. Therefore, to achieve our goal today, we need to change the configuration information in * .dsp. in this way, we can convert a. EXE file into the DLL file we need.
Now let's get started:
1> create three VC projects. The names are: demodll(.exe generated by the dialogclass, which is used to convert it to the DLL file we want) DLL (default mfc dll) and calldall (the dialog class is used to call the DLL file we convert)
2> open the demodll. dsp dll. DSP file respectively.
Demodll. DSP
# Microsoft developer studio project file-name = "demodll"-package owner = <4>
# Microsoft developer studio generated Build File, format version 6.00
# ** Do not edit **

# Targtype "Win32 (x86) Application" 0x0101

CFG = demodll-Win32 debug
! Message this is not a valid makefile. To build this project using nmake,
! Message use the export makefile command and run
! Message
! Message nmake/F "demodll. Mak ".
! Message
! Message You can specify a configuration when running nmake
! Message by defining the macro CFG on the command line. For example:
! Message
! Message nmake/F "demodll. Mak" cfg = "demodll-Win32 debug"
! Message
! Message possible choices for configuration are:
! Message
! Message "demodll-Win32 release" (based on "Win32 (x86) application ")
! Message "demodll-Win32 debug" (based on "Win32 (x86) application ")
! Message

# Begin project
# Prop allowperconfigdependencies 0
# Prop scc_projname ""
# Prop scc_localpath ""
Cpp1_cl.exe
Mtl1_midl.exe
Rscloud rc.exe

! If "$ (CFG)" = "demodll-Win32 release"

# Prop base use_mfc 6
# Prop base use_debug_libraries 0
# Prop base output_dir "release"
# Prop base intermediate_dir "release"
# Prop base target_dir ""
# Prop use_mfc 6
# Prop use_debug_libraries 0
# Prop output_dir "release"
# Prop intermediate_dir "release"
# Prop target_dir ""
# Add base CPP/nologo/MD/W3/GX/O2/D "Win32"/D "ndebug"/D "_ WINDOWS"/D "_ afxdll"/YU "stdafx. H "/FD/C
# Add CPP/nologo/MD/W3/GX/O2/D "Win32"/D "ndebug"/D "_ WINDOWS"/D "_ afxdll"/D "_ MBCS "/YU" stdafx. H "/FD/C
# Add base MTL/nologo/D "ndebug"/mktyplib203/Win32
# Add MTL/nologo/D "ndebug"/mktyplib203/Win32
# Add base RSC/L 0x804/D "ndebug"/D "_ afxdll"
# Add RSC/L 0x804/D "ndebug"/D "_ afxdll"
Bsc321_bscmake.exe
# Add base bsc32/nologo
# Add bsc32/nologo
Link321_link.exe
# Add base link32/nologo/subsystem: Windows/machine: i386
# Add link32/nologo/subsystem: Windows/machine: i386

! Elseif "$ (CFG)" = "demodll-Win32 debug"

# Prop base use_mfc 6
# Prop base use_debug_libraries 1
# Prop base output_dir "debug"
# Prop base intermediate_dir "debug"
# Prop base target_dir ""
# Prop use_mfc 6
# Prop use_debug_libraries 1
# Prop output_dir "debug"
# Prop intermediate_dir "debug"
# Prop target_dir ""
# Add base CPP/nologo/MDD/W3/GM/GX/Zi/OD/D "Win32"/D "_ debug"/D "_ WINDOWS"/D "_ afxdll "/YU" stdafx. H "/FD/GZ/C
# Add CPP/nologo/MDD/W3/GM/GX/Zi/OD/D "Win32"/D "_ debug"/d
"_ WINDOWS"/D "_ afxdll"/D "_ MBCS"/YU "stdafx. H"/FD/GZ/C
# Add base MTL/nologo/D "_ debug"/mktyplib203/Win32
# Add MTL/nologo/D "_ debug"/mktyplib203/Win32
# Add base RSC/L 0x804/D "_ debug"/D "_ afxdll"
# Add RSC/L 0x804/D "_ debug"/D "_ afxdll"
Bsc321_bscmake.exe
# Add base bsc32/nologo
# Add bsc32/nologo
Link321_link.exe
# Add base link32/nologo/subsystem: Windows/debug/machine: i386/pdbtype: sept
# Add link32/nologo/subsystem: Windows/debug/machine: i386/pdbtype: sept

! Endif

# Begin target

# Name "demodll-Win32 release"
# Name "demodll-Win32 debug"
# Begin group "source files"

# Prop default_filter "CPP; C; cxx; RC; def; R; odl; IDL; HPJ; BAT"
# Begin source file

Source =./demodll. cpp
# End source file
# Begin source file

Source =./demodll. RC
# End source file
# Begin source file

Source =./demodlldlg. cpp
# End source file
# Begin source file

Source =./stdafx. cpp
# Add CPP/YC "stdafx. H"
# End source file
# End Group
# Begin group "header files"

# Prop default_filter "h; HPP; hxx; HM; INL"
# Begin source file

Source =./demodll. h
# End source file
# Begin source file

Source =./demodlldlg. h
# End source file
# Begin source file

Source =./resource. h
# End source file
# Begin source file

Source =./stdafx. h
# End source file
# End Group
# Begin group "resource files"

# Prop default_filter "ICO; cur; BMP; DLG; RC2; RDBMS; bin; RGS; GIF; JPG; JPEG; jpe"
# Begin source file

Source =./RES/demodll. ICO
# End source file
# Begin source file

Source =./RES/demodll. RC2
# End source file
# End Group
# Begin source file

Source =./readme.txt
# End source file
# End target
# End Project

DLL. DSP
# Microsoft developer studio project file-name = "DLL"-package owner = <4>
# Microsoft developer studio generated Build File, format version 6.00
# ** Do not edit **

# Targtype "Win32 (x86) Dynamic-Link Library" 0x0102

CFG = DLL-Win32 debug
! Message this is not a valid makefile. To build this project using nmake,
! Message use the export makefile command and run
! Message
! Message nmake/F "DLL. Mak ".
! Message
! Message You can specify a configuration when running nmake
! Message by defining the macro CFG on the command line. For example:
! Message
! Message nmake/F "DLL. Mak" cfg = "DLL-Win32 debug"
! Message
! Message possible choices for configuration are:
! Message
! Message "DLL-Win32 release" (based on "Win32 (x86) Dynamic-Link Library ")
! Message "DLL-Win32 debug" (based on "Win32 (x86) Dynamic-Link Library ")
! Message

# Begin project
# Prop allowperconfigdependencies 0
# Prop scc_projname ""
# Prop scc_localpath ""
Cpp1_cl.exe
Mtl1_midl.exe
Rscloud rc.exe

! If "$ (CFG)" = "DLL-Win32 release"

# Prop base use_mfc 6
# Prop base use_debug_libraries 0
# Prop base output_dir "release"
# Prop base intermediate_dir "release"
# Prop base target_dir ""
# Prop use_mfc 6
# Prop use_debug_libraries 0
# Prop output_dir "release"
# Prop intermediate_dir "release"
# Prop target_dir ""
# Add base CPP/nologo/MD/W3/GX/O2/D "Win32"/D "ndebug"/D "_ WINDOWS"/D "_ Windll"/D "_ afxdll "/YU" stdafx. H "/FD/C
# Add CPP/nologo/MD/W3/GX/O2/D "Win32"/D "ndebug"/D "_ WINDOWS"
/D "_ Windll"/D "_ afxdll"/D "_ MBCS"/D "_ usrdll"/YU "stdafx. H"/FD/C
# Add base MTL/nologo/D "ndebug"/mktyplib203/Win32
# Add MTL/nologo/D "ndebug"/mktyplib203/Win32
# Add base RSC/L 0x804/D "ndebug"/D "_ afxdll"
# Add RSC/L 0x804/D "ndebug"/D "_ afxdll"
Bsc321_bscmake.exe
# Add base bsc32/nologo
# Add bsc32/nologo
Link321_link.exe
# Add base link32/nologo/subsystem: Windows/dll/machine: i386
# Add link32/nologo/subsystem: Windows/dll/machine: i386

! Elseif "$ (CFG)" = "DLL-Win32 debug"

# Prop base use_mfc 6
# Prop base use_debug_libraries 1
# Prop base output_dir "debug"
# Prop base intermediate_dir "debug"
# Prop base target_dir ""
# Prop use_mfc 6
# Prop use_debug_libraries 1
# Prop output_dir "debug"
# Prop intermediate_dir "debug"
# Prop target_dir ""
# Add base CPP/nologo/MDD/W3/GM/GX/Zi/OD/D "Win32"/D "_ debug"
/D "_ WINDOWS"/D "_ Windll"/D "_ afxdll"/YU "stdafx. H"/FD/GZ/C
# Add CPP/nologo/MDD/W3/GM/GX/Zi/OD/D "Win32"/D "_ debug"/d
"_ WINDOWS"/D "_ Windll"/D "_ afxdll"/D "_ MBCS"/D "_ usrdll"
/YU "stdafx. H"/FD/GZ/C
# Add base MTL/nologo/D "_ debug"/mktyplib203/Win32
# Add MTL/nologo/D "_ debug"/mktyplib203/Win32
# Add base RSC/L 0x804/D "_ debug"/D "_ afxdll"
# Add RSC/L 0x804/D "_ debug"/D "_ afxdll"
Bsc321_bscmake.exe
# Add base bsc32/nologo
# Add bsc32/nologo
Link321_link.exe
# Add base link32/nologo/subsystem: Windows/dll/debug/machine: i386/pdbtype: sept
# Add link32/nologo/subsystem: Windows/dll/debug/machine: i386/pdbtype: sept

! Endif

# Begin target

# Name "DLL-Win32 release"
# Name "DLL-Win32 debug"
# Begin group "source files"

# Prop default_filter "CPP; C; cxx; RC; def; R; odl; IDL; HPJ; BAT"
# Begin source file

Source =./DLL. cpp
# End source file
# Begin source file

Source =./DLL. Def
# End source file
# Begin source file

Source =./DLL. RC
# End source file
# Begin source file

Source =./stdafx. cpp
# Add CPP/YC "stdafx. H"
# End source file
# End Group
# Begin group "header files"

# Prop default_filter "h; HPP; hxx; HM; INL"
# Begin source file

Source =./DLL. h
# End source file
# Begin source file

Source =./resource. h
# End source file
# Begin source file

Source =./stdafx. h
# End source file
# End Group
# Begin group "resource files"

# Prop default_filter "ICO; cur; BMP; DLG; RC2; RDBMS; bin; RGS; GIF; JPG; JPEG; jpe"
# Begin source file

Source =./RES/DLL. RC2
# End source file
# End Group
# Begin source file

Source =./readme.txt
# End source file
# End target
# End Project

Well, I have already marked the differences between the two files. Of course, we only need to modify the differences here. To implement our functions today, we only need to modify the ones marked above.
This is the modified demodll. DSP.
(1) # targtype "Win32 (x86) Dynamic-Link Library" 0x0102
(2 )! Message "demodll-Win32 release" (based on "Win32 (x86) Dynamic-Link Library ")
(3 )! Message "demodll-Win32 debug" (based on "Win32 (x86) Dynamic-Link Library ")
(4) # Add base CPP/nologo/MD/W3/GX/O2/D "Win32"/D "ndebug"/D "_ WINDOWS"/D "_ Windll"/D "_ afxdll "/YU" stdafx. H "/FD/C
(5) # Add CPP/nologo/MD/W3/GX/O2/D "Win32"/D "ndebug"/d
"_ WINDOWS"/D "_ Windll"/D "_ afxdll"/D "_ MBCS"/D "_ usrdll"
/YU "stdafx. H"/FD/C
(6) # Add base link32/nologo/subsystem: Windows/dll/machine: i386
(7) # Add link32/nologo/subsystem: Windows/dll/machine: i386
(8) # Add base CPP/nologo/MDD/W3/GM/GX/Zi/OD/D "Win32"/d
"_ Debug"/D "_ WINDOWS"/D "_ Windll"/D "_ afxdll"/YU "stdafx. H"/FD
/GZ/C
(9) # Add CPP/nologo/MDD/W3/GM/GX/Zi/OD/D "Win32"/D "_ debug"
/D "_ WINDOWS"/D "_ Windll"/D "_ afxdll"/D "_ MBCS"/D "_ usrdll"
/YU "stdafx. H"/FD/GZ/C
(10) # Add base link32/nologo/subsystem: Windows/dll/debug/machine: i386/pdbtype: sept
(11) # Add link32/nologo/subsystem: Windows/dll/debug/machine: i386/pdbtype: sept
Okay, that's all. The above is the modified demodll. the contents of the DSP file need to be modified in 13 places. In fact, there is nothing to do with it. As long as you can see it clearly, it will be OK.
Now, we can convert the file. Let's call it:
Calldll.exe:
Void ccalldlldlg: onok ()
{
// Todo: add extra validation here
Hinstance;
Hinstance =: loadlibrary (".. // demodll. dll ");
If (! Hinstance)
{
MessageBox ("loadlibrary is falied! ");
Return;
}
Freelibrary (hinstance );
Cdialog: onok ();
}
I will not post the specific execution results here. You can see the execution results after you execute them yourself.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.