One-day training of Windows API (82) loadlibrary Function

Source: Internet
Author: User
One-day training of Windows API (82) loadlibrary Function

With the expansion of software, more and more functions are required, and more developers are involved. Therefore, functional division of software has become a major task of modern software engineering, and concurrency of software development is becoming more and more important. To solve these problems, we will see that IT hardware is developing rapidly and functions are becoming more and more complex. However, the major improvement in hardware development lies in the use of IC to implement complex functions, that is to say, to integrate most functions together, you only need to provide some pins to implement the product. Is there any IC in the software that is the same as that in the hardware? I think it should be the dynamic Connection Library. In the Windows building, many cornerstones are dynamic connection libraries. A dynamic Connection Library encapsulates particularly complex functions, so users do not have to worry about how it is implemented. Of course, this also allows different developers to develop products at the same time, improving the speed of software development. To use functions in the dynamic connection library, you must use the loadlibrary function to load the dynamic Connection Library and use the getprocaddress function to obtain the function address.

The loadlibrary function declaration is as follows:

Winbaseapi
_ Out
Hmodule
Winapi
Loadlibrarya (
_ In lpcstr lplibfilename
);
Winbaseapi
_ Out
Hmodule
Winapi
Loadlibraryw (
_ In lpcwstr lplibfilename
);
# Ifdef Unicode
# Define loadlibrary loadlibraryw
# Else
# Define loadlibrary loadlibrarya
# Endif //! Unicode

Lplibfilename is the name of the dynamic Connection Library.

An example of calling a function is as follows:
#001 // load the dynamic Connection Library.
#002 // Cai junsheng 2007/12/03 QQ: 9073204 Shenzhen
#003 void testloaddll (void)
#004 {
#005 // load the dynamic Connection Library.
#006 hmodule hdlllib = loadlibrary (_ T ("kernel32.dll "));
#007 if (hdlllib)
#008 {
#009 // obtain the function address of the dynamic Connection Library.
#010 farproc fpfun = getprocaddress (hdlllib, "getversion ");
#011
#012 // call the function to run.
#013 DWORD dwversion = (* fpfun )();
#014
#015 // obtain the Windows version.
#016 DWORD dwwindowsmajorversion = (DWORD) (lobyte (loword (dwversion )));
#017 DWORD dwwindowsminorversion = (DWORD) (hibyte (loword (dwversion )));
#018
#019 // display.
#020 const int nbufsize = 512;
#021 tchar chbuf [nbufsize];
#022 zeromemory (chbuf, nbufsize );
#023
#024 wsprintf (chbuf, _ T ("display version: % d, % d/R/N "),
#025 dwwindowsmajorversion, dwwindowsminorversion );
#026 outputdebugstring (chbuf );
#027
#028 // release the dynamic Connection Library.
#029 freelibrary (hdlllib );
#030}
#031
#032}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.