简体   繁体   English

C#dll导入和环境变量

[英]C# dllImport and Environment Variables

This is a tough one to explain, but I will do my best. 这很难解释,但我会尽力而为。 I writing a C# program and am using DLLImport to access Unmanaged Code in an external C++ DLL. 我正在编写C#程序,并且正在使用DLLImport来访问外部C ++ DLL中的非托管代码。 The C++ DLL is a wrapper to a java program. C ++ DLL是Java程序的包装。 I can only get it to work if I call my C# program is called within a DOS batch file that sets various Environment Variables that are required by the C++/Java external functions. 只有在DOS批处理文件中调用我的C#程序时,它才能工作,该批处理文件设置了C ++ / Java外部函数所需的各种环境变量。 I want to be able to not use a DOS batch file and set and control the Environment Variables withing my C# program. 我希望不能使用DOS批处理文件,而不能通过C#程序设置和控制环境变量。 Seeking tips form anyone as I have not found a way to do this, or know if it even possible. 寻求技巧的人来自任何人,因为我还没有找到做到这一点的方法,或者甚至知道是否有可能。 Thanks. 谢谢。

What's about 关于什么

public static void SetEnvironmentVariable(
    string variable,
    string value,
     EnvironmentVariableTarget targer
)

This function sets Enviroment variable 此函数设置环境变量

using System
....
Environment.SetEnvironmentVariable(envName, envValue,EnvironmentVariableTarget.Machine);

Look example at msdn http://msdn.microsoft.com/en-us/library/z46c489x%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1 在msdn http://msdn.microsoft.com/zh-cn/library/z46c489x%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1中查看示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM