Vb. NET Foundation of Dll__.net

Source: Internet
Author: User
Tags try catch win32
Wedge

In vb.net video learning, once again ran into the DLL this dongdong. The two simple small systems previously dealt with DLLs, and then gave them away when they knew the DLL was the English abbreviation for the dynamic link library. Results now the vb.net video of the DLL again appeared, really worthy of the teacher said that "owed the general will return." Today we are going to make a mental repair from DLL and DLL files.DLLA DLL is an acronym for a dynamic link library, which is all called the Dynamics link libraries. is a giant in the software world. Microsoft has a way of implementing the concept of shared libraries in Windows systems.
DLLs are used primarily for sharing and updating these two areas. In the area of sharing, DLLs are primarily used to share data between the time dimension and the individual level through DLL files, which are initially shared with DLL files.
Where data is shared on the time dimension refers to the fact that multiple applications can access the contents of a single DLL copy in memory at the same time. It is necessary to explain what is different function before the data is shared at the individual level. An XOR function is one that is written in different languages to achieve the same function. For example, the same error-handling language, which is reflected in VB, is On Error Goto. NET, a try Catch is the embodiment of the language. And what is called a different function call is through a DLL, we can give the process a call to a function that does not belong to its executable code.     This approach is similar to the adapter pattern we are exposed to in design patterns. On the update side, the DLL is mainly in the update of our team's large system. For example, a dozens of G 3D game needs to update a role, we do not have to refactor those several G software code, only need to add the corresponding DLL file or to update the corresponding DLL file to achieve our integrity to maintain the established objectives.DLL File definitionThe dynamic link library file, also known as "Application Expansion", is a binary file that is not executable and belongs to a software file type. DLL documents generally exist in the "C/windows/system32" directory of the computer. It allows programs to share the code and other resources necessary to perform special tasks. Many of the applications we use today are not a complete, indivisible, monolithic executable, but consist of a number of dynamically-linked library files that are fragmented and relatively independent. This coincides with object-oriented thinking, which increases the ER reusability of code and facilitates the maintenance and extension of code.
ClassificationSome of the files in the Windows operating system that implement DLLs have. The ActiveX (. OCR) file is defined by Microsoft's Authoritative Software Development Guide MSDN (Microsoft Developer Network), which is also known as an OLE control or OCX control. It is a component or object that can be inserted into a Web page or other application to provide multimedia effects, interactive objects, and complex programs for Web pages or other applications. Example: Calendar control, select a date from the calendar. activex--Baidu Encyclopedia. The CPL File CPL (Control Panel item) file is also referred to as the dashboard entry, which is saved more than the System32 file in the system installation directory. They correspond to the items in the Control Panel respectively. Normal users do not have the appropriate access rights. The CPL file is essentially a Windows executable, but it does not belong to a file that can be run directly, and needs to be opened through the Shell32.dll file. Cpl file--Baidu encyclopedia. DRV files. DRV (Device Driver) file, a file that communicates with the computer and its devices, as we have previously contacted in the introduction to the operating system. Device driver--Baidu EncyclopediafeaturesOne, with fewer resources when multiple programs use a function library at the same time, DLLs can have multiple programs make the appropriate access by building multiple copies to reduce the amount of code that DLL files load in the disk and physical memory already cached.     (quite a sense of monkey king pulling hair to small monkeys) second, the extension of modular architecture DLL files itself is a good embodiment of the encapsulation of object-oriented thinking, which makes it fairly straightforward to develop programs that provide multiple-language versions of large systems or that have modular architecture. Iii. simplifying deployment and installation when a DLL file in a system needs to be updated or a corresponding change is required, deploying and installing new DLLs does not require two links to the system and DLL files. In addition, if multiple modules share a DLL file, all of these modules will benefit from this update or modification.DependenciesWhen a program or a DLL file needs to invoke another DLL file, a dependency is created in the appropriate program or DLL file to make the DLL call successful. After the DLL file is invoked, the program or the DLL file is no longer independent. And if there is a problem with the invoked DLL file, then the program or DLL that invokes the DLL file will also have a corresponding problem.Use linksWhen a DLL is loaded in an application, it can be invoked through two linking methods: Dynamic linking and run-time dynamic linking. Dynamic linking at run time, the application calls the LoadLibraryEx function to load the DLL at run time. After the DLL is successfully loaded, you can use Getpro to obtain the address of the exported DLL function that needs to be invoked from the addressing function, and you do not need to import the library file when you use Run-time dynamic linking.
entry pointWhen you create a DLL, you can optionally make an entry point function. The entry point function is invoked when processes or threads themselves attach them to the DLL or detach themselves from the DLL. We can use the entry point function for data structure initialization or data structure of the clear 0 work. If the application is multi-threaded, we can use thread local storage (TLS) in the entry point function to allocate memory specific to each thread. Example of DLL entry functions:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:24PX;" >bool apientry DllMain (
    HANDLE hmodule,//             DLL module handle
    DWORD Ul_reason_for_call,//   reason
    for calling this function) LPVOID lpreserved           //Hold
) {
    switch (ul_reason_for_call)
    {case
        Dll_process_attach:
            // The process is loading this DLL break
        ;
        Case Dll_thread_attach:
            //A thread is created break
        ;
        Case Dll_thread_detach:
            //A thread normally exits the break
        ;
        Case Dll_process_detach:
            //The process is uninstalling this DLL break
        ;
    }
    return TRUE;            Returns true indicating successful execution of this function
}</span>

