|
#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;}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Lucian studied theoretical computer science in Cambridge and Bologna, and then moved into the computer industry. Since 2004 he's been paid to do what he loves -- designing and implementing programming languages! The articles he writes on CodeProject are entirely his own personal hobby work, and do not represent the position or guidance of the company he works for. (He's on the VB/C# language team at Microsoft).