📄 intrface.cpp
字号:
Please refer to DDK documentation for more details.
Arguments:
pdevobj - pointer to a DEVOBJ structure.
pUFObj - pointer to a UNIFONTOBJ structure.
pdwResult - Receives one of the following method-supplied constant values:
TTDOWNLOAD_BITMAP Unidrv should download the specified font as bitmaps.
TTDOWNLOAD_DONTCARE Unidrv can select the font format.
TTDOWNLOAD_GRAPHICS Unidrv should print TrueType fonts as graphics,
instead of downloading the font.
TTDOWNLOAD_TTOUTLINE Unidrv should download the specified font as outlines.
Return Value:
S_OK The operation succeeded.
E_FAIL The operation failed.
E_NOTIMPL The method is not implemented.
--*/
{
OEMDBG(DBG_VERBOSE, L"COemUni2::TTDownloadMethod() entry.");
return E_NOTIMPL;
}
HRESULT __stdcall
COemUni2::
TTYGetInfo(
PDEVOBJ pdevobj,
DWORD dwInfoIndex,
PVOID pOutputBuf,
DWORD dwSize,
DWORD *pcbcNeeded
)
/*++
Routine Description:
Implementation of IPrintOemUni::TTYGetInfo
The IPrintOemUni::TTYGetInfo method enables a rendering plug-in
to supply Unidrv with information relevant to text-only printers.
Please refer to DDK documentation for more details.
Arguments:
pdevobj - pointer to a DEVOBJ structure.
dwInfoIndex - constant identifying the type of information being requested.
The following constant values are defined:
OEMTTY_INFO_CODEPAGE - The pOutputBuf parameter points to a
DWORD in which the method should return the number of the
code page to be used.
OEMTTY_INFO_MARGINS - The pOutputBuf parameter points to a
RECT structure in which the method should return page margin
widths, in tenths of millimeters (for example, 20 represents 2 mm).
If the entire page is printable, all margin values must be 0.
OEMTTY_INFO_NUM_UFMS - The pOutputBuf parameter points to a
DWORD in which the method should return the number of resource
IDs of the UFMs for 10, 12, and 17 CPI fonts. To actually obtain
these resource IDs, perform a query using OEMTTY_INFO_UFM_IDS.
OEMTTY_INFO_UFM_IDS - The pOutputBuf parameter points to an array
of DWORDs of sufficient size to hold the number of resource IDs of
the UFMs for 10, 12, and 17 CPI fonts. (This number is obtained by
using OEMTTY_INFO_NUM_UFMS in a query.) The method should
return the resource IDs of the UFMs for 10,12, and 17 CPI fonts.
pOutputBuf - pointer to a buffer to receive the requested information.
dwSize - size, in bytes, of the buffer pointed to by pOutputBuf.
pcbcNeeded - pointer to a location to receive the number of bytes written into
the buffer pointed to by pOutputBuf. If the number of bytes required is
smaller than the number specified by dwSize, the method should supply
the required size and return E_FAIL.
Return Value:
S_OK The operation succeeded.
E_FAIL The operation failed.
E_NOTIMPL The method is not implemented.
--*/
{
OEMDBG(DBG_VERBOSE, L"COemUni2::TTYGetInfo() entry.");
return E_NOTIMPL;
}
HRESULT __stdcall
COemUni2::
WritePrinter(
PDEVOBJ pdevobj,
PVOID pBuf,
DWORD cbBuffer,
PDWORD pcbWritten
)
/*++
Routine Description:
Implementation of IPrintOemUni2::WritePrinter
The IPrintOemUni2::WritePrinter method, if supported, enables a
rendering plug-in to capture all output data generated by a Unidrv
driver. If this method is not supported, the output data would
otherwise be sent to the spooler in a call to the spooler's WritePrinter API.
Please refer to DDK documentation for more details.
Arguments:
pdevobj - pointer to a DEVOBJ structure.
pBuf - pointer to the first byte of an array of bytes that contains
the output data generated by the Unidrv driver.
cbBuffer - size, in bytes, of the array pointed to by pBuf.
pcbWritten - pointer to a DWORD value that receives the number
of bytes of data that were successfully sent to the plug-in.
Return Value:
S_OK The operation succeeded.
E_FAIL The operation failed.
E_NOTIMPL The method is not implemented.
--*/
{
OEMDBG(DBG_VERBOSE, L"COemUni2::WritePrinter() entry.");
return E_NOTIMPL;
}
////////////////////////////////////////////////////////////////////////////////
//
// oem class factory
//
class COemCF : public IClassFactory
{
public:
// *** IUnknown methods ***
STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID FAR* ppvObj);
STDMETHOD_(ULONG,AddRef)(THIS);
STDMETHOD_(ULONG,Release)(THIS);
// *** IClassFactory methods ***
STDMETHOD(CreateInstance)(THIS_
LPUNKNOWN pUnkOuter,
REFIID riid,
LPVOID FAR* ppvObject);
STDMETHOD(LockServer)(THIS_ BOOL bLock);
// Constructor
COemCF(): m_cRef(1) { };
// Destructor
~COemCF() { };
protected:
LONG m_cRef;
};
///////////////////////////////////////////////////////////
//
// Class factory body
//
HRESULT __stdcall
COemCF::
QueryInterface(
const IID& iid,
void** ppv)
{
OEMDBG(DBG_VERBOSE, L"COemCF::QueryInterface entry.");
if ((iid == IID_IUnknown) || (iid == IID_IClassFactory))
{
*ppv = static_cast<COemCF*>(this);
}
else
{
*ppv = NULL;
#if DBG && defined(USERMODE_DRIVER)
TCHAR szOutput[80] = {0};
StringFromGUID2(iid, szOutput, COUNTOF(szOutput)); // can not fail!
VERBOSE(TEXT("COemCF::QueryInterface %s not supported.\r\n"), szOutput);
#endif
return E_NOINTERFACE;
}
reinterpret_cast<IUnknown*>(*ppv)->AddRef();
return S_OK;
}
ULONG __stdcall
COemCF::
AddRef()
{
return InterlockedIncrement(&m_cRef);
}
ULONG __stdcall
COemCF::
Release()
{
// ASSERT( 0 != m_cRef);
ULONG cRef = InterlockedDecrement(&m_cRef);
if (0 == cRef)
{
delete this;
}
return cRef;
}
// IClassFactory implementation
HRESULT __stdcall
COemCF::
CreateInstance(
IUnknown* pUnknownOuter,
const IID& iid,
void** ppv)
{
OEMDBG(DBG_VERBOSE, L"Class factory:Create component.");
// Cannot aggregate.
if (pUnknownOuter != NULL)
{
return CLASS_E_NOAGGREGATION;
}
// Create component.
COemUni2* pOemCP = new COemUni2;
if (pOemCP == NULL)
{
return E_OUTOFMEMORY;
}
// Get the requested interface.
HRESULT hr = pOemCP->QueryInterface(iid, ppv);
// Release the IUnknown pointer.
// (If QueryInterface failed, component will delete itself.)
pOemCP->Release();
return hr;
}
// LockServer
HRESULT __stdcall
COemCF::
LockServer(
BOOL bLock
)
{
if (bLock)
{
InterlockedIncrement(&g_cServerLocks);
}
else
{
InterlockedDecrement(&g_cServerLocks);
}
return S_OK;
}
//
// Registration functions
//
//
// Can DLL unload now?
//
STDAPI DllCanUnloadNow(void)
{
OEMDBG(DBG_VERBOSE, L"DllCanUnloadNow entry.");
//
// To avoid leaving OEM DLL still in memory when Unidrv or Pscript drivers
// are unloaded, Unidrv and Pscript driver ignore the return value of
// DllCanUnloadNow of the OEM DLL, and always call FreeLibrary on the OEMDLL.
//
// If OEM DLL spins off a working thread that also uses the OEM DLL, the
// thread needs to call LoadLibrary and FreeLibraryAndExitThread, otherwise
// it may crash after Unidrv or Pscript calls FreeLibrary.
//
if ((g_cComponents == 0) && (g_cServerLocks == 0))
{
return S_OK;
}
else
{
return S_FALSE;
}
}
//
// Get class factory
//
STDAPI DllGetClassObject(
const CLSID& clsid,
const IID& iid,
void** ppv)
{
OEMDBG(DBG_VERBOSE, L"DllGetClassObject:\tCreate class factory.");
// Can we create this component?
if (clsid != CLSID_OEMRENDER)
{
ERR(ERRORTEXT("DllGetClassObject:\tClass not available!\r\n"));
return CLASS_E_CLASSNOTAVAILABLE;
}
// Create class factory.
COemCF* pFontCF = new COemCF; // Reference count set to 1 in constructor
if (pFontCF == NULL)
{
ERR(ERRORTEXT("DllGetClassObject:\tOut of Memory!\r\n"));
return E_OUTOFMEMORY;
}
// Get requested interface.
HRESULT hrResult = pFontCF->QueryInterface(iid, ppv);
pFontCF->Release();
return hrResult;
}
BOOL
bGrowBuffer(
POEMPDEV pOemPDEV,
DWORD dwBufInc
)
/*++
Routine Description:
Enlarge the buffer for holding the bitmap data
Arguments:
pOemPDEV - Pointer to the private PDEV structure
dwBufInc - Amount to enlarge the buffer by
Return Value:
TRUE if successful, FALSE if memory allocation fails
--*/
{
OEMDBG(DBG_VERBOSE, L"bGrowBuffer entry.");
DWORD dwOldBufferSize;
PBYTE pNewBuffer;
// Allocate a new buffer whose size is the size of the previous buffer plus the increment
//
dwOldBufferSize = pOemPDEV->pBufStart ? pOemPDEV->dwBufSize : 0;
pOemPDEV->dwBufSize = dwOldBufferSize + dwBufInc;
if (! (pNewBuffer = (PBYTE)LocalAlloc(LPTR, pOemPDEV->dwBufSize)))
{
WARNING(DLLTEXT("LocalAlloc failed!\n"));
vFreeBuffer(pOemPDEV);
return FALSE;
}
if (pOemPDEV->pBufStart) // Growing an existing buffer
{
CopyMemory(pNewBuffer, pOemPDEV->pBufStart, dwOldBufferSize);
LocalFree(pOemPDEV->pBufStart);
pOemPDEV->pBufStart = pNewBuffer;
}
else // First time allocation
{
pOemPDEV->pBufStart = pNewBuffer;
}
return TRUE;
}
VOID
vFreeBuffer(
POEMPDEV pOemPDEV
)
/*++
Routine Description:
Free the buffer for holding the bitmap data
Arguments:
pOemPDEV - Pointer to the private PDEV structure
Return Value:
None
--*/
{
if (pOemPDEV->pBufStart)
{
LocalFree(pOemPDEV->pBufStart);
pOemPDEV->pBufStart = NULL;
pOemPDEV->dwBufSize = 0;
}
}
BOOL
bFillColorTable(
POEMPDEV pOemPDEV
)
/*++
Routine Description:
Fill the color table for the bitmap data. This function
obtains the entries in the default palette and fills the
RGBQUAD structure that represents the color table.
Arguments:
pOemPDEV - Pointer to the private PDEV structure
Return Value:
TRUE if successful, FALSE if memory allocation for the color table fails
--*/
{
PALETTEENTRY * pPaletteEntry;
UINT uiPalEntries;
INT iLastPalIndex = pOemPDEV->cPalColors - 1;
pOemPDEV->prgbq = (RGBQUAD *)LocalAlloc(LPTR, pOemPDEV->cPalColors * sizeof(RGBQUAD));
if (pOemPDEV->prgbq == NULL)
return FALSE;
pPaletteEntry = (PALETTEENTRY *)LocalAlloc(LPTR, pOemPDEV->cPalColors * sizeof(PALETTEENTRY));
uiPalEntries = GetPaletteEntries(pOemPDEV->hpalDefault, 0, pOemPDEV->cPalColors, pPaletteEntry);
if (uiPalEntries == 0)
return FALSE;
for (int i = 0; i < pOemPDEV->cPalColors; i++)
{
pOemPDEV->prgbq[i].rgbBlue = pPaletteEntry[i].peBlue;
pOemPDEV->prgbq[i].rgbGreen = pPaletteEntry[i].peGreen;
pOemPDEV->prgbq[i].rgbRed = pPaletteEntry[i].peRed;
}
// Set the last index in the color table to white
//
pOemPDEV->prgbq[iLastPalIndex].rgbBlue = 0xff;
pOemPDEV->prgbq[iLastPalIndex].rgbGreen = 0xff;
pOemPDEV->prgbq[iLastPalIndex].rgbRed = 0xff;
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -