DLL, dll syntax

Source: Internet
Author: User

DLL, dll syntax

By default, all data segments are independent of processes, and each process has its own copy. However, sometimes a process shares a data segment. Therefore, the VC ++ compilation Connector provides a special syntax. The following is a typical example. A Shared data segment named Shared is created, there is only one variable g_hwndOwner in this data segment.


//////////////////////////////////////// ///// Process sharing zone /////////////////////////////// ///// // # pragma data_seg ("Shared ") HWND g_hwndOwner = NULL; // call the main window of the SetWindowsHookEx thread # pragma data_seg () # pragma comment (linker, "/section: Shared, rws") // readable, writable, process sharing. All processes that load this dll share the same memory.


Simple things often make mistakes. The following are some syntax issues that need attention:

(1) If the data segment name is "Shared", make sure that the segment name is exactly the same as "Shared" and case sensitive when setting the attribute of the segment. If the two are different, the connector will warn you of an error.

> LINK: warning LNK4039: the SECTION "Shar2ed" specified by the/SECTION option does not exist. Note that a warning error occurs. Therefore, the DLL file will continue to be compiled successfully, but the Shared data segment is not set as the Shared data segment.


(2) the variables in the shared segment must be initialized. Otherwise, the connector will report an error and cannot be properly set as the shared segment.

1> LINK: warning LNK4039: the SECTION "Shared" specified by the/SECTION option does not exist. But continue to generate the dll file.


(3) there must be no space before rws in the last row; otherwise, the compiler reports an error.

1> main. obj: fatal error LNK1276: the invalid command "rws" is found. It does not start. Then stop the compilation connection.


The three most serious errors are (1) and (2), because although the shared segment is not successfully set, the compilation is still successful. If you do not pay attention to them, it will be very dangerous. For (3), compilation is not successful at all, so you only need to understand the syntax modification, there is no potential danger.


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.