在dll和exe之间共享常量和变量 [英] sharing constants and variables between dll and exe

查看:277
本文介绍了在dll和exe之间共享常量和变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个包含3个部分的程序,主要dll,作为服务运行的.exe和具有通用代码和变量的dll.这个想法是主dll和exe都调用公用dll并共享变量/常量.但事实证明,它们都打开了通用dll的单独实例,因此没有共享变量.有没有办法解决这个问题,让他们使用通用dll的单个实例?
感谢您的帮助

标记

I am writing a program that consists of 3 parts, the main dll, an .exe which runs as a service and a dll with common code and variables. The idea was that both the main dll and the exe call the common dll and share variables/constants. But it turns out they both open a seperate instance of the common dll, thus no sharing the variables. Is there a way to solve this and let them use a single instance of the common dll?
Thanks for any help

Mark

推荐答案

您不能在dll之间共享变量.您可以做的是,将要共享的任何数据都放在外部数据存储区中,例如数据库,平面文件.
You can not share varibles across dlls. What you can do is, any data you want to share put it in external data storage area such as database, flat file.


您用"C#"标记问题,所以我ll假设当您说"DLL"时,意味着".Net程序集".

如果是这种情况,则共享程序集中的公共类或结构的任何公共静态字段和/或属性对于引用它们的任何程序集都是可见的.
You tag your question with "C#", so I''ll assume that when you say "DLL" you are implying ".Net assembly".

If that''s the case, then any public static fields and/or properties, of public classes or structs, in the shared assemblies will be visible to any assemblies that reference them.


这篇关于在dll和exe之间共享常量和变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