[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.
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.
Re: Where can I get User32.lib file?
Quote:
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.
Re: Where can I get User32.lib file?
Quote:
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.
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);
}
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
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?
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.
Re: Where can I get User32.lib file?
Quote:
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/
Re: Where can I get User32.lib file?
Quote:
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.
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.
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!
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.
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