Listing 4 A decompressing installer
// install.h // #define RC_BINARYTYPE 256 #define ID_COMPRESSED_SETUP 100 // // install.rc // #include "install.h" ID_COMPRESSED_SETUP RC_BINARYTYPE AppSetup.ex_ // // install.cpp // #include <windows.h> #include "install.h" void WriteResourceToFile(HINSTANCE hInstance, int idResource, char const *filename) { // see Listing 3 } void DecompressFile(char const *source, char const *dest) { OFSTRUCT ofs; ofs.cBytes = sizeof(ofs); int zhfSource = LZOpenFile(const_cast<char *>(source), &ofs, OF_READ); int zhfDest = LZOpenFile(const_cast<char *>(dest), &ofs, OF_CREATE | OF_WRITE); LZCopy(zhfSource, zhfDest); LZClose(zhfSource); LZClose(zhfDest); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WriteResourceToFile(hInstance, ID_COMPRESSED_SETUP, "AppSetup.ex_"); DecompressFile("AppSetup.ex_", "AppSetup.exe"); DeleteFile("AppSetup.ex_"); // launch AppSetup.exe PROCESS_INFORMATION procInfo; STARTUPINFO startInfo; memset(&startInfo, 0, sizeof(startInfo)); CreateProcess(0, "AppSetup.exe", 0, 0, FALSE, NORMAL_PRIORITY_CLASS, 0, 0, &startInfo, &procInfo); }