When the entry point function returns a value of FALSE, the application will not be started if we use the load-time dynamic link, and if we use the Run-time dynamic link, then only the individual DLL files will not be loaded (the application can be started, but some of the features cannot be used.) Some software developers use this method to run the free version and the billing version. In addition, the entry point function should perform a simple initialization task and should not call any other DLL load function or terminate function. ExportWe can implement the export of DLL files by adding function keywords to DLL functions that need to be exported or by creating template definition files (. def files).     To add a function keyword to a DLL file: _decispec (dllexport): Declares the function that needs to be exported, thereby obtaining permission to use the function keyword. _decispec (dllimport): Use this keyword to declare a function that needs to be imported, thereby obtaining permission to use the Import function. Typically, a header file containing define statements and IFDEF statements is used to differentiate between export statements and import statements. Special CallUsing the Win32 API in DLL functions or using a language-generated DLL for other languages, you need to do the appropriate processing one, the use of the Win32 API in DLL functions requires the help of the keyword _stdcall two, the DLL generated in one language for use in other languages, DLL generated in C + + for standard C language use for example 1, the output file needs to use the extern "C" modifier 2, the Export function format should be in the. def file format If you use the _stdcall invocation method, you may produce C unrecognized decorated name, so you need to set the export file as. def Piece form, not _decispex (dllexport) Form. Because _decispec (dllexport) will be decorated name conversion, C language is not recognized. Trouble ShootingMicrosoft offers a number of tools to help us solve DLL problems, and we'll just introduce the (DW) Dependency Walker and Dups (DLL Universal Problem solver). DWThe DW tool can be recursively scanned for all dependent DLLs that are used by the program. When we open the application in DWR, DW does the following: Dependency Walker checks to see if the DLL is missing.
Dependency Walker Check for invalid program files or DLLs.
Dependency Walker checks whether the import function matches the exported function.
Dependency Walker checks for cyclic dependency errors.
Dependency Walker checks for modules that are not valid due to a different operating system.
By using Dependency Walker, you can record all the DLLs that your program uses. This may help to avoid and correct DLL problems that may occur in the future. When you install Microsoft Visual Studio 6.0, Dependency Walker will be located in the following directory:
Drive\program Files\Microsoft Visual Studio\Common\Tools
dupsThe Dups tool is used to audit, compare, record, and display DLL information. The following table describes the utilities that make up the dups tool:
Dlister.exe: The utility enumerates all the DLLs in the computer and logs this information to a text file or database file.
Dcomp.exe: This utility compares the DLLs listed in two text files and produces a third text file that contains differences.
Dtxt2DB.exe: This utility will be loaded into the Dllhell database by using a text file created by the Dlister.exe utility and the Dcomp.exe utility.
DlgDtxt2DB.exe: This utility provides a graphical user interface (GUI) version of the Dtxt2DB.exe utility.
Well, for the DLL and DLL file to share with you here. These things I am also the first contact, some places are still very vague, like the great God to teach a lot ~ ~ ~ ~
SummaryThrough the DLL we can easily realize a lot of complex functions, and can realize the various benefits of object-oriented programming, saying "All the world are objects", to be a programmer is really too happy ~ ~ ~ Thank you for your valuable time, wish you happy. -joker

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.