First of all, I understand there are many topics on this function, but I did not find any about this particular problem, sorry if I am repeating...
I have been working on a program in C++ that works with printers and I need to get the list of printers in the system.
I am using the EnumPrinters API and I am getting a compile error I don't understand.
This is my code:
#include <iostream>
#include <windows.h>
#include <winspool.h>
using namespace std;
int main()
{
PRINTER_INFO_5 pi;
PBYTE buffer[99];
DWORD bufferSize = 0;
DWORD bufferNeeded = 0;
DWORD Entries = 0;
bool r;
r = EnumPrinters(PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 5, NULL, bufferSize, &bufferNeeded, &Entries);
if (!r)
{ cout << "No printer found" << endl; }
else { cout << "Found printers" << endl; }
}
When I try to compile (codeBlocks typical installation w/ gcc), I get this error:
C:\Programação\C++\lab\main.cpp 18 undefined reference to 'EnumPrintersA@28'
I think this may be a linker problem, but I don't know how to solve it...
Thank you!
SOLVED!
After some help I found out that the problem was that I wasn't importing the correct library. I thought including the header would be enough.
I needed to follow these steps (using 'winspool' instead of 'gdi32').
By the way, adding 'winspool.lib' did not solve it. Use 'winspool' instead (no '.lib')