Sync to Wine-20050524:
Alexandre Julliard <julliard@winehq.org>
- Added rules for building import libraries in the individual dll
  makefiles, and added support for building a .def.a static import
  library too.
Vincent Beron <vberon@mecano.gme.usherb.ca>
- Provide minimal API documentation in advapi/eventlog.c to silence some
  winapi_check output.
- Move around functions in riched20, richedit and rpcrt4 to achieve the
  same goal.
Robert Shearman <rob@codeweavers.com>
- Fix RpcServerListen so that it doesn't return
  RPC_S_ALREADY_LISTENING when the only interfaces it is listening on
  are auto listens.
- Only synchronize with server thread when necessary and move this
  into RpcMgmtWaitServerListen.
Francois Gouget <fgouget@free.fr>
- Tweak the API documentation to silence winapi_check warnings.
Hartmut Birr <hartmut.birr@gmx.de>
- Clean up if named pipe is not available.
  (merge back from WineHQ)
Modified: trunk/reactos/lib/rpcrt4/Makefile.in
Modified: trunk/reactos/lib/rpcrt4/ndr_stubless.c
Modified: trunk/reactos/lib/rpcrt4/rpc_server.c
Modified: trunk/reactos/lib/rpcrt4/rpcrt4_main.c
Modified: trunk/reactos/lib/rpcrt4/rpcss_np_client.c

Modified: trunk/reactos/lib/rpcrt4/Makefile.in
--- trunk/reactos/lib/rpcrt4/Makefile.in	2005-05-28 14:56:02 UTC (rev 15580)
+++ trunk/reactos/lib/rpcrt4/Makefile.in	2005-05-28 15:04:47 UTC (rev 15581)
@@ -4,6 +4,7 @@
 SRCDIR    = @srcdir@
 VPATH     = @srcdir@
 MODULE    = rpcrt4.dll
+IMPORTLIB = librpcrt4.$(IMPLIBEXT)
 IMPORTS   = iphlpapi advapi32 kernel32 ntdll
 EXTRALIBS = -luuid
 

Modified: trunk/reactos/lib/rpcrt4/ndr_stubless.c
--- trunk/reactos/lib/rpcrt4/ndr_stubless.c	2005-05-28 14:56:02 UTC (rev 15580)
+++ trunk/reactos/lib/rpcrt4/ndr_stubless.c	2005-05-28 15:04:47 UTC (rev 15581)
@@ -41,7 +41,11 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(ole);
 
