Menu

Linker problem with windows.h

kaasiro
2004-10-25
2012-09-26
  • kaasiro

    kaasiro - 2004-10-25

    Hi,
    I try to make an inventory, for interrest is the local connected printer. I write some c++ code, it will be compiled but the linker say angry:

    "[Linker Error] undefined reference to 'EnumPrintersA@28'".

    I'm new in coding c++, mayby it is something wrong in my source?

    I use Dev-C++ 4.9.9.0, the platform is XP Prof SP2.

    Have somebody an idea?

    include <iostream>

    include <stdlib.h>

    include <windows.h>

    using namespace std;

    void Drucker()
    {
    PRINTER_INFO_1 paDrucker[32];
    DWORD dwDummy, dwCount, i;

    cout &lt;&lt; &quot;[Lokale Drucker]&quot; &lt;&lt; endl;
    EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 1, (unsigned char*) (&amp;paDrucker[0]), sizeof(paDrucker), &amp;dwDummy, &amp;dwCount);
    
    for(i=0; i&lt;dwCount; i++)
        cout &lt;&lt; paDrucker[ i ].pName &lt;&lt; endl;
    

    }

    int main(int argc, char *argv[])
    {
    Drucker();
    system("PAUSE");
    return 0;
    }

    kaasiro

     
    • Larry Young

      Larry Young - 2004-10-25

      Your error message means that the linker cannot find object code for the function EnumPrinters. That function is in the Windows API, not in your source code, so you need to pass to the linker the library that contains the code. The header <windows.h> has the declaration but not the definition. In MSVC 6.0 the relevant libary is winspool.lib; you need to find that or its equivalent on your system and add it to the libraries of your project.

       
    • kaasiro

      kaasiro - 2004-10-25

      Thank you for the quickly answer, Iryoung. I search for winspool.lib on my system, but it seems to be inexistent. I try to download it (google :-)) .

       
    • kaasiro

      kaasiro - 2004-10-25

      I find on my system the library "libwinspool.a", and after I add it to my project the program runs.
      Well, it shows the network printers too, but I need just the printers with a local, physical connection to the PC. It's possible on the way I begin to go, or I'm wrong?

       
  • andrew7

    andrew7 - 2010-02-11

    I ran into this problem, and here was the solution for a smartwin project.

    using DevCpp 4.9.9.2, under Project | Project Options | Parameters | Linker
    you will see:
    ../../lib/libSmartWin.a -lcomctl32

    and you want to add the winspool library which has GetDefaultPrinterA
    ../../lib/libSmartWin.a -lcomctl32 -lwinspool

     
  • cpns

    cpns - 2010-02-11

    Not only is this thread OVER FIVE YEARS OLD; but it was was also solved
    already! Don't be silly.

     
  • laxman varada

    laxman varada - 2010-08-16

    hi,
    That function is in the Windows API, not in your source code, so you need to
    pass to the linker the library that contains the code.

    regards,
    phe9oxis,
    http://www.guidebuddha.com

     

Log in to post a comment.