"Technology and Water" discussion on dism++ cleaning plug-in development

Source: Internet
Author: User


Objective

Yesterday I released the Ncleaner, a dism++ cleanup plugin (address:http://bbs.pcbeta.com/viewthread-1692182-1-1.html)

Some people want my open source ncleaner; I can only say that it is regrettable that, given the domestic environment, it is impossible. Let me tell you a real story (it's sad)

Once, a Daniel wrote a software full of black technology, published in the Forum and published the source code
One day, the Daniel found that some people modify his source code for commercial purposes, more exasperating is that some people only modified the name of the software
In the end, the Daniel changed his software name and never released the main program source code.
That software is the DISM manager, the dism++ predecessor


Although Ncleaner closed source, but I can write an article dism++ Plug-in development tutorial as compensation (laughter)

Although I cannot guarantee how vivid the tutorial is, I will try to (laugh)

dism++, I can only say that this software is really very powerful (this is my personal view); As for reliability, If you don't die, turn on expert mode. (laughter)

When it comes to dism++ plug-in development, the author has previously provided the SDK (but it has never been provided in the world); last time I talked to the author about my idea of developing a plugin (hopefully the author can provide the SDK); and released Ncleaner (in the game-related discourse, I was also a week target person)

development environment Span style= "font-size:10pt" >

1.?? dism++ 10.1.5.3 and later versions of dism++ (not dism++ development dism++ plugin is not possible)
2. A C + + compiler that can compile DLLs, I recommend using Visual Studio
3. If you can, It is best to install the Windows SDK 10.0.10586


dism++ Cleanup Plugin related content Popular Science

First dism++ clean up the plug-in function definition (refer to the dism++ Help document. PDF 68 page)

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
An image session that can be used to obtain various information about the image (which can be treated as a handle to an image session)

DWORD Flags
Reserved, dism++ does not use this parameter now, please ignore

UINT64 *cleanupspace
If Cleanupspace is empty, then the function needs to perform cleanup.
If it is not empty, the description is only to estimate the space that can be cleaned. Finally, the estimated size is returned with this variable

Dismcallback CallBack
dism++ Cleanup callback function for displaying progress, file path and other information.
If this parameter is NULL, no callback is indicated.
callback function definitions refer to the next paragraph

LPVOID UserData
UserData part of the callback function, be sure to pass in the CallBack.


Return value: If the function executes successfully, return S_OK, and any other value represents an error

callback function definition

typedef DWORD (WINAPI *dismcallback) (
DWORD Dwmessageid,
WPARAM WPARAM,
LPARAM LPARAM,
PVOID UserData);


The callback function supports the following message:

dism_msg_progress– for feedback processing progress
WParam = Current percent complete
LParam = 0

Dism_msg_process?? – Used to show the path of the file being processed in the status bar
WParam = (PWSTR) pszfullpath
LParam = 0

Dism_mgs_removeinfo
Report the files that the UI needs to be deleted, this message is only available for scanning, and will ignore this message when cleaned up
WParam = 0
LParam = (LPCWSTR) The file path to be deleted
dism++ When this message is received, the file path is displayed in the details.

I often use the dism++ API introduction (Want to help others)


HRESULT WINAPI Dismgetsysteminfobysession (
dismsession Session,
dismsystem** Info);
The API function is to get the current image information; you get a pointer to the DISMSYSTEM structure (see dism++ Author's description of the structure, I think you should all understand)

HRESULT WINAPI dismfreememory (void* PSTRUCT);
Remember that structure pointers obtained through dism++ need to be freed with the API

HRESULT WINAPI dismregopenkeyex (
dismsession Session,
HKEY HKEY,
LPCWSTR Lpsubkey,
Regsam samdesired,
Phkey phkresult);
Get registry key value, usage similar to RegOpenKeyEx

HRESULT WINAPI dismwritelog (
DWORD LogLevel,
lpcwstr LogName,
LPCWSTR Logvalue);
Write log, loglevel defined as follows, LogName is the log category, Logvalue is the log content
Dismloglevelsilent do not output any information
Dismloglevelfailure error only
Dismloglevelwarning errors and Warnings
dismloglevelinformation errors, warnings, and information
Dismlogleveldebug all content and debug output

plug-in development considerations Span style= "font-size:10pt" >


1. dism++ is based on CBS, and CBS is a COM component, so COM initialization is done automatically at startup; You do not need to perform COM initialization in the cleanup plug-in function; Do not call COM anti-initialization in the cleanup plug-in function, or the consequences of me and dism++ 's authors do not dare to think ( Of course not to try)
2. Note that the path to the rootpath of the Dismsystem structure is similar to "C:", "D:\Image" (note when writing a file operation code)
3. The dism++ expansion environment variable API is limited to
4 offline. Dism++ 's open Registry API does not support opening an offline image HKEY_USERS (dism++ older version support; only the author has removed it); HKEY_CURRENT_USER opens the registry
for the default user. Span style= "font-family:arial" >
plugin development tutorial


Configure the environment, open visual Studio, first create a new Win32 dynamic link library project
and then copy the contents of 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 (for example)

#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

Getting Started with dism++ cleanup plugin development
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 (also for example)

LIBRARY

Exports
TestCleanup


And you need to write dism++ plug-in configuration file (need to name custom.xml, below for an example)

<?xml version= "1.0" encoding= "Utf-8"?>
<Data>
?? <CleanCollection4>
? ? <item name= "cleanup project name" level= "2" >
? ?? ?<discription> Cleanup Project Description </Discription>
? ?? ?<warning> warning dialog box to display the content </Warning>
? ?? ?<group> Cleanup Project belongs to group </Group>
? ?? ? <scancollection>??
? ?? ??? <scan type= "Custom" >
? ?? ?? ? <Activate>
? ?? ?? ?? <custom procname= "Plugin dll corresponding to export symbol"/>
? ?? ?? ? </Activate>
? ?? ??? </Scan>
? ?? ?</scancollection>
? ? </Item>
?? </CleanCollection4>
</Data>


and dism++ plugin information file (need to be named Info.xml)

<?xml version= " 1.0 "encoding=" Utf-8 ",
<data>
?? <plugin>
? <Name> plugin name </name>
? <Version> fill in the version number of the plugin, e.g. 1.0.0.0</version>
?? </plugin>
?? <languages>
? <zh>
???? <FriendlyName> plug-in name (Chinese) </friendlyname>
???? < Decription> Plug-in Comment (Chinese) </decription>
? </zh>
?? <en>
???? <FriendlyName> plugin Name </friendlyname>
???? <Decription> plugin comments </decription>
? </en>
?? </languages>
</data>


Compile
A 64-bit DLL needs to be named PLUGIN.AMD64.DLL;32-bit DLLs that need to be named Plugin.x86.dll

Plugin.amd64.dll, Plugin.x86.dll, Custom.xml, Info.xml these four files need to be placed in a [plugin name]_[publisher name Base64 encryption, Publisher name requires 16 characters] directory, and the directory is copied into the dism++ directory \config\plugin directory can

and then open DISM + + can be debugged (visualstudio-> debug, attach to process)

Demo Project Download (requires VS2015)
http://pan.baidu.com/s/1o8znY7w


Conclusion

Finally, I have to remind developers who want to develop dism++ clean plug-ins, although the plugin is easy to write, but to pay attention to the details are many (writing tutorial, the landlord's experience more profound)

If you want to get more information, we recommend joining the dism++ official group (200783396) Discussion

Maori

"Technology and Water" discussion on dism++ cleaning plug-in development

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.