dll的环境变量不同于exe [英] Environment variables are different for dll than exe

查看:425
本文介绍了dll的环境变量不同于exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试一个64位应用程序,其中c#exe正在使用本机c ++ dll,在Windows 7上。似乎环境变量是不同的这两个,即使他们都在同一个进程中执行。如何调用System.Environment.SetEnvironmentVariable对getenv()返回的值没有影响?

I'm debugging an 64-bit application where c# exe is using native c++ dll, on Windows 7. It seems environment variables are different for these two, even though they are both executing in the same process. How is it possible that calling System.Environment.SetEnvironmentVariable has no effect on values returned by getenv()?

推荐答案

只是一个数据块,当它开始时被窗口传递给进程。您正在使用的运行时函数(System.Environment的BCL和getenv的CRT)可能在启动期间创建环境的副本,这意味着它们不在相同的环境变量上操作。

The environment variables are just a blob of data which gets passed by windows to the process when it starts. The runtime functions you are using (The BCL for System.Environment and the CRT for getenv) are probably making copies of the environment during startup, which means they are not operating on the same "environment" variables.

从概念上讲,他们必须这样做,因为否则需要一些方法来同步他们访问环境。

Conceptually they must do this because otherwise there would need to be some way to synchronize them accessing the environment.

这篇关于dll的环境变量不同于exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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