如何将变量值从一个项目传递到另一个项目 [英] how to pass value of variables from one project to another project

查看:108
本文介绍了如何将变量值从一个项目传递到另一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将变量的值从一个项目传递到另一个项目





i有1个exe,我必须将用户名传递给另一个项目(exe)

我该怎么办

解决方案

在运行期间没有project这样的东西。有两个应用程序,运行单独的进程。这些过程很好地隔离,在不同的地址空间中执行。他们无法沟通,除非他们是为此而设计的。在大多数情况下,解决两个不同进程中的一个应用程序问题是一个坏主意,您应该使用一个进程和线程。如果你不想合并它们,可以考虑使用现有项目之一作为另一个项目引用的类库。



其他一切都取决于你的细节。我只想补充说,如果你还有两个不同的进程,它们应该专门设计用于通信,这称为IPC。它可以通过命名管道,共享内存,套接字, TcpListener / TcpClient ,.NET远程处理,WCF进行通信...我不想进一步详细说明,作为问题太模糊了。



但首先,考虑在一个流程中拥有一个应用程序。这就是所有,基于您的有限信息。



-SA


您好,
我不确定你要求的是什么,但我在其他应用程序中传递共享设置的方式是使用注册表。



据我所知,你不需要管理员权限来执行此操作。



将变量保存到注册表的代码是:



 SaveSetting(  MyApp  启动  Top  75' 保存变量 





在这种情况下,变量的名称为Top,值为75

存储在以下注册表位置:

 [HKEY_CURRENT_USER \Software\VB和VBA Program Settings \ MyApp\Startup] 







在您的其他应用程序中读取变量的代码是:



< pre lang =vb> Messagebox.show( 你的变量是:& GetSetting( MyApp < span class =code-string> Startup, Top ' 读取变量







添加的骨头是这样可以节省你的变量,即使用户重新启动计算机后仍可使用。





附加说明:

你当在用户的计算机上存储原始文本时,可能想要使用某种加密方式进行保护。





欲了解更多信息,请访问:

http://msdn.microsoft.com/en-us/library/13zyfez5(V = VS.90)的.aspx APPID = Dev10IDEF1&安培; L = EN-US&安培; K = K(MICROSOFT.VISUALBASIC.INTERACTION。 GETSETTING)%3BK(TargetFrameworkMoniker - )%3BK(DevLang-VB)及 NETFRAMEWORK,VERSION%3dV3.5\" 。; RD =真安培; CS-保存琅= 1&安培; CS琅= VB#代码片断-1 [ ^ ]


how to pass value of variables from one project to another project


i have 1 exe and i have to pass user name to another project (exe)
how can i do

解决方案

There is no such thing as "project" during runtime. There are two applications, running separate processes. The processes are well isolated, executed in different address spaces. They cannot communicate unless they are designed for that. In most cases, solving one application problem in two different processes is a bad idea, you should rather have one process and threading. Think about using one of existing project as a class library referenced by another project, if you don't want to merge them.

Everything else depends on your detail. I just can add that if you still have two different processes, they should be specially designed to communication, which is called IPC. It can be communication via named pipes, shared memory, sockets, TcpListener/TcpClient, .NET remoting, WCF… I don't want to go into further detail, as the question was too vague.

But first of all, think about having one application in one process. That's all, based on your limited information.

—SA


Hello,
I am not sure what you are asking for but the way I pass share settings across my other applications is to use the registry.

As far as I am aware you do not need Administrator permissions to do this.

The code to save a variable to the registry is:

SaveSetting("MyApp", "Startup", "Top", "75") ' Save the variable



In this case the variable's name is "Top" And the value is "75"
It is stored in the following registry location:

[HKEY_CURRENT_USER\Software\VB and VBA Program Settings\MyApp\Startup]




And the code to read the variable in your other application is:

Messagebox.show("Your variable is: " & GetSetting("MyApp", "Startup", "Top", "") ' Read the variable




The added bones is that this will save your variable and is still usable even after the User restarts there computer.


Additional notes:
You may want to conceder using some kind of encryption when storing raw text on a User's computer.


For more information please visit:
http://msdn.microsoft.com/en-us/library/13zyfez5(v=vs.90).aspx?appId=Dev10IDEF1&l=EN-US&k=k(MICROSOFT.VISUALBASIC.INTERACTION.GETSETTING)%3bk(TargetFrameworkMoniker-".NETFRAMEWORK,VERSION%3dV3.5")%3bk(DevLang-VB)&rd=true&cs-save-lang=1&cs-lang=vb#code-snippet-1[^]


这篇关于如何将变量值从一个项目传递到另一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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