On Thu, Apr 24, 2008 at 5:36 AM, Alexandre Julliard <[EMAIL PROTECTED]> wrote:
>  You certainly don't want to call through explorer for that, showing a
>  message box directly is fine. You have to be careful to only do it when
>  loading the main exe, not for any random dll load; also you have to
>  properly handle the case of a missing X display.

OK so is doing this in ntdll even the right case? I don't really see
where to do it only from the main exe. I understand we don't want to
report the error if the application is manually doing a
GetProcAddress/LoadLibrary but again don't really know how to limit
it. Here is my stab #2, it actually returns something sane to the
user.

-- 
Steven Edwards

"There is one thing stronger than all the armies in the world, and
that is an idea whose time has come." - Victor Hugo
From a9a763015d9d4738fc9187e6d913d54cd5d6f25f Mon Sep 17 00:00:00 2001
From: Steven Edwards <[EMAIL PROTECTED]>
Date: Thu, 24 Apr 2008 02:21:08 -0400
Subject: [PATCH] Took a stab at graphically reporting an error when a dll was not found

---
 dlls/ntdll/loader.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index b0000b8..4d37e64 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -464,6 +464,32 @@ static FARPROC find_named_export( HMODULE module, const IMAGE_EXPORT_DIRECTORY *
 
 }
 
+FARPROC pMessageBoxW;
+static NTSTATUS report_error()
+{
+    NTSTATUS nts,nts2;
+    UNICODE_STRING wstr;
+    ANSI_STRING str;
+    HMODULE hdll;
+    WCHAR user32[] = {'u','s','e','r','3','2','.','d','l','l',0};
+
+    RtlInitUnicodeString( &wstr, user32 );
+    nts = LdrLoadDll(0, 0, &wstr, &hdll);
+    if (nts != STATUS_SUCCESS)
+    {
+        ERR("couldn't load user32 to display error\n");
+        return nts;
+    }
+
+    RtlInitAnsiString( &str, "MessageBoxW" );
+    nts2 = LdrGetProcedureAddress( hdll, &str, 0, (void**)&pMessageBoxW );
+    if (nts2 != STATUS_SUCCESS)
+    {
+        ERR("Couldn't import MessageBoxW\n");
+        return nts;
+    }
+    return nts;
+}
 
 /*************************************************************************
  *		import_dll
@@ -514,8 +540,15 @@ static WINE_MODREF *import_dll( HMODULE module, const IMAGE_IMPORT_DESCRIPTOR *d
     if (status)
     {
         if (status == STATUS_DLL_NOT_FOUND)
+        {
+            WCHAR dll_error[] = {'A',' ','r','e','q','i','u','r','e','d',' ','d','l','l',' ','w','a','s',' ','n','o','t',' ','f','o','u','n','d',0};
+            NTSTATUS nts = report_error();
+            if (nts == STATUS_SUCCESS)
+                pMessageBoxW(NULL,dll_error,NULL,NULL);
+
             ERR("Library %s (which is needed by %s) not found\n",
                 name, debugstr_w(current_modref->ldr.FullDllName.Buffer));
+        }
         else
             ERR("Loading library %s (which is needed by %s) failed (error %x).\n",
                 name, debugstr_w(current_modref->ldr.FullDllName.Buffer), status);
-- 
1.5.3.7



Reply via email to