gpt4 book ai didi

c++ - 为什么我会得到对任何与打印相关的函数 win32 的 undefined reference ?

转载 作者:行者123 更新时间:2023-11-28 02:52:19 26 4
gpt4 key购买 nike

这是我的包含的样子(链接器错误,所以可能与这些无关):

#define WINVER 0x0500
#define _WIN32_WINNT 0x0500
#define _WIN32_IE 0x0501
#include <windows.h>
#include <CommCtrl.h>
#include "resources.h"
#include <iostream>
#include <string>
#include <vector>
#include <tchar.h>
#include <winspool.h>

下面是我尝试实现的方式:

HRESULT DisplayPrintPropertySheet(HWND hWnd)
{
HRESULT hResult;
PRINTDLGEX pdx = {0};
LPPRINTPAGERANGE pPageRanges = NULL;

pPageRanges = (LPPRINTPAGERANGE) GlobalAlloc(GPTR, 10 * sizeof(PRINTPAGERANGE));
if (!pPageRanges)
return E_OUTOFMEMORY;


pdx.lStructSize = sizeof(PRINTDLGEX);
pdx.hwndOwner = hWnd;
pdx.hDevMode = NULL;
pdx.hDevNames = NULL;
pdx.hDC = NULL;
pdx.Flags = PD_RETURNDC | PD_COLLATE;
pdx.Flags2 = 0;
pdx.ExclusionFlags = 0;
pdx.nPageRanges = 0;
pdx.nMaxPageRanges = 10;
pdx.lpPageRanges = pPageRanges;
pdx.nMinPage = 1;
pdx.nMaxPage = 1000;
pdx.nCopies = 1;
pdx.hInstance = 0;
pdx.lpPrintTemplateName = NULL;
pdx.lpCallback = NULL;
pdx.nPropertyPages = 0;
pdx.lphPropertyPages = NULL;
pdx.nStartPage = START_PAGE_GENERAL;
pdx.dwResultAction = 0;



hResult = PrintDlgEx(&pdx);

if ((hResult == S_OK) && pdx.dwResultAction == PD_RESULT_PRINT)
{
StartDocPrinter(pdx.hDC,1,NULL);
EndDocPrinter(pdx.hDC);

cout << "Printer Succeeeded";

}

if (pdx.hDevMode != NULL)
GlobalFree(pdx.hDevMode);
if (pdx.hDevNames != NULL)
GlobalFree(pdx.hDevNames);
if (pdx.lpPageRanges != NULL)
GlobalFree(pPageRanges);

if (pdx.hDC != NULL)
DeleteDC(pdx.hDC);

return hResult;
}

每当我尝试使用 StartDoc,EndDoc,StartPage,EndPage,ect.

时,我总是收到这些未定义的链接器错误

链接器错误:

obj\Release\main.o:main.cpp|| undefined reference to `StartDocPrinterA@12'|
obj\Release\main.o:main.cpp|| undefined reference to `EndDocPrinter@4'|
||=== Build finished: 2 errors, 15 warnings ===|

最佳答案

如文档所述,这两个函数需要您链接到 winspool.lib。因此,您似乎没有那样做。

关于c++ - 为什么我会得到对任何与打印相关的函数 win32 的 undefined reference ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22775653/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com