Sync to Wine-20050111:
[reactos.git] / reactos / lib / rpcrt4 / rpcrt4_main.c
index baf7914..cdf5451 100644 (file)
@@ -748,3 +748,53 @@ BOOL RPCRT4_RPCSSOnDemandCall(PRPCSS_NP_MESSAGE msg, char *vardata_payload, PRPC
 \r
     return TRUE;\r
 }\r
+\r
+/* DceErrorInqText\r
+ *\r
+ * Notes\r
+ * 1. On passing a NULL pointer the code does bomb out.\r
+ * 2. The size of the required buffer is not defined in the documentation.\r
+ *    It appears to be 256.\r
+ * 3. The function is defined to return RPC_S_INVALID_ARG but I don't know\r
+ *    of any value for which it does.\r
+ * 4. The MSDN documentation currently declares that the second argument is\r
+ *    unsigned char *, even for the W version.  I don't believe it.\r
+ */\r
+\r
+#define MAX_RPC_ERROR_TEXT 256\r
+\r
+RPC_STATUS RPC_ENTRY DceErrorInqTextW (RPC_STATUS e, unsigned short *buffer)\r
+{\r
+    DWORD count;\r
+    count = FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM |\r
+                FORMAT_MESSAGE_IGNORE_INSERTS,\r
+                NULL, e, 0, buffer, MAX_RPC_ERROR_TEXT, NULL);\r
+    if (!count)\r
+    {\r
+        count = FormatMessageW (FORMAT_MESSAGE_FROM_SYSTEM |\r
+                FORMAT_MESSAGE_IGNORE_INSERTS,\r
+                NULL, RPC_S_NOT_RPC_ERROR, 0, buffer, MAX_RPC_ERROR_TEXT, NULL);\r
+        if (!count)\r
+        {\r
+            ERR ("Failed to translate error");\r
+            return RPC_S_INVALID_ARG;\r
+        }\r
+    }\r
+    return RPC_S_OK;\r
+}\r
+\r
+RPC_STATUS RPC_ENTRY DceErrorInqTextA (RPC_STATUS e, unsigned char *buffer)\r
+{\r
+    RPC_STATUS status;\r
+    WCHAR bufferW [MAX_RPC_ERROR_TEXT];\r
+    if ((status = DceErrorInqTextW (e, bufferW)) == RPC_S_OK)\r
+    {\r
+        if (!WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_RPC_ERROR_TEXT,\r
+                NULL, NULL))\r
+        {\r
+            ERR ("Failed to translate error");\r
+            status = RPC_S_INVALID_ARG;\r
+        }\r
+    }\r
+    return status;\r
+}\r