DLL共享内存的问题

AreDreaming 2002-09-26 04:39:21
我想让我的DLL文件共享内存,以便与多次调用的时候能够对同一内存进行操作?
有几种方法可以做呢?
...全文
181 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
siphonelee 2002-09-26
  • 打赏
  • 举报
回复
static FILE* *fp = stdout;
没见过这么用的
你用CreateFile吧
AreDreaming 2002-09-26
  • 打赏
  • 举报
回复
加入stdout之后却出现了错误:
error C2099: initializer is not a constant
不知道是不是由这引起的?
siphonelee 2002-09-26
  • 打赏
  • 举报
回复
把包含psConvert()函数的DLL加入到工程了
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
你怎么加的?

stdout是标准输出,一般是显示器
qxwang 2002-09-26
  • 打赏
  • 举报
回复


CreateFileMapping
MapViewOfFile
OpenFileMapping
UnmapViewOfFile
AreDreaming 2002-09-26
  • 打赏
  • 举报
回复
static FILE *tmpfp = NULL, *fp = stdout;

中的stdout是啥子呀?
AreDreaming 2002-09-26
  • 打赏
  • 举报
回复
UP
AreDreaming 2002-09-26
  • 打赏
  • 举报
回复
真的很谢谢
不过我还有一个编译错误的问题不能解决,非常着急:
Linking...
psConvDlg.obj : error LNK2001: unresolved external symbol _psConvert
.\Debug/Dfv.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

我是使用VC6.0编译别人VC5.0的程序。
而且我把包含psConvert()函数的DLL加入到工程了。那么这可能由什么原因引起的呢?
taoni 2002-09-26
  • 打赏
  • 举报
回复
#pragma data_seg ("mydata")
int nValue = 5 ;
#pragma data_seg()
在.def文件中写
SECTIONS
mydata READ WRITE SHARED
目前只知道这个了。
masterz 2002-09-26
  • 打赏
  • 举报
回复
DLL Programming Hints


--------------------------------------------------------------------------------
This contains hints to developing DLL's. I'll continue to add them as time goes on. If you know something that may help people developing DLL's, please email me.
Last updated July 27, 1998


--------------------------------------------------------------------------------

Shared Memory
Thanks to Jim Lyssy for his additions and improvements.

Quite often, the same DLL is loaded in different process spaces. This means special code needs to be written to share data by all instances of the DLL.

When sharing data in a DLL, it is important to know if the data is initialized or uninitialized. Uninitialized data is placed into a bss_seg. By keeping the data initialized, the data_seg pragma may then be used. To simply initialize the data, it can be placed in a structure, then initialize it by a {0}. (see example)

Example:
Create an initialized data structure in a DLL.


#pragma data_seg(".SECNAME")
/* Data declarations go here*/
static struct
{
int A;
int B;
}MySharedData = {0};
#pragma data_seg()

After this, the linker needs to be advised that this section is a shared section. This can be done a couple ways. One way is to place this option right after the #pragma data_seg() call.


//option passed to the linker to share the segment
#pragma comment(linker,"section:/.SECNAME:rws")

Another method is to define the section as sharable in the DEF file. Following is a snippet of a DEF file for a library named LibName with a shared section named .SECNAME.


LIBRARY LibName
SECTIONS
.SECNAME READ WRITE SHARED

If you want to have the data unitialized, use bss_seg(). This isn't often used, because the DLL tends to need a starting point for the data.

Example:
Create an uninitialized shared data structure in a DLL.


#pragma bss_seg("Share")
static struct
{
int A;
int B;
} MySharedData;
#pragma bss_seg()

//options passed to linker to share the segment
#pragma comment(linker, "section:/Share:rws");

masterz 2002-09-26
  • 打赏
  • 举报
回复
http://www.codeproject.com/dll/data_seg_share.asp
How to share a data segment in a DLL
http://support.microsoft.com/default.aspx?scid=KB;EN-US;q125677&
HOWTO: Share Data Between Different Mappings of a DLL

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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