-
September 15th, 2021, 06:15 AM
#1
[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.
-
September 15th, 2021, 06:27 AM
#2
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
-
September 15th, 2021, 08:27 AM
#3
Re: Where can I get User32.lib file?
![Quote](images/misc/quote_icon.png) Originally Posted by VictorN
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.
-
September 15th, 2021, 10:26 AM
#4
Re: Where can I get User32.lib file?
![Quote](images/misc/quote_icon.png) Originally Posted by ldor108
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
-
September 16th, 2021, 01:32 AM
#5
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);
}
-
September 16th, 2021, 02:09 AM
#6
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
-
September 16th, 2021, 02:36 AM
#7
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?
-
September 16th, 2021, 02:39 AM
#8
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.
-
September 16th, 2021, 03:13 AM
#9
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)
-
September 16th, 2021, 03:22 AM
#10
Re: Where can I get User32.lib file?
![Quote](images/misc/quote_icon.png) Originally Posted by ldor108
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
-
September 16th, 2021, 03:37 AM
#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.
-
September 16th, 2021, 04:29 AM
#12
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)
-
September 16th, 2021, 05:33 AM
#13
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.
-
September 16th, 2021, 05:51 AM
#14
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|