[Translator]: This article is from Alex Tilles in the Windows Developer Network (phase 2003 12th) published an article: "Writing Your Own and Install Code". This is an article with a certain amount of technical content, and it is believed that many developers need the technology described in this article, including several important technical points:
The use method of Rundll32.exe utility program;
Self-deletion technology of DLL or EXE;
embedding resources processing skills;
Lzcopy API use demonstration;
Compress.exe,expand.exe use instructions;
Summary
When I was writing "What to Do" (This is an application written by the author, small, very practical-the translator), I wanted to write a set of his own installation and uninstall code, the main purpose is to control the entire installation/uninstall process as users see the screen. In this article, we will discuss how to implement a self deletion executable program by using a deleted dynamic link library (DLL) to implement a program installation/uninstall. I believe many friends want to do this when they write Windows programs, this article will also show some very useful related technology, must let you eye-opening ...
Difficulties in implementing a self-removal uninstall program
The most challenging part of writing an uninstall program is how to get the uninstaller to delete itself after deleting the target program files and related directories. In addition, the uninstall program must also be able to operate on all Windows operating system platforms (Windows 9x, Windows NT, Windows 2000, Windows XP ...). Does not require the user to download any additional components. I searched the internet for some information about how to delete executable files, but most of the suggested solutions have a problem with being able to work on only one version of Windows. Some methods are implemented by modifying thread attributes, which generally results in timing problems. There are also some methods that run with serious errors that cannot be used at all. I was thinking of finding a better solution to implement the self deletion function of the executable program: Implement a self deletion executable program with a DLL that has been removed, thus breaking the limits of these methods.
Introduction to Rundll32.exe Utility program
It is well known that the code for a DLL usually needs to be loaded into memory before it can be executed, so how do you execute the code exported by a DLL without creating an EXE that loads and invokes the DLL? This is as follows: Each Windows operating system version starting with Windows 95 comes with a system utility: Rundll32.exe. It allows you to perform any functions that are output by some DLLs (but not all) as follows:
rundll32.exe DllName,ExportedfnName args
Exportedfnname is the function name of the DLL output. When you write a DLL for use by rundll32, you can declare the output function as follows:
extern "C" __declspec(dllexport) void CALLBACK FunctionName (
HWND hwnd,
HINSTANCE hInstance,
LPTSTR lpCmdLine,
int nCmdShow
)
{ ... }
Rundll32.exe calls the function according to the function parameter list, but according to experience, in fact, the parameter value is only one, and that is lpCmdLine, which receives the parameter value passed in when running rundll32.exe; __declspec (dllexport) The purpose is to output functions; extern "C" has modifiers for the output function name, such as: _functionname@16 (the size of the function argument is enforced in the name of the functions, see MSDN for a description of the DLL output function call specification). rundll32.exe loads the specified DLL and invokes the output function specified by the value of the lpCmdLine passed in by the args parameter. Official documentation for Rundll32.exe see MSDN Library related information (Q164787):
http://support.microsoft.com/default.aspx?scid=kb;en-us;164787