将数据写入dll [英] write data to dll

查看:82
本文介绍了将数据写入dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的项目(主要)中,我需要服务器名称,用户名和密码.要获得此信息,我需要一个.dll文件.而另一个项目(安装程序)将此值写入dll.公司不需要文本文件.

如果我写;

公共静态字符串servername ="servername"

像这样

公共无效的get_servername()

返回服务器名称;

我可以阅读

问题是我不知道如何从安装项目向dll发送信息.

解决方案

不确定为什么需要DLL获取该信息.您也不要将值写入DLL.一旦代码被编译,数据就无法更改.您可以在DLL中调用函数,就是这样.

配置数据必须存储在代码之外.尽管注册表和特定于用户的配置文件也很常见,但配置文件是最常见的位置.这是您唯一可以存储在编译后(例如在安装过程中)更改的数据的地方 或运行时).

给出您的代码示例,其中服务器名是硬编码的,这就是返回的全部内容.您的安装程序无法更改该设置.相反,您需要做的是修改get_servername以从您的安装程序中获取信息. 程序可以写入(同样:配置文件,注册表,用户特定的位置等).

迈克尔·泰勒
http://www.michaeltaylorp3.net


In my project(Main) I need server name, username and password. To get this informations, I need a .dll file. And the other project(setup) write this value in dll..Company doesnt want text file.

If I write;

public static string servername="servername"

and methot like this

public void get_servername()

return servername;

I can read it

the problem is I dont know how I send infos from setup project to dll.

解决方案

Not sure why you need a DLL to get that information. You also don't write values into DLLs. Once the code is compiled, the data cannot change. You can call functions in the DLL but that is it.

Configuration data must be stored outside your code. The config file is the most common place although the registry and user-specific config files are also common. This is the only place you can store data that changes after compilation (such as during setup or runtime).

Given your code example, with servername being hard coded that is all that would ever get returned. Your setup program cannot change that. What you would need to do instead is modify get_servername to retrieve the information from somewhere that your setup program can write to (again: config file, registry, user-specific location, etc).

Michael Taylor
http://www.michaeltaylorp3.net


这篇关于将数据写入dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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