Realize the anti-compilation of the help file under the Windows platform

zhaozj2021-02-16  81

Realize the anti-compilation of the help file under the Windows platform

http://91mail.51.net

Abstract: This article discusses the meaning of anti-compilation of CHM and HLP types and its anti-compilation tools. This paper introduces the creation of the process in Win32 program, the creation of resources in C Builder and the difference between the creation and management of resources in VC.

Keywords: HLP, CHM, API, Anti-compilation, Process, C Builder, TresourceStream

CLC number: TP3 literature sign identification code B

The ease of use of software is largely affected by the quality of its help system, and excellent software must have excellent help systems. As a programmer, it is necessary to be able to make its own help system, but also able to compile these helps files, re-editing and modifying resources in these files, so how to extract resources in helper files must become a must Completed task.

The help files used in the Windows system have two formats, extension of files named HLP and CHM files. HLP file is an earlier help file, currently using the CHM file. Nowadays, the tools of the anti-compilation help files at home and abroad are very small, the author has found such a tool on the Internet, but the procedures under DOS, it is difficult to operate, and the interface is not very friendly, so the program under Windows is Quite necessary. There are two options for making this tool, one is code transplant, one is to add a Windows shell for the DOS program. The first way is more cumbersome, I choose the second way. The following is a tool for transplanting the DOS program of the anti-compilation HLP file to make tools used in Windows.

There are two technical points of this tool implementation:

1. The creation of the background process

2. How to achieve resource separation in C Builder

1. Creation of the background process:

In WIN32, in order to ensure the independence between multitasking, multiple processes can be used when each module can be separately executed. Creating a process can use the createProcess function.

The original shape of this function is

Bool createprocess

LPCTSTR LPAPPLICATIONNAME,

LPCTSTR LPCOMMANDLINE,

LPSecurity_attributes LPPROCESSATTRIBUTES,

LPSecurity_attributes LPTHREADATIADATTRIBUTES,

Bool binherithandles,

DWORD DWCREATIONFLAGS,

LPVOID LPENVIRONMENT,

LPCTSTR LPCURRENTDIRECTORY,

LPStartupinfo LPstartupinfo,

LPPROCESS_INFORMATION LPPROCESSINFORMATION

)

The CreateProcess function is a Windows API function, its meaning is included in the Windows.h header file. Its parameters are more complicated, and the meaning of each parameter is described below:

LPApplicationName points to the string of executable file name, pay attention to the full name.

LPCommandline points to the string of the command line of the executable application. If lpapplicationname and lpcommandline are empty, the lpapplicationName specifies the execution module, and lpCommandline specifies the command line. If any one is empty, Windows uses the one who is not empty to call the executable.

LPPRocessAttributes point to a secure structure to illustrate the security properties of the creation process.

LPTHREADATTRIBUTES is used to specify the security properties of the primary thread that creates the process.

BinheritHandles decides whether the new process inherits the handle from the calling process. If it is true, then the process in which each can inherit is invoked. DWCREATIONFLAGS is an additional sign for a new process.

LpenVironment points to an environment block for a new process. If this parameter is empty, the new process uses the environment where the calling process is called.

LPCurrentDirectory points to a string that specifies the process to specify the current work drive and directory, must be a full path name. If this string is empty, the new process uses the current work driver and work directory that calls the process.

LPStartupInfo points to the StartupInfo structure that is used to specify how the new process is started to display.

The LPProcessInformation parameter points to a process_information structure that is used to accept identification information about the new process.

In addition to creating processes with the CreateProcess function, you can also use the Winexec function and the loadModule function. Winexec is derived from a Windows3.1 operating system, but still available in Win32. The Winexec function is more simpler than the CreateProcess function, but it is much less controlled or secure. This function is as follows:

UINT WINEXEC (LPCSTR LPCMDLINE, UINT UCMDSHOW);

LPCMDLINE is the command line

Ucmdshow is the application window display method

The use of loadModule functions is also simpler than the CreateProcess function, its original shape is as follows:

DWORD loadModule

LPCSTR LPMODULENAME, / / ​​Point to the string of executable file name

LPVOID LPPARETERBLOCK / / Point to the LoadParms32 structure, the LoadParms32 structure defines the program parameters, including how to display, command parameters, etc.

);

If you want to end a process, you can call the exitprogress function or the TerminateProgress function. If you use EXITPROGRESS, all affiliated DLLs and threads of this process will be terminated.

2. How to achieve resource separation in C Builder:

C Builder is different from VC in the creation and reference of the resource. There is a dedicated resource editor in the VC, as long as resources are created in the resource editor and assign ID, then reference the ID is OK. Although VC This visual resource management is very convenient, it is always better than that of C Builder's resource management and reference. In C Builder, just use the Notepad to write according to the "Resource Name" file name (including path) "format, then save this file into the project in the file called RC. These resources that can be handled in the TResourceStream class after completing the above steps.

Please see the following code.

GetCurrentDirectory (Sizeof (CurrentPath), CurrentPath;

IF (fileListbox1-> filename! = "")

{

TMPPATH = filelistbox1-> filename.delete (fileEListBox1-> filename.length () - 3, 4);

CreatedIRectory (TmpPath.c_STR (), NULL); STRCPY (ANSISTRING (TMPPATH) Ansistring ("// helpdeco.exe")). C_str ());

Ret = getFileAttributes (EXEFILE); FileListBox1-> filename.c_str (), (ANSISTRING (TMPPATH) ANSISTRING ("// tmp.hlp")). c_str (), false; if (Ret = 0xffffffFFF)

{

TResourceStream & Rs = * New TresourceStream ((int) Hinstance, Ansistring ("HelpFile"), "HelpFile");

rs.savetofile (ANSISTRING (Exefile);

Delete & RS;

CMD = ANSISTRING (TMPPATH) "// HelpDeco.exe" "" "tmp.hlp";

SHOWMESSAGE (CMD); Proc_create_State = CreateProcess (Null, cmd.c_str (), null, null, false, null, null, tmp_c_str (), & sistartinfo, & piprocinfo;

IF (proc_create_state) showMessage ("Anti-Compile Success");

TerminateThread (piprocinfo.hprocess, 0); // Terminate process deletefile (Ansistring (Tmpath) "// HelpDeco.exe"). C_str ());

DELETEFILE ((ANSISTRING (TMPPATH) "// tmp.hlp"). C_str ());

}

}

Else

{

ShowMessage ("Please select the file you want to compile");

}

Conclusion: The purpose of this paper is to recommend a DOS program to the Windows program transplant. Tools made in this way can be implemented: Select files that need to be compiled to create a folder in the same directory as this file, and store the resources that are reflectively extracted. This tool passes through the author's multiple tests, stable operation, and less system resources, does not produce temporary junk files, basically able to meet the requirements of users.

references:

[1] Liang Qixin, Programming Master Proverbs, Electronic Industry Press, October 2003 First Edition

转载请注明原文地址:https://www.9cbs.com/read-14797.html

New Post(0)