BCB编写DLL的问题

yesry 2003-10-24 09:08:17
项目:ShareMemory
//+-+-+-+-+-+-+ uShareMemory.cpp -+-+-+-+-+-+-+-+-+-
extern char buff[100];

extern "C"
__declspec(dllexport) void WINAPI
Mem(char *p)
{
if(p[0])
{
strcpy(buff,p);
}else
{
strcpy(p,buff);
}
}

//+-+-+-+-+-+-+ ShareUnit.cpp -+-+-+-+-+-+-+-+-+-
#pragma option -zRShareSEG // 改变缺省数据段名
#pragma option -zTShareCLASS // 改变缺省数据类名
char buff[100];
int LoadCount=0; // DLL装入次数计数
int ShareVar=9;
#include "ShareUnit.h"


//+-+-+-+-+-+-+ ShareUnit.def -+-+-+-+-+-+-+-+-+-
SEGMENTS ShareSEG CLASS 'ShareCLASS' SHARED




出现错误了
[Linker error] Section ShareSEG define in .def file is empty

我不知道如何解决[精华去还说解决了,但我不知道缺少什么]
还望各位大侠赐教!不胜感激!
...全文
26 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yesry 2003-10-24
  • 打赏
  • 举报
回复
整理后:
工程的名字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

yesry 2003-10-24
  • 打赏
  • 举报
回复
真是谢谢fatwave,虽然没有直接指导,但是给出的例子却是通过了。
经过一番比较,LIBRARY SharedDll可以不用。
(1)ShareUnit.cpp文件中必须用struct,(2)并且必须申明一个该struct的全局变量,(3)并且一定要对这样的struct进行初始化。(4)输出DLL的函数必须至少使用一次上述的struct.

要满足上述4条件才行。
fatwave 2003-10-24
  • 打赏
  • 举报
回复
我做过!

#pragma option -zRShareSEG // 改变缺省数据段名
#pragma option -zTShareCLASS // 改变缺省数据类名

改成,我是用这个的
#pragma option -zRSHSEG
#pragma option -zTSHCLASS

//-++-+-+--+-文件ShareMemory.def
LIBRARY SharedDll
SEGMENTS
SHSEG CLASS 'SHCLASS' SHARED

经常看到你的帖子!!MSN:jx_wbo@hotmail.com,有空聊聊!

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