Rob Shearman : net: Display a more specific error message when a service command fails.

Alexandre Julliard julliard at winehq.org
Wed Apr 2 06:55:29 CDT 2008


Module: wine
Branch: master
Commit: e4c8d763c9839391d41498b6512fece32037c7f2
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=e4c8d763c9839391d41498b6512fece32037c7f2

Author: Rob Shearman <rob at codeweavers.com>
Date:   Tue Apr  1 12:49:29 2008 +0100

net: Display a more specific error message when a service command fails.

Use FormatMessage to get the message for the Win32 error.

---

 programs/net/net.c |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/programs/net/net.c b/programs/net/net.c
index f27c853..30337a6 100644
--- a/programs/net/net.c
+++ b/programs/net/net.c
@@ -37,6 +37,20 @@ int output_string(int msg, ...)
     return 0;
 }
 
+BOOL output_error_string(DWORD error)
+{
+    LPSTR pBuffer;
+    if (FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
+            FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
+            NULL, error, 0, (LPSTR)&pBuffer, 0, NULL))
+    {
+        fputs(pBuffer, stdout);
+        LocalFree(pBuffer);
+        return TRUE;
+    }
+    return FALSE;
+}
+
 static BOOL net_use(int argc, char *argv[])
 {
     USE_INFO_2 *buffer, *connection;
@@ -140,14 +154,22 @@ static BOOL net_service(int operation, char *service_name)
         result = StartService(serviceHandle, 0, NULL);
 
         if(result) output_string(STRING_START_SVC_SUCCESS, service_display_name);
-        else output_string(STRING_START_SVC_FAIL, service_display_name);
+        else
+        {
+            if (!output_error_string(GetLastError()))
+                output_string(STRING_START_SVC_FAIL, service_display_name);
+        }
         break;
     case NET_STOP:
         output_string(STRING_STOP_SVC, service_display_name);
         result = StopService(SCManager, serviceHandle);
 
         if(result) output_string(STRING_STOP_SVC_SUCCESS, service_display_name);
-        else output_string(STRING_STOP_SVC_FAIL, service_display_name);
+        else
+        {
+            if (!output_error_string(GetLastError()))
+                output_string(STRING_STOP_SVC_FAIL, service_display_name);
+        }
         break;
     }
 




More information about the wine-cvs mailing list