The TWAIN data sources sane.ds and gpoto.ds create progress dialogs with the WIN32 CreateDialog API in files ui.c
When they need to destroy these windows, they call EndDialog. But EndDialog is meant for Modal Dialogs created by DialogBox, DialogBoxParam, DialogBoxInd and the like. Calling it for dialogs created by CreateDialog is undocumented behaviour.
In the end, those progress dialogs are not destroyed (immediatly?) and can still be open when the application program closes the data source with the message.
DG_CONTROL / DAT_IDENTITY / MSG_CLOSEDS
This can then later cause a segfault if the sane.ds/gpoto2.ds gets unloaded with FreeLibrary so the dialog box procedure is no longer in memory. There is a workaround for this in dlls/twain_32/dsm_ctrl.c:220:
``` /* This causes crashes due to still open Windows, so leave out for now. * FreeLibrary (currentDS->hmod); */ ```
But the TWAIN organization offers their own DSM-Library twaindsm.dll, that does not contain this workaround so segfaults after an otherwise successful scan:
https://github.com/twain/twain-dsm
Using this patch, progress dialogs are closed with DestroyWindow instead of EndDialog and these segfaults do not occur any more. This would also allow to change the code in dsm_ctrl.c:220 to FreeLibrary the DS module again. I've tested that it works. But there is no evidence that that change would have benefits and it might have other disadvantages.
Compatibility of twaindsm.dll with sane.ds requires one of my previous merge requests that are not yet in wine main tree.
From: Bernd Herd codeberg@herdsoft.com
--- dlls/gphoto2.ds/ui.c | 4 ++-- dlls/sane.ds/ui.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/dlls/gphoto2.ds/ui.c b/dlls/gphoto2.ds/ui.c index a385b1139cb..e837527ee0f 100644 --- a/dlls/gphoto2.ds/ui.c +++ b/dlls/gphoto2.ds/ui.c @@ -127,7 +127,7 @@ static void PopulateImageList(HIMAGELIST *iList, HWND list) IMAGE_BITMAP, (LPARAM)static_bitmap); RedrawWindow(progress_dialog,NULL,NULL,RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN); } - EndDialog(progress_dialog,0); + DestroyWindow(progress_dialog); }
static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) @@ -239,7 +239,7 @@ HWND TransferringDialogBox(HWND dialog, LONG progress)
if (progress == -1) { - EndDialog(dialog,0); + DestroyWindow(dialog); return NULL; }
diff --git a/dlls/sane.ds/ui.c b/dlls/sane.ds/ui.c index 25a1cf33970..37f10f97f33 100644 --- a/dlls/sane.ds/ui.c +++ b/dlls/sane.ds/ui.c @@ -924,7 +924,7 @@ HWND ScanningDialogBox(HWND dialog, LONG progress)
if (progress == -1) { - EndDialog(dialog,0); + DestroyWindow(dialog); return NULL; }
This merge request was approved by Esme Povirk.