-LONG_PTR /* CLIENT_CALL_RETURN */ RPCRT4_NdrClientCall2(PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat, va_list args)
+/***********************************************************************
+ * Note: this should return a CLIENT_CALL_RETURN, but calling convention for
+ * returning structures/unions is different between Windows and gcc on i386.
+ */
+LONG_PTR RPCRT4_NdrClientCall2(PMIDL_STUB_DESC pStubDesc, PFORMAT_STRING pFormat, va_list args)
 {
 
   RPC_CLIENT_INTERFACE *rpc_cli_if = (RPC_CLIENT_INTERFACE *)(pStubDesc->RpcInterfaceInformation);
@@ -83,8 +87,11 @@
 
 /***********************************************************************
  *           NdrClientCall2 [RPCRT4.@]
+ *
+ * Note: this should return a CLIENT_CALL_RETURN, but calling convention for
+ * returning structures/unions is different between Windows and gcc on i386.
  */
-LONG_PTR /* CLIENT_CALL_RETURN */ WINAPIV NdrClientCall2(PMIDL_STUB_DESC pStubDesc,
+LONG_PTR WINAPIV NdrClientCall2(PMIDL_STUB_DESC pStubDesc,
   PFORMAT_STRING pFormat, ...)
 {
     LONG_PTR ret;

Modified: trunk/reactos/lib/rpcrt4/rpc_server.c
--- trunk/reactos/lib/rpcrt4/rpc_server.c	2005-05-28 14:56:02 UTC (rev 15580)
+++ trunk/reactos/lib/rpcrt4/rpc_server.c	2005-05-28 15:04:47 UTC (rev 15581)
@@ -103,8 +103,6 @@
 static HANDLE mgr_mutex;
 /* set when server thread has finished opening connections */
 static HANDLE server_ready_event;
-/* thread that waits for connections */
-static HANDLE server_thread;
 
 static CRITICAL_SECTION spacket_cs;
 static CRITICAL_SECTION_DEBUG spacket_cs_debug =
@@ -587,14 +585,18 @@
   ReleaseMutex(mgr_mutex);
 }
 
-static void RPCRT4_start_listen(BOOL auto_listen)
+static RPC_STATUS RPCRT4_start_listen(BOOL auto_listen)
 {
+  RPC_STATUS status = RPC_S_ALREADY_LISTENING;
+
   TRACE("\n");
 
   EnterCriticalSection(&listen_cs);
   if (auto_listen || (manual_listen_count++ == 0))
   {
+    status = RPC_S_OK;
     if (++listen_count == 1) {
+      HANDLE server_thread;
       /* first listener creates server thread */
       if (!mgr_mutex) mgr_mutex = CreateMutexW(NULL, FALSE, NULL);
       if (!mgr_event) mgr_event = CreateEventW(NULL, FALSE, FALSE, NULL);
@@ -603,13 +605,12 @@
       if (!worker_tls) worker_tls = TlsAlloc();
       std_listen = TRUE;
       server_thread = CreateThread(NULL, 0, RPCRT4_server_thread, NULL, 0, NULL);
-    } else {
-      LeaveCriticalSection(&listen_cs);
-      RPCRT4_sync_with_server_thread();
-      return;
+      CloseHandle(server_thread);
     }
   }
   LeaveCriticalSection(&listen_cs);
+
+  return status;
 }
 
 static void RPCRT4_stop_listen(BOOL auto_listen)
@@ -977,24 +978,17 @@
  */
 RPC_STATUS WINAPI RpcServerListen( UINT MinimumCallThreads, UINT MaxCalls, UINT DontWait )
 {
+  RPC_STATUS status;
+
   TRACE("(%u,%u,%u)\n", MinimumCallThreads, MaxCalls, DontWait);
 
   if (!protseqs)
     return RPC_S_NO_PROTSEQS_REGISTERED;
 
-  EnterCriticalSection(&listen_cs);
+  status = RPCRT4_start_listen(FALSE);
 
-  if (std_listen) {
-    LeaveCriticalSection(&listen_cs);
-    return RPC_S_ALREADY_LISTENING;
-  }
+  if (DontWait || (status != RPC_S_OK)) return status;
 
-  RPCRT4_start_listen(FALSE);
-
-  LeaveCriticalSection(&listen_cs);
-
-  if (DontWait) return RPC_S_OK;
-
   return RpcMgmtWaitServerListen();
 }
 
@@ -1003,29 +997,20 @@
  */
 RPC_STATUS WINAPI RpcMgmtWaitServerListen( void )
 {
-  RPC_STATUS rslt = RPC_S_OK;
+  TRACE("()\n");
 
-  TRACE("\n");
-
   EnterCriticalSection(&listen_cs);
 
-  if (!std_listen)
-    if ( (rslt = RpcServerListen(1, 0, TRUE)) != RPC_S_OK ) {
-      LeaveCriticalSection(&listen_cs);
-      return rslt;
-    }
+  if (!std_listen) {
+    LeaveCriticalSection(&listen_cs);
+    return RPC_S_NOT_LISTENING;
+  }
   
   LeaveCriticalSection(&listen_cs);
 
-  while (std_listen) {
-    WaitForSingleObject(mgr_event, INFINITE);
-    if (!std_listen) {
-      Sleep(100); /* don't spin violently */
-      TRACE("spinning.\n");
-    }
-  }
+  RPCRT4_sync_with_server_thread();
 
-  return rslt;
+  return RPC_S_OK;
 }
 
 /***********************************************************************

Modified: trunk/reactos/lib/rpcrt4/rpcrt4_main.c
--- trunk/reactos/lib/rpcrt4/rpcrt4_main.c	2005-05-28 14:56:02 UTC (rev 15580)
+++ trunk/reactos/lib/rpcrt4/rpcrt4_main.c	2005-05-28 15:04:47 UTC (rev 15581)
@@ -767,7 +767,10 @@
     return TRUE;
 }
 
-/* DceErrorInqText
+#define MAX_RPC_ERROR_TEXT 256
+
+/******************************************************************************
+ * DceErrorInqTextW   (rpcrt4.@)
  *
  * Notes
  * 1. On passing a NULL pointer the code does bomb out.
@@ -778,9 +781,6 @@
  * 4. The MSDN documentation currently declares that the second argument is
  *    unsigned char *, even for the W version.  I don't believe it.
  */
-
-#define MAX_RPC_ERROR_TEXT 256
-
 RPC_STATUS RPC_ENTRY DceErrorInqTextW (RPC_STATUS e, unsigned short *buffer)
 {
     DWORD count;
@@ -801,6 +801,9 @@
     return RPC_S_OK;
 }
 
+/******************************************************************************
+ * DceErrorInqTextA   (rpcrt4.@)
+ */
 RPC_STATUS RPC_ENTRY DceErrorInqTextA (RPC_STATUS e, unsigned char *buffer)
 {
     RPC_STATUS status;

Modified: trunk/reactos/lib/rpcrt4/rpcss_np_client.c
--- trunk/reactos/lib/rpcrt4/rpcss_np_client.c	2005-05-28 14:56:02 UTC (rev 15580)
+++ trunk/reactos/lib/rpcrt4/rpcss_np_client.c	2005-05-28 15:04:47 UTC (rev 15581)
@@ -84,7 +84,6 @@
     if (! WaitNamedPipeA(NAME_RPCSS_NAMED_PIPE, MASTER_MUTEX_WAITNAMEDPIPE_TIMEOUT))
     {
       ERR("Named pipe unavailable after waiting.  Something is probably wrong.\n");
-      CloseHandle(the_pipe);
       the_pipe = NULL;
       break;
     }