// NSIS Shell Execute Plugin // // Douglas Thrift // // $Id$ #include #include #include static char *popstring_alloc() { char *string = new char[::g_stringsize]; if (::popstringn(string, 0) || string == std::string("0", 1) || string == std::string("NULL", 4)) { delete [] string; return NULL; } return string; } extern "C" void __declspec(dllexport) Ex(HWND parent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra) { EXDLL_INIT(); SHELLEXECUTEINFO info; info.cbSize = sizeof (info); info.fMask = ::popint_or(); info.hwnd = parent; info.lpVerb = ::popstring_alloc(); info.lpFile = ::popstring_alloc(); info.lpParameters = ::popstring_alloc(); info.nShow = ::popint(); info.lpIDList = NULL; if (info.fMask & SEE_MASK_CLASSNAME) info.lpClass = ::popstring_alloc(); info.hkeyClass = NULL; info.dwHotKey = 0; info.hMonitor = NULL; int code; if (code = ::ShellExecuteEx(&info)) ::pushint(reinterpret_cast(info.hProcess)); else { char *message; ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, ::GetLastError(), 0, reinterpret_cast(&message), sizeof (message), NULL); ::pushstring(message); ::LocalFree(message); } ::pushint(code); delete [] info.lpVerb, delete [] info.lpFile; delete [] info.lpParameters; }