mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-04-21 07:43:21 +03:00
remove xpsprint.dll hard dep, https://github.com/rustdesk/rustdesk/discussions/12042#discussioncomment-13464313
This commit is contained in:
@@ -872,7 +872,44 @@ extern "C"
|
|||||||
// Remote printing
|
// Remote printing
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#pragma comment(lib, "XpsPrint.lib")
|
// Dynamic loading of XPS Print functions
|
||||||
|
typedef HRESULT(WINAPI *StartXpsPrintJobFunc)(
|
||||||
|
LPCWSTR printerName,
|
||||||
|
LPCWSTR jobName,
|
||||||
|
LPCWSTR outputFileName,
|
||||||
|
HANDLE progressEvent,
|
||||||
|
HANDLE completionEvent,
|
||||||
|
UINT8* printablePagesOn,
|
||||||
|
UINT32 printablePagesOnCount,
|
||||||
|
IXpsPrintJob** xpsPrintJob,
|
||||||
|
IXpsPrintJobStream** documentStream,
|
||||||
|
IXpsPrintJobStream** printTicketStream);
|
||||||
|
|
||||||
|
static HMODULE xpsPrintModule = nullptr;
|
||||||
|
static StartXpsPrintJobFunc StartXpsPrintJobPtr = nullptr;
|
||||||
|
|
||||||
|
static bool InitXpsPrint()
|
||||||
|
{
|
||||||
|
if (xpsPrintModule == nullptr)
|
||||||
|
{
|
||||||
|
xpsPrintModule = LoadLibraryA("XpsPrint.dll");
|
||||||
|
if (xpsPrintModule == nullptr)
|
||||||
|
{
|
||||||
|
flog("Failed to load XpsPrint.dll. Error: %d\n", GetLastError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
StartXpsPrintJobPtr = (StartXpsPrintJobFunc)GetProcAddress(xpsPrintModule, "StartXpsPrintJob");
|
||||||
|
if (StartXpsPrintJobPtr == nullptr)
|
||||||
|
{
|
||||||
|
flog("Failed to get StartXpsPrintJob function. Error: %d\n", GetLastError());
|
||||||
|
FreeLibrary(xpsPrintModule);
|
||||||
|
xpsPrintModule = nullptr;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
#pragma warning(push)
|
#pragma warning(push)
|
||||||
#pragma warning(disable : 4995)
|
#pragma warning(disable : 4995)
|
||||||
|
|
||||||
@@ -886,6 +923,13 @@ extern "C"
|
|||||||
|
|
||||||
int PrintXPSRawData(LPWSTR printerName, BYTE *rawData, ULONG dataSize)
|
int PrintXPSRawData(LPWSTR printerName, BYTE *rawData, ULONG dataSize)
|
||||||
{
|
{
|
||||||
|
// Check if XPS Print DLL is available
|
||||||
|
if (!InitXpsPrint())
|
||||||
|
{
|
||||||
|
flog("XPS Print functionality not available on this system\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
BOOL isCoInitializeOk = FALSE;
|
BOOL isCoInitializeOk = FALSE;
|
||||||
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||||
if (hr == RPC_E_CHANGED_MODE)
|
if (hr == RPC_E_CHANGED_MODE)
|
||||||
@@ -931,7 +975,7 @@ extern "C"
|
|||||||
// `StartXpsPrintJob()` is deprecated, but we still use it for compatibility.
|
// `StartXpsPrintJob()` is deprecated, but we still use it for compatibility.
|
||||||
// We may change to use the `Print Document Package API` in the future.
|
// We may change to use the `Print Document Package API` in the future.
|
||||||
// https://learn.microsoft.com/en-us/windows/win32/printdocs/xpsprint-functions
|
// https://learn.microsoft.com/en-us/windows/win32/printdocs/xpsprint-functions
|
||||||
hr = StartXpsPrintJob(
|
hr = StartXpsPrintJobPtr(
|
||||||
printerName,
|
printerName,
|
||||||
L"Print Job 1",
|
L"Print Job 1",
|
||||||
nullptr,
|
nullptr,
|
||||||
@@ -976,5 +1020,15 @@ extern "C"
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CleanupXpsPrint()
|
||||||
|
{
|
||||||
|
if (xpsPrintModule != nullptr)
|
||||||
|
{
|
||||||
|
FreeLibrary(xpsPrintModule);
|
||||||
|
xpsPrintModule = nullptr;
|
||||||
|
StartXpsPrintJobPtr = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#pragma warning(pop)
|
#pragma warning(pop)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user