📄 ce_setup.cpp
字号:
#include <windows.h>
enum codeINSTALL_INIT {codeINSTALL_INIT_CONTINUE=0, codeINSTALL_INIT_CANCEL};
enum codeINSTALL_EXIT {codeINSTALL_EXIT_DONE=0,codeINSTALL_EXIT_UNINSTALL};
//
extern "C" __declspec(dllexport) codeINSTALL_INIT Install_Init(HWND hpar, BOOL fFirstCall, BOOL fPreviouslyInstalled, LPCTSTR pszSuggestedInstallDir)
{ // can either return "continue", or abort before we've even started the install
return codeINSTALL_INIT_CONTINUE;
}
extern "C" __declspec(dllexport) codeINSTALL_EXIT Install_Exit(HWND hpar, LPCTSTR pszChosenInstallDir, WORD cFailedDirs, WORD cFailedFiles, WORD cFailedRegKeys, WORD cFailedRegVals, WORD cFailedShortcuts)
{ // can either return "okay", or "uninstall what we've just installed"
// but we're going to return "okay" since it succeeded, and then delete the dummy files
// since we intend success by this. The dummy files were just a workaround
// around a bug in cabwiz, not a sign of failure.
wchar_t buf[MAX_PATH]; wcscpy(buf,pszChosenInstallDir);
wcscat(buf,L"\\ce_setup_dummyN.txt"); int len=wcslen(buf)-5;
buf[len]='1'; DeleteFile(buf);
buf[len]='2'; DeleteFile(buf);
buf[len]='3'; DeleteFile(buf);
buf[len]='4'; DeleteFile(buf);
// And now continue with the main work of installing:
MessageBox(hpar,L"Installing...",L"My App",MB_OK);
// ...
return codeINSTALL_EXIT_DONE;
}
enum codeUNINSTALL_INIT{codeUNINSTALL_INIT_CONTINUE=0, codeUNINSTALL_INIT_CANCEL};
enum codeUNINSTALL_EXIT {codeUNINSTALL_EXIT_DONE=0};
wchar_t install_dir[MAX_PATH];
extern "C" __declspec(dllexport) codeUNINSTALL_INIT Uninstall_Init(HWND hpar, LPCTSTR pszInstallDir)
{ // we can either return "continue", or "abort before we even start the uninstall
// We will abort if our application is already open.
// Note: first take this opportunity to recard the install_dir.
// That's because we'll need to refer to it in Uninstall_Exit, but the
// system fails to tell us it again. Hence the need to remember.
// It's safe to to remember in a global variable, since Uninstall_Init and _Exit
// are invoked in the same instance of the DLL.
wcscpy(install_dir,pszInstallDir);
//
HWND halready = FindWindow(L"MyMainClass",L"My App");
if (!halready) return codeUNINSTALL_INIT_CONTINUE;
MessageBox(hpar,L"Quit the program before uninstalling it",L"My App",MB_OK);
return codeUNINSTALL_INIT_CANCEL;
}
extern "C" __declspec(dllexport) codeUNINSTALL_EXIT Uninstall_Exit(HWND hpar)
{ // Here we do the main work of our uninstalling:
MessageBox(hpar,L"Uninstalling...",L"My App",MB_OK);
// ...
return codeUNINSTALL_EXIT_DONE;
}
BOOL WINAPI DllMain(HANDLE hMod, DWORD dwReason, LPVOID lpvReserved) {return TRUE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -