Create a shared memory segment in C ++ Builder

zhaozj2021-02-08  237

Originally from community.borland.com Original name: Creating a Shared Memory Segment WITH C Builder 4.0 Translated Name: Create a shared memory segment C Builder 4.0 in C Builder is the first C that supports shared memory segments Builder compiler. This article explains how to use this feature in Windows DLL.

To change the data segment and class name, you need to add #pragma option -zr [segment name] and #pragma option -zt [class name] below to add a piece of code to 'Data'. Integer. File: shareddata.cpp # pragma option -zrshseg // Change the default data segment name #pragma option -ztshclass // Change the default data class name

// Initialize our intended data INT DATA = 0;

Note that the paragraph in this document is SHSEGSHCLASS. Linker requires a .def file to create a shared segment. The following is the content of the .def file.

File: shared.deflibrary shareddll

Segments SHSEG CLAS 'SHCLASS' Shared

Below is a DLL source file and header file containing the DLL entry point. Includes a method of setting up and acquires a shared memory segment. File: shareddll.h # idef __dll __ # define dll_export __declspec (dllexport) # Else # define dll_export __declspec (dllimport) #ENDIF

Extern "C" {void DLL_EXPORT SETDATA (INT X); int DLL_EXPORT GETDATA (VOID);

File: shareddll.cpp # include # pragma HDRSTOP

#include "shared.h" Useunit ("SharedData.cpp"); Usedef ("Shared.def"); int WinAPI DLLENTRYPOINT (Hinstance Hinst, Unsigned Long Reason, Void *) {Return 1;} Extern Int Data;

Void DLL_EXPORT SETDATA (INT X) {data = x;} int dll_export getdata (void) {return data;}

转载请注明原文地址:https://www.9cbs.com/read-2207.html

New Post(0)