reactos/win32ss/printing/base/winspool/spoolfile.c
James Tabor 7bffb70353 [Printing] Fix ups and Implementations.
WinSpool : Implement missing API. Sync/Port from wine. Setting it to fast track for needed testing of the later GDI code. Leaving Fix-me debug prints on.
Local tree has WinSpool_winetest turned on. So no debug noise during normal ReactOS operation.

SpoolSS : Reordered header types. Have more Spl function to be added while SpoolSV is being coded to forward to LocalSpl.

Based on wine and old research from the GDI code.
2020-08-03 21:07:58 -05:00

155 lines
4.3 KiB
C

/*
* PROJECT: ReactOS Spooler API
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Functions related to Spool Files and printing
* COPYRIGHT: Copyright 1998-2020 ReactOS
*/
#include "precomp.h"
HANDLE WINAPI
GetSpoolFileHandle( HANDLE hPrinter )
{
DWORD dwErrorCode, cpid;
WINSPOOL_FILE_INFO_CONTAINER FileInfoContainer;
WINSPOOL_FILE_INFO_1 wsplfi;
PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
HANDLE hHandle = NULL;
FIXME("GetSpoolFileHandle(%p)\n", hPrinter);
if ( IntProtectHandle( hPrinter, FALSE ) )
{
dwErrorCode = ERROR_INVALID_HANDLE;
}
else
{
if ( pHandle->hSpoolFileHandle != INVALID_HANDLE_VALUE )
{
hHandle = pHandle->hSpoolFileHandle;
}
else
{
cpid = GetCurrentProcessId();
FileInfoContainer.Level = 1;
FileInfoContainer.FileInfo.pFileInfo1 = &wsplfi;
// Do the RPC call.
RpcTryExcept
{
dwErrorCode = _RpcGetSpoolFileInfo2( &pHandle->hPrinter, cpid, 1, &FileInfoContainer );
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{
dwErrorCode = RpcExceptionCode();
ERR("_RpcGetSpoolFileInfo failed with exception code %lu!\n", dwErrorCode);
}
RpcEndExcept;
if (dwErrorCode == ERROR_SUCCESS)
{
pHandle->hSpoolFileHandle = wsplfi.hSpoolFileHandle;
pHandle->dwOptions = wsplfi.dwOptions;
hHandle = pHandle->hSpoolFileHandle;
}
}
IntUnprotectHandle(pHandle);
}
SetLastError(dwErrorCode);
return hHandle;
}
HANDLE WINAPI
CommitSpoolData( HANDLE hPrinter, HANDLE hSpoolFile, DWORD cbCommit )
{
DWORD dwErrorCode, cpid;
WINSPOOL_FILE_INFO_CONTAINER FileInfoContainer;
WINSPOOL_FILE_INFO_1 wsplfi;
PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
HANDLE hHandle = INVALID_HANDLE_VALUE;
FIXME("CommitSpoolData(%p, %p, %d)\n", hPrinter,hSpoolFile,cbCommit);
if ( IntProtectHandle( hPrinter, FALSE ) )
{
return hHandle;
}
if ( pHandle->hSpoolFileHandle == INVALID_HANDLE_VALUE || pHandle->hSpoolFileHandle != hSpoolFile )
{
dwErrorCode = ERROR_INVALID_HANDLE;
}
else
{
cpid = GetCurrentProcessId();
FileInfoContainer.Level = 1;
FileInfoContainer.FileInfo.pFileInfo1 = &wsplfi;
// Do the RPC call.
RpcTryExcept
{
dwErrorCode = _RpcCommitSpoolData2( &pHandle->hPrinter, cpid, cbCommit, 1, &FileInfoContainer );
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{
dwErrorCode = RpcExceptionCode();
ERR("_RpcCommitSpoolData failed with exception code %lu!\n", dwErrorCode);
}
RpcEndExcept;
if (dwErrorCode == ERROR_SUCCESS)
{
if ( wsplfi.hSpoolFileHandle != INVALID_HANDLE_VALUE )
{
CloseHandle( pHandle->hSpoolFileHandle );
pHandle->hSpoolFileHandle = wsplfi.hSpoolFileHandle;
}
hHandle = pHandle->hSpoolFileHandle;
}
IntUnprotectHandle(pHandle);
}
SetLastError(dwErrorCode);
return hHandle;
}
BOOL WINAPI
CloseSpoolFileHandle( HANDLE hPrinter, HANDLE hSpoolFile )
{
DWORD dwErrorCode;
PSPOOLER_HANDLE pHandle = (PSPOOLER_HANDLE)hPrinter;
FIXME("CloseSpoolFileHandle(%p, %p)\n", hPrinter,hSpoolFile);
if ( IntProtectHandle( hPrinter, FALSE ) )
{
return FALSE;
}
if ( pHandle->hSpoolFileHandle == hSpoolFile )
{
CloseHandle( pHandle->hSpoolFileHandle );
pHandle->hSpoolFileHandle = INVALID_HANDLE_VALUE;
// Do the RPC call.
RpcTryExcept
{
dwErrorCode = _RpcCloseSpoolFileHandle( &pHandle->hPrinter );
}
RpcExcept(EXCEPTION_EXECUTE_HANDLER)
{
dwErrorCode = RpcExceptionCode();
ERR("_RpcloseSpoolFileHandle failed with exception code %lu!\n", dwErrorCode);
}
RpcEndExcept;
}
else
{
dwErrorCode = ERROR_INVALID_HANDLE;
}
IntUnprotectHandle(pHandle);
SetLastError(dwErrorCode);
return (dwErrorCode == ERROR_SUCCESS);
}