Menu

Undefined reference to 'GetDefaultPrinterA'

2005-10-06
2012-09-26
  • Nobody/Anonymous

    Hi,

    I'm trying to get the name of the default printer with GetDefaultPrinter. I'm using WinXP.
    The Problem is I'm always getting an "undefined reference" error from the linker, although I have included the libwinspool for linking(I'm succesfully using other functions from libwinspool).
    Any idea?

    Thanks.

     
    • Nobody/Anonymous

      Could you post your "Basic 3" please - see the thread titled "Please Read Before Posting a Question" in this forum for what they are if you do not know.

      Wayne

       
    • Nobody/Anonymous

      Ok, now that I'm on my home computer where I actually have a reasonably up to date version of dev, I see that they have this in winspool.h

      if _WIN32_WINNT >= 0x0500

      BOOL WINAPI GetDefaultPrinterA(LPSTR,LPDWORD);
      BOOL WINAPI GetDefaultPrinterW(LPWSTR,LPDWORD);

      endif

      So, you have to add a line like this to your code

      define _WIN32_WINNT 0x0500

      Whenever you come across a problem like this the first thing to do is look in the related headers to see if the function is actually declared, and if it is, is it inside an #if block.

      b_a

       
    • Nobody/Anonymous

      Have you looked in the winspool.h file to see if GetDefaultPrinter is declared? Sometimes things are left out of the header files.

      If it isn't you can add this to your code (or in winspool.h) and see if it works.

      I got this from
      http://www.cs.bgu.ac.il/~pcprogs/install/Microsoft_SDK/Include/WinSpool.h

      BOOL
      WINAPI
      GetDefaultPrinterA(
      IN LPSTR pszBuffer,
      IN LPDWORD pcchBuffer
      );
      BOOL
      WINAPI
      GetDefaultPrinterW(
      IN LPWSTR pszBuffer,
      IN LPDWORD pcchBuffer
      );

      ifdef UNICODE

      define GetDefaultPrinter GetDefaultPrinterW

      else

      define GetDefaultPrinter GetDefaultPrinterA

      endif // !UNICODE

      b_a

       
    • Nobody/Anonymous

      Oh, just looked at that again.. I think you'll probably need to remove the word IN in those declarations..

      b_a

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.