Syntax issues to be noted in building a process shared data segment in a DLL

Source: Internet
Author: User

By default, all data segments are process independent and each process has its own copy. But sometimes the process of sharing a data segment is also necessary, for this VC + + compiler connector provides a special syntax, the following is a typical example, the establishment of a shared data section named shared, the data segment has only one variable G_hwndowner.


The process sharing area///////////////////////////////////////#pragma data_seg (" Shared ") HWND G_hwndowner = null;//call SetWindowsHookEx The main window of the thread #pragma data_seg () #pragma comment (linker,"/SECTION: Shared,rws ")//readable, writable, inter-process sharing. All processes that load this DLL share a portion of memory


Seemingly simple things, but it is often easy for us to make mistakes. Here are a few syntax questions to be aware of:

(1) The name of the data segment is "shared", so when setting this property, make sure that the segment name is exactly the same as "shared" and is case sensitive. Once the two are different, the connector warns of errors.

>link:warning LNK4039: The section "shar2ed" specified with the/SECTION option does not exist. Note that it is a warning error, so the DLL file will continue to compile the connection successfully, except that the shared data segment is not set to share segment.


(2) The variables in the shared segment must be initialized, or the connector will error, and it cannot be set as a shared segment.

1>link:warning LNK4039: The section "shared" specified with the/SECTION option does not exist. However, the DLL file continues to be generated.


(3) The last row of RWS can not have a space before, or the compiler error.

1>main.obj:fatal error LNK1276: Found invalid instruction "RWS"; not beginning with "/". Then stop compiling the connection.


The three kinds of errors, the most serious is (1) and (2), because although the shared segment has not been successfully set, but still compiled successfully, a little attention, it will be very dangerous. for (3) It is not possible to compile successfully, so as long as the understanding of syntax modification can be, there is no potential danger.


??

Syntax issues to be noted in building a process shared data segment in a DLL

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.