CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Sep 2021
    Posts
    11

    [RESOLVED] Where can I get User32.lib file?

    Hi,
    I am trying to use PrintWindow function in very old Borland C of 1997 (that is the only development environment I have and know). I've downloaded User32.dll file that contains that function but I also need User32.lib to link the dll to my project. Can somebody send this file to me, I could not find it on the Web.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Where can I get User32.lib file?

    If PrintWindow is the only one function from User32.dll you need to use then just use LoadLibrary/GetProcAddress, so you won't need the User32.lib.
    Victor Nijegorodov

  3. #3
    Join Date
    Sep 2021
    Posts
    11

    Re: Where can I get User32.lib file?

    Quote Originally Posted by VictorN View Post
    If PrintWindow is the only one function from User32.dll you need to use then just use LoadLibrary/GetProcAddress, so you won't need the User32.lib.
    Thank you. This sounds great but it is something I don't know.
    I found some information here: https://docs.microsoft.com/en-us/cpp...?view=msvc-160 . I tried to implement it but the linker still reports the same error "Unresolved external 'PrintWindow' ..."
    Could you help me with this.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Where can I get User32.lib file?

    Quote Originally Posted by ldor108 View Post
    Thank you. This sounds great but it is something I don't know.
    I found some information here: https://docs.microsoft.com/en-us/cpp...?view=msvc-160 . I tried to implement it but the linker still reports the same error "Unresolved external 'PrintWindow' ..."
    Could you help me with this.
    You may want to show your code.
    Victor Nijegorodov

  5. #5
    Join Date
    Sep 2021
    Posts
    11

    Re: Where can I get User32.lib file?

    I've found another example and here is the code that I made using it. The only thing that is unclear to me in this example is how to pass arguments to the function whose address is extracted from the dll. I tried to include the arguments in the parentheses following (ProcAdd), as in the code below. However the compiler reports an error "Extra parameter in call". If I figure out how to correctly pass arguments to PrintWindow, I expect this example to work.

    Code:
    // This part is not directly related to the example, it just initializes and displays the print dialog 
    ZeroMemory(&pd, sizeof(pd));
    pd.lStructSize = sizeof(pd);
    pd.hwndOwner   = hwnd;
    pd.hDevMode    = NULL;     // Don't forget to free or store hDevMode.
    pd.hDevNames   = NULL;     // Don't forget to free or store hDevNames.
    pd.Flags       = PD_USEDEVMODECOPIESANDCOLLATE | PD_RETURNDC;
    pd.nCopies     = 1;
    pd.nFromPage   = 0xFFFF;
    pd.nToPage     = 0xFFFF;
    pd.nMinPage    = 1;
    pd.nMaxPage    = 0xFFFF;
    
    PrintDlg(&pd);
    
    //This is the actual example I found for LoadLibrary/GetProcAddress
    // Get a handle to the DLL module.
    hinstLib = LoadLibrary(TEXT("user32.dll"));
    // If the handle is valid, try to get the function address.
     if (hinstLib != NULL) {
    	ProcAdd = (MYPROC) GetProcAddress(hinstLib, "PrintWindow");
    	// If the function address is valid, call the function.
            	if (NULL != ProcAdd) {
            	fRunTimeLinkSuccess = TRUE;
            	(ProcAdd) (hwnd,pd.hDC,PW_CLIENTONLY);  // this is where the compiler gives and error message
            }
            // Free the DLL module.
            fFreeResult = FreeLibrary(hinstLib);
    }

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Where can I get User32.lib file?

    I guess you have defined this ProcAdd not correct (unfortunately you didn't show the definition).
    See the correct example here: https://docs.microsoft.com/en-us/cpp...?view=msvc-160
    Victor Nijegorodov

  7. #7
    Join Date
    Sep 2021
    Posts
    11

    Re: Where can I get User32.lib file?

    Sorry, I forgot to show the definition. And you are right, I did not understand it correctly. Now I've changed the definition as follows:
    Code:
    typedef int (__cdecl *MYPROC)(HWND,HDC,UINT);
    Now there are no more errors, the code compiles. However, nothing happens when I try to print. I tried both printing and creating a pdf. Nothing happens in either case. Did I miss something in this code?

  8. #8
    Join Date
    Sep 2021
    Posts
    11

    Re: Where can I get User32.lib file?

    By the way, I've checked with the debugger, the line (ProcAdd) (hwnd,pd.hDC,PW_CLIENTONLY); is executed (my first thought was that maybe the program never reaches there but it does). So the problem must be somewhere else.

  9. #9
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Where can I get User32.lib file?

    very old Borland C of 1997 (that is the only development environment I have and know)
    If you're using Windows, then there is the free Visual Studio 2019 (or 2022 preview) community iDE/compiler.

    https://visualstudio.microsoft.com/f...eloper-offers/
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Where can I get User32.lib file?

    Quote Originally Posted by ldor108 View Post
    By the way, I've checked with the debugger, the line (ProcAdd) (hwnd,pd.hDC,PW_CLIENTONLY); is executed (my first thought was that maybe the program never reaches there but it does). So the problem must be somewhere else.
    What does the e (ProcAdd) (hwnd,pd.hDC,PW_CLIENTONLY); return? TRUE (some value != 0) or FALSE (0)?
    If it is FALSE then this function failed.
    Victor Nijegorodov

  11. #11
    Join Date
    Sep 2021
    Posts
    11

    Re: Where can I get User32.lib file?

    It returns TRUE.
    Well, probably 2kaud is right and the only solution is to switch to Visual Studio, although for the sake of using just one function it would probably be too much trouble.

  12. #12
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Where can I get User32.lib file?

    Yes - but you get the latest c/c++ compilers etc etc. There's been huge changes to the languages since 1997! I used to use Borland as well way back then!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  13. #13
    Join Date
    Sep 2021
    Posts
    11

    Re: Where can I get User32.lib file?

    Thank you guys, this discussion has been really helpful. I don't do programing so much so learning a new platform is not something I would prefer now. And, as (ProcAdd) (hwnd,pd.hDC,PW_CLIENTONLY); returns TRUE, it does not actually look like the problem is in Borland. Most probably i missed something in the initialization. I guess at this point I better start a new thread with a proper subject as the subject of this thread is too far from where it has arrived by now. Then maybe somebody who has good experience with printing will read it and will be able to help.

  14. #14
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Where can I get User32.lib file?

    [QUOTE=ldor108;2239997... Most probably i missed something in the initialization. ...[/QUOTE]
    You may want to look at the existing code examples in Web: https://www.google.com/search?q=prin...client=gws-wiz
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured