[TECHNOLOGY · water] talking about Dism ++ plug-in development and dism
Preface
Yesterday I released NCleaner, A Dism ++ cleanup plug-in (Address: http://bbs.pcbeta.com/viewthread-1692182-1-1.html)
Some people want to open-source NCleaner. I can only say that it is a pity that it is impossible in view of the domestic environment. Let me tell you a real story (SADLY)
Once, a Daniel wrote a software full of black technology and published the source code on the forum.
One day, the Daniel found that some people modified his source code for commercial purposes. What's more, some people only modified the software name.
In the end, the Daniel changed his software name and never published the source code of the main program.
The software is the Dism manager, that is, the predecessor of Dism ++.
Although NCleaner closes the source, I can write a Dism ++ plug-in development tutorial as compensation (Laugh)
Although I cannot guarantee how vivid the tutorial is, I will try my best (Laugh)
Dism ++, I can only say that this software is really very powerful (this is just my personal opinion); As for reliability, as long as you don't turn on the expert mode, it's Okay (Laugh)
Speaking of Dism ++ plug-in development, in fact, the author has provided the SDK (but it has never been provided for a long time ); last time I talked with the author about my idea of developing plug-ins (I hope the author can provide the SDK). Finally, I got my wish and released NCleaner (in game-related words, I also spent a week)
Development Environment
1. Dism ++ 10.1.5.3 and later versions of Dism ++ (it is impossible to develop Dism ++ plug-ins without Dism ++)
2. a c ++ compiler that can compile dll. I recommend that you use Visual Studio 2015.
3. If you can, install Windows SDK 10.0.10586.
Dism ++ cleanup plug-in-related content Popular Science
First, let's talk about the definition Definition of dism?+ 文 page (for more information, see dism=68 68 68 68 68)
// A cleanup plug-in Function Definition
Hresult winapi CleanupPlugin (
_ In _ DismSession Session,
_ Reserved _ DWORD Flags,
_ In_opt _ UINT64 * CleanUpSpace,
_ In _ DismCallBack CallBack,
_ In _ LPVOID UserData );
DismSession Session
Image session, which can be used to obtain various information about the image (which can be seen as the handle of the image session)
DWORD Flags
Retained. Dism ++ does not use this parameter currently. Ignore this parameter.
UINT64 * CleanUpSpace
If CleanUpSpace is empty, the function needs to be cleaned up.
If it is not empty, only estimated space to be cleared is required. Use this variable to return the estimated size.
DismCallBack CallBack
The Dism ++ cleanup callback function is used to display progress, file path, and other information.
If this parameter is NULL, no callback is performed.
For more information about callback function definition, see the next section.
LPVOID UserData
The UserData section of the CallBack function must be passed in CallBack.
Returned value: if the function is successfully executed, S_ OK is returned. Any other value indicates an error.
Callback Function Definition
Typedef DWORD (WINAPI * DismCallBack )(
DWORD dwMessageId,
WPARAM wParam,
LPARAM lParam,
PVOID UserData );
The callback function supports the following messages:
DISM_MSG_PROGRESS-used to feedback processing progress
WParam = current completion percentage
LParam = 0
DISM_MSG_PROCESS-used to display the file path being processed in the status bar
WParam = (PWSTR) pszFullPath
LParam = 0
DISM_MGS_RemoveInfo
Report the file to be deleted by the UI. This message is only available for scanning and will be ignored during cleaning.
WParam = 0
LParam = (LPCWSTR) path of the file to be deleted
After receiving the message, Dism ++ displays the file path in the details.
I often use Dism ++ API introduction (to be useful to others)
Hresult winapi DismGetSystemInfoBySession (
DismSession Session,
DismSystem ** Info );
This API is used to obtain information about the current image. You will get a pointer to the DismSystem structure (see Dism ++'s description of this structure. I think you can understand it)
Hresult winapi DismFreeMemory (void * pStruct );
Remember to use this API to release the structure pointer obtained through Dism ++.
Hresult winapi DismRegOpenKeyEx (
DismSession Session,
HKEY hKey,
Lpwstr lpSubKey,
REGSAM samDesired,
PHKEY phkResult );
Obtains the registry key value. The usage is similar to RegOpenKeyEx.
Hresult winapi DismWriteLog (
DWORD LogLevel,
LPCWSTR LogName,
LPCWSTR LogValue );
Write logs. LogLevel is defined as follows. LogName is the log type and LogValue is the log Content.
DismLogLevelSilent does not output any information
DismLogLevelFailure is error only
DismLogLevelWarning errors and warnings
DismLogLevelInformation errors, warnings, and information
All the above content and debugging output of DismLogLevelDebug
Plug-in development considerations
1. dism ++ is based on CBS, while CBS is a COM component. Therefore, COM Initialization is automatically performed at startup. You do not need to execute COM Initialization in the cleaning plug-in function; do not call COM anti-initialization in the cleanup plug-in function; otherwise, neither Dism ++ nor I dare to think about it (of course I dare not try it)
2. Note that the path of the RootPath in the DismSystem structure is similar to "C:", "D: \ Image" (note this when writing file operation code)
3. The expanded environment variable API of Dism ++ is limited offline.
4. the open registry API of Dism ++ does not support opening the HKEY_USERS of offline images (supported by the Dism ++ old version; only the author removed it in a specific version); The HKEY_CURRENT_USER opens the registry of the Default User.
Plugin development tutorial
Configure the environment and open Visual Studio. First, create a Win32 dynamic link library project.
Then copy the Dism ++ SDK (Dism ++ directory \ Dism ++ SDK directory) to your project directory and add your solution
Then you can write the code you want to write in the cpp file based on the previous content (the following example is used)
# Include <Windows. h>
# Include "Dism ++ API. h"
# Include "Plugin. h"
# Ifdef _ AMD64 _
# Pragma comment (lib, "Dism ++ x64.lib ")
# Else
# Pragma comment (lib, "Dism ++ x86.lib ")
# Endif
// Dism ++ getting started with plug-in cleanup
Hresult winapi TestCleanup (
_ In _ DismSession Session,
_ Reserved _ DWORD Flags,
_ In _ UINT64 * CleanUpSpace,
_ In _ DismCallBack CallBack,
_ In _ LPVOID UserData)
{
MessageBoxW (nullptr, L "Hello Dism ++", L "HelloWorld", MB_ICONINFORMATION );
Return S_ OK;
}
By the way, you need to create a def file to export your symbols (for example)
LIBRARY
EXPORTS
TestCleanup
You also need to compile the Dism ++ plug-in configuration file (name Custom. xml, as shown in the following example)
<? Xml version = "1.0" encoding = "UTF-8"?>
<Data>
<CleanCollection4>
<Item Name = "cleanup project Name" Level = "2">
<Discription> clear the project description </Discription>
<Warning> content to be displayed in the Warning dialog box </Warning>
<Group> clear the Group to which the project belongs </Group>
<ScanCollection>
<Scan Type = "Custom">
<Activate>
<Custom ProcName = "Export symbol corresponding to plug-in dll"/>
</Activate>
</Scan>
</ScanCollection>
</Item>
</CleanCollection4>
</Data>
And Dism ++ plug-in information files (must be named Info. xml)
<? Xml version = "1.0" encoding = "UTF-8"?>
<Data>
<Plugin>
<Name> plug-in Name </Name>
<Version> enter the plug-in Version number, for example, 1.0.0.0 </Version>
</Plugin>
<Ages>
<Zh>
<FriendlyName> plug-in name (Chinese) </FriendlyName>
<Decription> plug-in comments (Chinese) </Decription>
</Zh>
<En>
<FriendlyName> plug-in name (English) </FriendlyName>
<Decription> plug-in comments (English) </Decription>
</En>
</Ages>
</Data>
Compile
The 64-bit dll must be named Plugin. amd64.dll; the 32-bit dll must be named Plugin. x86.dll.
Plugin. amd64.dll, Plugin. x86.dll, Custom. xml, Info. xml files need to be placed in a directory with the [plug-in name] _ [publisher name Base64 encrypted ciphertext; Publisher name requires 16 characters, copy the directory to the Dism ++ directory \ Config \ Plugin.
Then enable Dism ++ to debug (Visual Studio-> debug-> attach to the process)
Download Demo project (VS2015 required)
Http://pan.baidu.com/s/1o8znY7w
Conclusion
Finally, I have to remind developers who want to develop Dism ++ to clean up plug-ins. Although it is easy to write plug-ins, there are a lot of details to pay attention to. (During this tutorial, the author's experience becomes more profound)
For more information, we recommend that you join the Dism ++ official group (200783396 ).
Gross profit