GetDefaultPrinterA undeclared(first us this function

This is a discussion on GetDefaultPrinterA undeclared(first us this function within the C++ Programming forums, part of the General Programming Boards category; hey all once again i need your technical expertise. i am using DEV-C++ 4.9.9.2 and when i compile my dll ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    7

    GetDefaultPrinterA undeclared(first us this function

    hey all

    once again i need your technical expertise.

    i am using DEV-C++ 4.9.9.2

    and when i compile my dll i get the following Error

    GetdefaultPrinerA undeclared (first ust this function)

    this is the code of my dll
    Code:
    #include "NativeWindowsPrinter.h"
    #include <windows.h>
    #include <stdio.h>
    #include <Winspool.h>
    
    
    BOOL APIENTRY DllMain (HINSTANCE hInst     /* Library instance handle. */ ,
                           DWORD reason        /* Reason this function is being called. */ ,
                           LPVOID reserved     /* Not used. */ )
    {
        switch (reason)
        {
          case DLL_PROCESS_ATTACH:
            break;
    
          case DLL_PROCESS_DETACH:
            break;
    
          case DLL_THREAD_ATTACH:
            break;
    
          case DLL_THREAD_DETACH:
            break;
        }
    
        /* Returns TRUE on success, FALSE on failure */
        return TRUE;
    }
    
    JNIEXPORT jstring JNICALL Java_be_ikmo_print_NativeWindowsPrinter_ngetDefaultPrinter
      (JNIEnv * env, jobject obj)
      {
            LPTSTR  pPrinterName;
            LPDWORD pdwBufferSize;
            if(!GetDefaultPrinter(pPrinterName, pdwBufferSize))
                  return env->NewStringUTF("sdfqsdfqs");
                  
            return  env->NewStringUTF(pPrinterName); 
    }
    can anybody help me out with this problem

    thanks in advance

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Did you add Winspool.lib ( might be called a little different on dev-cpp ) to the linker options ?
    Kurt

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    7
    no i added system32\winspool.drv
    or winspool.a that was provided with dev-c++

    James

  4. #4
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    You are right. It's not a linker error you have.
    Are you shure the include isn't called <winspool.h> ?.
    Kurt

  5. #5
    Registered User
    Join Date
    Jul 2005
    Posts
    69
    // from winspool.h
    // #if _WIN32_WINNT >= 0x0500
    so:
    #define _WIN32_WINNT 0x0500

    before including windows.h or winspool.h

    That should get you going,
    Brian

    p.s. that would probably have been better served in the windows programming section but we got you covered

  6. #6
    Registered User
    Join Date
    Jan 2006
    Posts
    7
    ow dang, that could very well be it.
    i will check this first thing in the morning

    i will let you know the outcome

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    7

    Unhappy

    i does compile but when i execute the program freezes.
    i never get the default printer returned.

    anybody got any ideas

  8. #8
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    There's more to calling a function than just getting the types to match.
    Code:
    TCHAR szPrinterName[500];
    DWORD cchPrinterName = 500;
    GetDefaultPrinter(szPrinterName, &cchPrinterName);
    Last edited by anonytmouse; 01-12-2006 at 12:20 AM.

  9. #9
    Registered User
    Join Date
    Jan 2006
    Posts
    7
    shouldn't it be better to
    use something like this

    Code:
            DWORD cchPrinterName ;     
            if (!GetDefaultPrinter(NULL, &cchPrinterName))
            {
               if(::GetLastError() != ERROR_INSUFFICIENT_BUFFER)
               {
                                   return env->NewStringUTF(""); 
               }
            }
    
            TCHAR szPrinterName[cchPrinterName];
            if(!GetDefaultPrinter(szPrinterName, &cchPrinterName))
                    return env->NewStringUTF("");
            return  env->NewStringUTF(szPrinterName);
    that way the buffer is always sufficient? correct me if i am wrong ?

    James

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    If that's the behaviour GetDefaultPrinter offers, then the code is sound (except the C99-style array, which won't work in C++). If not ... not.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21