📄 deleteourself.cpp
字号:
/* * * deleteourself.cpp * * Copyright (C) 2006 Michael H. Overlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact at poster_printer@yahoo.com */#include "deleteourself.h"#include "winmain.h"#include "..\lib\types.h"#include "..\lib\utils.h"#include <windows.h>#include <shlobj.h>#define NOHANDLE_SLEEP_TIME 2000#define HAVEHANDLE_MAX_WAIT_TIME 10000#define HAVEHANDLE_SLEEP_TIME_SAFETY 500HINSTANCE g_hinstDLL;BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) { switch (fdwReason) { case DLL_PROCESS_ATTACH: g_hinstDLL = hinstDLL; break; case DLL_PROCESS_DETACH: break; default: break; } return TRUE;}extern "C" __declspec(dllexport) void CALLBACK DeleteOurself(HWND, HINSTANCE, LPTSTR lpCmdLine, int){ ulong ul1, ul2; if (::swscanf(lpCmdLine, TEXT("%ul %ul"), &ul1, &ul2) == 2) { HINSTANCE hInst = (HINSTANCE) MAKELPARAM(ul2, ul1); ::WaitForSingleObject(hInst, HAVEHANDLE_MAX_WAIT_TIME); // BECAUSE I'M NOT SURE RECONSTRUCTING AN HINSTANCE FROM HIWORD/LOWORD IS VALID ::Sleep(HAVEHANDLE_SLEEP_TIME_SAFETY); } else { ::Sleep(NOHANDLE_SLEEP_TIME); } // NOTE -- WHETHER THE USER CANCELED THE UNINSTALL OR NOT, WE ALWAYS NEED TO // DELETE THIS DLL, BECAUSE THE UNINSTALL BEGINS BY AN EXE STUBB COPYING THIS // DLL STORED AS A RESOURCE TO A TEMP FILE AND THEN EXECUTING THIS ROUTINE USING // RUNDLL32 -- SO THE TEMP FILE DLL NEEDS TO BE ERASED IN ALL CASES DoUnInstallUI(g_hinstDLL); // DELETE OURSELF // TRICK FOUND AT http://www.ddj.com/showArticle.jhtml?documentID=win0312d&pgno=4 // "Writing Your Own Install and Uninstall Code", Dr.Dobb's Portal, Feb. 11, 2004, Alex Tilles TCHAR atstrFileNameDLL[MAX_PATH+2]; DWORD dw = GetModuleFileNameW(g_hinstDLL, atstrFileNameDLL, ARRCOUNT(atstrFileNameDLL)); if (dw != 0 && dw < ARRCOUNT(atstrFileNameDLL)) { __asm { lea eax, atstrFileNameDLL push 0 push 0 push eax push ExitProcess push g_hinstDLL push DeleteFile push FreeLibrary ret } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -