|
From: Rajat on 6 Feb 2006 05:19 Hi, I am trying to exit the appliction if it is already open in Uninstall_Init of setupdll.dll. I try with FindWindow, Named Mutex and directly sending message to the application to exit it. But none of them is working. I dont understand the strange behaviour of the Uninstall_Init. Can anybody else has observe this kind of behavior. Thanks in advance Rajat
From: Robert Scott on 6 Feb 2006 07:13 On 6 Feb 2006 02:19:37 -0800, "Rajat" <raj.rr7(a)gmail.com> wrote: >...I am trying to exit the appliction if it is already open in >Uninstall_Init of setupdll.dll. I try with FindWindow, Named Mutex and >directly sending message to the application to exit it. But none of >them is working.... Here is how I do it: //cesetup.cpp - the temporary DLL used by AppManager to close app before #include <windows.h> #include <tchar.h> #include <ce_setup.h> // in the SDK dir static const TCHAR c_szWNDCLASS_APP[] = _T("TuneLabPPC"); BOOL WINAPI DllMain(HANDLE hMod, DWORD dwReason, LPVOID lpvReserved) { return TRUE; } static HWND CloseRunningApp(void) { HWND hwnd = NULL; // close app if it is running hwnd = FindWindow(c_szWNDCLASS_APP, NULL); if (hwnd) { int ix; SendMessage(hwnd, WM_CLOSE, 0, 0L); // wait a bit for the app to close for (ix = 0; ix < 10; ix++) { Sleep(500); // wait 1/2 sec. hwnd = FindWindow(c_szWNDCLASS_APP, NULL); if(hwnd == NULL) break; } } Sleep(500); // wait 1/2 sec. return hwnd; } codeINSTALL_INIT Install_Init( HWND hwndParent, BOOL fFirstCall, // first time this function is being called? BOOL fPreviouslyInstalled, LPCTSTR pszInstallDir) { if( fPreviouslyInstalled ) if( CloseRunningApp() ) return codeINSTALL_INIT_CANCEL; return codeINSTALL_INIT_CONTINUE; } codeINSTALL_EXIT Install_Exit( HWND hwndParent, LPCTSTR pszInstallDir, WORD cFailedDirs, WORD cFailedFiles, WORD cFailedRegKeys, WORD cFailedRegVals, WORD cFailedShortcuts) { return codeINSTALL_EXIT_DONE; } codeUNINSTALL_INIT Uninstall_Init( HWND hwndParent, LPCTSTR pszInstallDir) { if (CloseRunningApp()) return codeUNINSTALL_INIT_CANCEL; else return codeUNINSTALL_INIT_CONTINUE; } codeUNINSTALL_EXIT Uninstall_Exit(HWND hwndParent) { return codeUNINSTALL_EXIT_DONE; } Robert Scott Ypsilanti, Michigan
From: Rajat on 7 Feb 2006 02:58 Hi Robert, Thanks for the reply. But here i am using MFC class so i am not able to FindWindow using the class name. so i try to find the window using the application name but no luck. Is there any way to set the class name in MFC application. Thanks in advance. Rajat Robert Scott wrote: > On 6 Feb 2006 02:19:37 -0800, "Rajat" <raj.rr7(a)gmail.com> wrote: > > >...I am trying to exit the appliction if it is already open in > >Uninstall_Init of setupdll.dll. I try with FindWindow, Named Mutex and > >directly sending message to the application to exit it. But none of > >them is working.... > > Here is how I do it: > > //cesetup.cpp - the temporary DLL used by AppManager to close app before > #include <windows.h> > #include <tchar.h> > #include <ce_setup.h> // in the SDK dir > > static const TCHAR c_szWNDCLASS_APP[] = _T("TuneLabPPC"); > > BOOL WINAPI DllMain(HANDLE hMod, DWORD dwReason, LPVOID lpvReserved) > { > return TRUE; > } > > static HWND CloseRunningApp(void) > { > HWND hwnd = NULL; > // close app if it is running > hwnd = FindWindow(c_szWNDCLASS_APP, NULL); > if (hwnd) > { > int ix; > SendMessage(hwnd, WM_CLOSE, 0, 0L); > // wait a bit for the app to close > for (ix = 0; ix < 10; ix++) > { > Sleep(500); // wait 1/2 sec. > hwnd = FindWindow(c_szWNDCLASS_APP, NULL); > if(hwnd == NULL) break; > } > } > Sleep(500); // wait 1/2 sec. > return hwnd; > } > > codeINSTALL_INIT Install_Init( > HWND hwndParent, > BOOL fFirstCall, // first time this function is being called? > BOOL fPreviouslyInstalled, > LPCTSTR pszInstallDir) > { > if( fPreviouslyInstalled ) > if( CloseRunningApp() ) > return codeINSTALL_INIT_CANCEL; > return codeINSTALL_INIT_CONTINUE; > } > > codeINSTALL_EXIT Install_Exit( > HWND hwndParent, > LPCTSTR pszInstallDir, > WORD cFailedDirs, > WORD cFailedFiles, > WORD cFailedRegKeys, > WORD cFailedRegVals, > WORD cFailedShortcuts) > { > return codeINSTALL_EXIT_DONE; > } > > codeUNINSTALL_INIT Uninstall_Init( > HWND hwndParent, > LPCTSTR pszInstallDir) > { > if (CloseRunningApp()) > return codeUNINSTALL_INIT_CANCEL; > else > return codeUNINSTALL_INIT_CONTINUE; > } > > codeUNINSTALL_EXIT Uninstall_Exit(HWND hwndParent) > { > return codeUNINSTALL_EXIT_DONE; > } > > Robert Scott > Ypsilanti, Michigan
|
Pages: 1 Prev: PPC 6700 built in GPS Next: Hooking into global Find system |