您的位置:首页 > 编程语言 > C语言/C++

C++Builder编写dll时如何添加共享数据段

2006-09-07 11:01 706 查看
yesry (噎死你)

回复于 2003-10-24 11:56:55 得分 0

整理后:
工程的名字ShareMemory

//-++-+-+--+-文件uShareMemory.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#include <windows.h>
#pragma hdrstop
#include "SharedUnit.h"
#pragma argsused

extern int Data;
extern struct test t;
extern char buff[100];

int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
strcpy(t.sb,"ffff");//不知道为什么无用的也做一做
return 1;
}
//---------------------------------------------------------------------------

#define DLL_EXPORT extern "C" __declspec(dllexport)

DLL_EXPORT
void WINAPI SetData(char *p)
{
strcpy(buff,p);
}

DLL_EXPORT
void WINAPI GetData(char *p)
{
strcpy(p,buff);
}

//-++-+-+--+-文件ShareUnit.h
#include <vcl.h>
struct test
{
int age;
int xy;
char *sb;
};

//-++-+-+--+-文件ShareUnit.cpp
#pragma option -zRSHSEG
#pragma option -zTSHCLASS
#include "SharedUnit.h"

int Data = 0;
test t={120,10,"asdg"};//必须的,不管你用不用
char buff[100];

//-++-+-+--+-文件ShareMemory.def
SEGMENTS SHSEG CLASS 'SHCLASS' SHARED
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: