* PROJECT: ReactOS Spooler API
* LICENSE: GNU LGPL v2.1 or any later version as published by the Free Software Foundation
* PURPOSE: Functions related to Print Processors
- * COPYRIGHT: Copyright 2015 Colin Finck <colin@reactos.org>
+ * COPYRIGHT: Copyright 2015-2016 Colin Finck <colin@reactos.org>
*/
#include "precomp.h"
+#include <prtprocenv.h>
static void
_MarshallUpDatatypesInfo(PDATATYPES_INFO_1W pDatatypesInfo1)
DWORD i;
PBYTE p = pPrintProcessorInfo;
+ // Choose our current environment if the caller didn't give any.
+ if (!pEnvironment)
+ pEnvironment = (PWSTR)wszCurrentEnvironment;
+
// Do the RPC call
RpcTryExcept
{
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{
dwErrorCode = RpcExceptionCode();
- ERR("_RpcEnumPrintProcessors failed with exception code %lu!\n", dwErrorCode);
}
RpcEndExcept;
}
BOOL WINAPI
-GetPrintProcessorDirectoryW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded)
+GetPrintProcessorDirectoryA(PSTR pName, PSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded)
{
BOOL bReturnValue = FALSE;
+ DWORD cch;
+ PWSTR pwszName = NULL;
+ PWSTR pwszEnvironment = NULL;
+ PWSTR pwszPrintProcessorInfo = NULL;
+
+ if (pName)
+ {
+ // Convert pName to a Unicode string pwszName.
+ cch = strlen(pName);
+
+ pwszName = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
+ if (!pwszName)
+ {
+ ERR("HeapAlloc failed for pwszName with last error %lu!\n", GetLastError());
+ goto Cleanup;
+ }
+
+ MultiByteToWideChar(CP_ACP, 0, pName, -1, pwszName, cch + 1);
+ }
+
+ if (pEnvironment)
+ {
+ // Convert pEnvironment to a Unicode string pwszEnvironment.
+ cch = strlen(pEnvironment);
+
+ pwszEnvironment = HeapAlloc(hProcessHeap, 0, (cch + 1) * sizeof(WCHAR));
+ if (!pwszEnvironment)
+ {
+ ERR("HeapAlloc failed for pwszEnvironment with last error %lu!\n", GetLastError());
+ goto Cleanup;
+ }
+
+ MultiByteToWideChar(CP_ACP, 0, pEnvironment, -1, pwszEnvironment, cch + 1);
+ }
+
+ if (cbBuf && pPrintProcessorInfo)
+ {
+ // Allocate a temporary buffer for the Unicode result.
+ // We can just go with cbBuf here. The user should have set it based on pcbNeeded returned in a previous call and our
+ // pcbNeeded is the same for the A and W functions.
+ pwszPrintProcessorInfo = HeapAlloc(hProcessHeap, 0, cbBuf);
+ if (!pwszPrintProcessorInfo)
+ {
+ ERR("HeapAlloc failed for pwszPrintProcessorInfo with last error %lu!\n", GetLastError());
+ goto Cleanup;
+ }
+ }
+
+ bReturnValue = GetPrintProcessorDirectoryW(pwszName, pwszEnvironment, Level, (PBYTE)pwszPrintProcessorInfo, cbBuf, pcbNeeded);
+
+ if (bReturnValue)
+ {
+ // Convert pwszPrintProcessorInfo to an ANSI string pPrintProcessorInfo.
+ WideCharToMultiByte(CP_ACP, 0, pwszPrintProcessorInfo, -1, (PSTR)pPrintProcessorInfo, cbBuf, NULL, NULL);
+ }
+
+Cleanup:
+ if (pwszName)
+ HeapFree(hProcessHeap, 0, pwszName);
+
+ if (pwszEnvironment)
+ HeapFree(hProcessHeap, 0, pwszEnvironment);
+
+ if (pwszPrintProcessorInfo)
+ HeapFree(hProcessHeap, 0, pwszPrintProcessorInfo);
+
+ return bReturnValue;
+}
+
+BOOL WINAPI
+GetPrintProcessorDirectoryW(PWSTR pName, PWSTR pEnvironment, DWORD Level, PBYTE pPrintProcessorInfo, DWORD cbBuf, PDWORD pcbNeeded)
+{
DWORD dwErrorCode;
+ // Sanity checks
+ if (Level != 1)
+ {
+ dwErrorCode = ERROR_INVALID_LEVEL;
+ goto Cleanup;
+ }
+
+ // Choose our current environment if the caller didn't give any.
+ if (!pEnvironment)
+ pEnvironment = (PWSTR)wszCurrentEnvironment;
+
// Do the RPC call
RpcTryExcept
{
dwErrorCode = _RpcGetPrintProcessorDirectory(pName, pEnvironment, Level, pPrintProcessorInfo, cbBuf, pcbNeeded);
- SetLastError(dwErrorCode);
- bReturnValue = (dwErrorCode == ERROR_SUCCESS);
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{
- ERR("_RpcGetPrintProcessorDirectory failed with exception code %lu!\n", RpcExceptionCode());
+ dwErrorCode = RpcExceptionCode();
}
RpcEndExcept;
- return bReturnValue;
+Cleanup:
+ SetLastError(dwErrorCode);
+ return (dwErrorCode == ERROR_SUCCESS);
}