MSI: make sure that dialogs are only created and destroyed in a single
thread (resend)
Mike McCormack
mike at codeweavers.com
Tue Apr 26 11:33:25 CDT 2005
This one uses a hidden window and SendMessage, at Alexandre's request.
Mike
ChangeLog:
* make sure that dialogs are only created and destroyed in a single
thread (resend)
-------------- next part --------------
? dlls/msi/version.res
Index: dlls/msi/action.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/action.c,v
retrieving revision 1.109
diff -u -p -r1.109 action.c
--- dlls/msi/action.c 20 Apr 2005 15:18:43 -0000 1.109
+++ dlls/msi/action.c 26 Apr 2005 16:27:57 -0000
@@ -631,7 +631,7 @@ static void ui_progress(MSIPACKAGE *pack
MSI_ProcessMessage(package, INSTALLMESSAGE_PROGRESS, row);
msiobj_release(&row->hdr);
- msi_dialog_check_messages(package->dialog, NULL);
+ msi_dialog_check_messages(NULL);
}
static void ui_actiondata(MSIPACKAGE *package, LPCWSTR action, MSIRECORD * record)
@@ -1421,7 +1421,7 @@ UINT ACTION_PerformUIAction(MSIPACKAGE *
if (!handled)
handled = ACTION_HandleDialogBox(package, action, &rc);
- msi_dialog_check_messages( package->dialog, NULL );
+ msi_dialog_check_messages( NULL );
if (!handled)
{
@@ -5421,7 +5421,7 @@ static UINT ACTION_SelfRegModules(MSIPAC
c_colon, &si, &info);
if (brc)
- msi_dialog_check_messages(package->dialog, info.hProcess);
+ msi_dialog_check_messages(info.hProcess);
HeapFree(GetProcessHeap(),0,filename);
msiobj_release(&row->hdr);
Index: dlls/msi/custom.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/custom.c,v
retrieving revision 1.11
diff -u -p -r1.11 custom.c
--- dlls/msi/custom.c 11 Apr 2005 16:10:33 -0000 1.11
+++ dlls/msi/custom.c 26 Apr 2005 16:27:57 -0000
@@ -372,9 +372,9 @@ static UINT process_handle(MSIPACKAGE* p
/* synchronous */
TRACE("Synchronous Execution of action %s\n",debugstr_w(Name));
if (ProcessHandle)
- msi_dialog_check_messages(package->dialog, ProcessHandle);
+ msi_dialog_check_messages(ProcessHandle);
else
- msi_dialog_check_messages(package->dialog, ThreadHandle);
+ msi_dialog_check_messages(ThreadHandle);
if (!(type & 0x40))
{
@@ -782,8 +782,7 @@ void ACTION_FinishCustomActions(MSIPACKA
{
TRACE("Waiting on action %s\n",
debugstr_w(package->RunningAction[i].name));
- msi_dialog_check_messages(package->dialog,
- package->RunningAction[i].handle);
+ msi_dialog_check_messages(package->RunningAction[i].handle);
}
HeapFree(GetProcessHeap(),0,package->RunningAction[i].name);
Index: dlls/msi/dialog.c
===================================================================
RCS file: /home/wine/wine/dlls/msi/dialog.c,v
retrieving revision 1.12
diff -u -p -r1.12 dialog.c
--- dlls/msi/dialog.c 11 Apr 2005 12:47:20 -0000 1.12
+++ dlls/msi/dialog.c 26 Apr 2005 16:27:57 -0000
@@ -44,6 +44,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(msi);
const WCHAR szMsiDialogClass[] = {
'M','s','i','D','i','a','l','o','g','C','l','o','s','e','C','l','a','s','s',0
};
+const WCHAR szMsiHiddenWindow[] = {
+ 'M','s','i','H','i','d','d','e','n','W','i','n','d','o','w',0
+};
const static WCHAR szStatic[] = { 'S','t','a','t','i','c',0 };
const static WCHAR szButton[] = { 'B','U','T','T','O','N', 0 };
@@ -106,6 +109,14 @@ static UINT msi_dialog_radiogroup_handle
static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
+/* dialog sequencing */
+
+#define WM_MSI_DIALOG_CREATE (WM_USER+0x100)
+#define WM_MSI_DIALOG_DESTROY (WM_USER+0x101)
+
+static DWORD uiThreadId;
+static HWND hMsiHiddenWindow;
+
INT msi_dialog_scale_unit( msi_dialog *dialog, INT val )
{
return (dialog->scale * val + 5) / 10;
@@ -725,41 +736,51 @@ static INT msi_dialog_get_sans_serif_hei
return height;
}
-static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
+/* fetch the associated record from the Dialog table */
+static MSIRECORD *msi_get_dialog_record( msi_dialog *dialog )
{
static const WCHAR query[] = {
'S','E','L','E','C','T',' ','*',' ',
'F','R','O','M',' ','D','i','a','l','o','g',' ',
'W','H','E','R','E',' ',
'`','D','i','a','l','o','g','`',' ','=',' ','\'','%','s','\'',0};
- static const WCHAR df[] = {
- 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
- msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
MSIPACKAGE *package = dialog->package;
MSIQUERY *view = NULL;
MSIRECORD *rec = NULL;
- DWORD width, height;
- LPCWSTR text;
- LPWSTR title = NULL;
UINT r;
- TRACE("%p %p\n", dialog, package);
-
- dialog->hwnd = hwnd;
- SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
+ TRACE("%p %s\n", dialog, debugstr_w(dialog->name) );
- /* fetch the associated record from the Dialog table */
r = MSI_OpenQuery( package->db, &view, query, dialog->name );
if( r != ERROR_SUCCESS )
{
ERR("query failed for dialog %s\n", debugstr_w(dialog->name));
- return -1;
+ return NULL;
}
MSI_ViewExecute( view, NULL );
MSI_ViewFetch( view, &rec );
MSI_ViewClose( view );
msiobj_release( &view->hdr );
+ return rec;
+}
+
+static LRESULT msi_dialog_oncreate( HWND hwnd, LPCREATESTRUCTW cs )
+{
+ static const WCHAR df[] = {
+ 'D','e','f','a','u','l','t','U','I','F','o','n','t',0 };
+ msi_dialog *dialog = (msi_dialog*) cs->lpCreateParams;
+ MSIRECORD *rec = NULL;
+ DWORD width, height;
+ LPCWSTR text;
+ LPWSTR title = NULL;
+
+ TRACE("%p %p\n", dialog, dialog->package);
+
+ dialog->hwnd = hwnd;
+ SetWindowLongPtrW( hwnd, GWLP_USERDATA, (LONG_PTR) dialog );
+
+ rec = msi_get_dialog_record( dialog );
if( !rec )
{
TRACE("No record found for dialog %s\n", debugstr_w(dialog->name));
@@ -1004,7 +1025,8 @@ static LRESULT WINAPI MSIDialog_WndProc(
{
msi_dialog *dialog = (LPVOID) GetWindowLongPtrW( hwnd, GWLP_USERDATA );
- TRACE(" 0x%04x\n", msg);
+ TRACE("0x%04x\n", msg);
+
switch (msg)
{
case WM_CREATE:
@@ -1020,13 +1042,43 @@ static LRESULT WINAPI MSIDialog_WndProc(
return DefWindowProcW(hwnd, msg, wParam, lParam);
}
+static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
+
+ TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
+
+ if (msg == WM_COMMAND) /* Forward notifications to dialog */
+ SendMessageW(GetParent(hWnd), msg, wParam, lParam);
+
+ return CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
+}
+
+static LRESULT WINAPI MSIHiddenWindowProc( HWND hwnd, UINT msg,
+ WPARAM wParam, LPARAM lParam )
+{
+ msi_dialog *dialog = (msi_dialog*) lParam;
+
+ ERR("%d %p\n", msg, dialog);
+
+ switch (msg)
+ {
+ case WM_MSI_DIALOG_CREATE:
+ return msi_dialog_run_message_loop( dialog );
+ case WM_MSI_DIALOG_DESTROY:
+ msi_dialog_destroy( dialog );
+ return 0;
+ }
+ return DefWindowProcW( hwnd, msg, wParam, lParam );
+}
+
/* functions that interface to other modules within MSI */
msi_dialog *msi_dialog_create( MSIPACKAGE* package, LPCWSTR szDialogName,
msi_dialog_event_handler event_handler )
{
+ MSIRECORD *rec = NULL;
msi_dialog *dialog;
- HWND hwnd;
TRACE("%p %s\n", package, debugstr_w(szDialogName));
@@ -1036,73 +1088,112 @@ msi_dialog *msi_dialog_create( MSIPACKAG
if( !dialog )
return NULL;
strcpyW( dialog->name, szDialogName );
+ msiobj_addref( &package->hdr );
dialog->package = package;
dialog->event_handler = event_handler;
+ dialog->finished = 0;
- /* create the dialog window, don't show it yet */
- hwnd = CreateWindowW( szMsiDialogClass, szDialogName, WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
- NULL, NULL, NULL, dialog );
- if( !hwnd )
+ /* verify that the dialog exists */
+ rec = msi_get_dialog_record( dialog );
+ if( !rec )
{
- ERR("Failed to create dialog %s\n", debugstr_w( szDialogName ));
- msi_dialog_destroy( dialog );
+ HeapFree( GetProcessHeap(), 0, dialog );
return NULL;
}
+ dialog->attributes = MSI_RecordGetInteger( rec, 6 );
+ msiobj_release( &rec->hdr );
return dialog;
}
+static void msi_process_pending_messages(void)
+{
+ MSG msg;
+
+ while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
+ {
+ TranslateMessage( &msg );
+ DispatchMessageW( &msg );
+ }
+}
+
void msi_dialog_end_dialog( msi_dialog *dialog )
{
+ TRACE("%p\n", dialog);
dialog->finished = 1;
+ PostMessageW(dialog->hwnd, WM_NULL, 0, 0);
}
-UINT msi_dialog_run_message_loop( msi_dialog *dialog )
+void msi_dialog_check_messages( HANDLE handle )
{
- MSG msg;
+ DWORD r;
- if( dialog->attributes & msidbDialogAttributesVisible )
+ /* in threads other than the UI thread, block */
+ if( uiThreadId != GetCurrentThreadId() )
{
- ShowWindow( dialog->hwnd, SW_SHOW );
- UpdateWindow( dialog->hwnd );
+ if( handle )
+ WaitForSingleObject( handle, INFINITE );
+ return;
}
- if( dialog->attributes & msidbDialogAttributesModal )
+ /* there's two choices for the UI thread */
+ while (1)
{
- while( !dialog->finished && GetMessageW( &msg, 0, 0, 0 ) )
- {
- TranslateMessage( &msg );
- DispatchMessageW( &msg );
- }
- }
- else
- return ERROR_IO_PENDING;
+ msi_process_pending_messages();
- return ERROR_SUCCESS;
+ if( !handle )
+ break;
+
+ /*
+ * block here until somebody creates a new dialog or
+ * the handle we're waiting on becomes ready
+ */
+ r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLINPUT );
+ if( r == WAIT_OBJECT_0 )
+ break;
+ }
}
-void msi_dialog_check_messages( msi_dialog *dialog, HANDLE handle )
+UINT msi_dialog_run_message_loop( msi_dialog *dialog )
{
- MSG msg;
- DWORD r;
+ HWND hwnd;
+
+ if( !(dialog->attributes & msidbDialogAttributesVisible) )
+ return ERROR_SUCCESS;
+
+ if( uiThreadId != GetCurrentThreadId() )
+ return SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_CREATE, 0, (LPARAM) dialog );
+
+ /* create the dialog window, don't show it yet */
+ hwnd = CreateWindowW( szMsiDialogClass, dialog->name, WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
+ NULL, NULL, NULL, dialog );
+ if( !hwnd )
+ {
+ ERR("Failed to create dialog %s\n", debugstr_w( dialog->name ));
+ return ERROR_FUNCTION_FAILED;
+ }
- do
+ ShowWindow( hwnd, SW_SHOW );
+ UpdateWindow( hwnd );
+
+ if( dialog->attributes & msidbDialogAttributesModal )
{
- while( PeekMessageW( &msg, 0, 0, 0, PM_REMOVE ) )
+ while( !dialog->finished )
{
- TranslateMessage( &msg );
- DispatchMessageW( &msg );
+ MsgWaitForMultipleObjects( 0, NULL, 0, INFINITE, QS_ALLEVENTS );
+ msi_process_pending_messages();
}
- if( !handle )
- break;
- r = MsgWaitForMultipleObjects( 1, &handle, 0, INFINITE, QS_ALLEVENTS );
}
- while( WAIT_OBJECT_0 != r );
+ else
+ return ERROR_IO_PENDING;
+
+ return ERROR_SUCCESS;
}
void msi_dialog_do_preview( msi_dialog *dialog )
{
+ TRACE("\n");
dialog->attributes |= msidbDialogAttributesVisible;
dialog->attributes &= ~msidbDialogAttributesModal;
msi_dialog_run_message_loop( dialog );
@@ -1110,6 +1201,12 @@ void msi_dialog_do_preview( msi_dialog *
void msi_dialog_destroy( msi_dialog *dialog )
{
+ if( uiThreadId != GetCurrentThreadId() )
+ {
+ SendMessageW( hMsiHiddenWindow, WM_MSI_DIALOG_DESTROY, 0, (LPARAM) dialog );
+ return;
+ }
+
if( dialog->hwnd )
ShowWindow( dialog->hwnd, SW_HIDE );
@@ -1142,7 +1239,7 @@ void msi_dialog_destroy( msi_dialog *dia
HeapFree( GetProcessHeap(), 0, dialog );
}
-void msi_dialog_register_class( void )
+BOOL msi_dialog_register_class( void )
{
WNDCLASSW cls;
@@ -1155,22 +1252,28 @@ void msi_dialog_register_class( void )
cls.lpszMenuName = NULL;
cls.lpszClassName = szMsiDialogClass;
- RegisterClassW( &cls );
-}
+ if( !RegisterClassW( &cls ) )
+ return FALSE;
-void msi_dialog_unregister_class( void )
-{
- UnregisterClassW( szMsiDialogClass, NULL );
-}
+ cls.lpfnWndProc = MSIHiddenWindowProc;
+ cls.lpszClassName = szMsiHiddenWindow;
-static LRESULT WINAPI MSIRadioGroup_WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- WNDPROC oldproc = (WNDPROC) GetPropW(hWnd, szButtonData);
+ if( !RegisterClassW( &cls ) )
+ return FALSE;
- TRACE("hWnd %p msg %04x wParam 0x%08x lParam 0x%08lx\n", hWnd, msg, wParam, lParam);
+ uiThreadId = GetCurrentThreadId();
- if (msg == WM_COMMAND) /* Forward notifications to dialog */
- SendMessageW(GetParent(hWnd), msg, wParam, lParam);
+ hMsiHiddenWindow = CreateWindowW( szMsiHiddenWindow, NULL, WS_OVERLAPPED,
+ 0, 0, 100, 100, NULL, NULL, NULL, NULL );
+ if( !hMsiHiddenWindow )
+ return FALSE;
- return CallWindowProcW(oldproc, hWnd, msg, wParam, lParam);
+ return TRUE;
+}
+
+void msi_dialog_unregister_class( void )
+{
+ DestroyWindow( hMsiHiddenWindow );
+ UnregisterClassW( szMsiDialogClass, NULL );
+ uiThreadId = 0;
}
Index: dlls/msi/msipriv.h
===================================================================
RCS file: /home/wine/wine/dlls/msi/msipriv.h,v
retrieving revision 1.53
diff -u -p -r1.53 msipriv.h
--- dlls/msi/msipriv.h 20 Apr 2005 12:50:05 -0000 1.53
+++ dlls/msi/msipriv.h 26 Apr 2005 16:27:58 -0000
@@ -368,10 +368,10 @@ typedef VOID (*msi_dialog_event_handler)
extern msi_dialog *msi_dialog_create( MSIPACKAGE*, LPCWSTR, msi_dialog_event_handler );
extern UINT msi_dialog_run_message_loop( msi_dialog* );
extern void msi_dialog_end_dialog( msi_dialog* );
-extern void msi_dialog_check_messages( msi_dialog*, HANDLE );
+extern void msi_dialog_check_messages( HANDLE );
extern void msi_dialog_do_preview( msi_dialog* );
extern void msi_dialog_destroy( msi_dialog* );
-extern void msi_dialog_register_class( void );
+extern BOOL msi_dialog_register_class( void );
extern void msi_dialog_unregister_class( void );
/* UI globals */
More information about the wine-patches
mailing list