Changes through SetEnvironmentVariable do not take effect in a library that uses getenv

I have a simple C # application that links a library to the mingnu compiler. I can easily call functions in the library without any problems.

However, the library calls getenvto set itself, this environment variable must be configured for the library to work correctly, so I use Environment.SetEnvironmentVariable, however, the library cannot get the value that I set.

+4
source share
3 answers

getenv . SetEnvironmentVariable , getenv. setenv, getenv.

: http://msdn.microsoft.com/en-us/library/tehxacec(VS.71).aspx

"getenv _putenv , _environ, . getenv , , " ", . , envp main wmain, . "

+5

_putenv_s #, , ++.

InteropServices:

using System.Runtime.InteropServices;

public class TestEnv
{
    [DllImport( "msvcrt.dll" )]
    public static extern int _putenv_s( string e, string v );

    public TestEnv()
    {
        _putenv_s( "ENV_VAR", "VALUE" );
    }
}

, .

+3

See here the P / Invoke Signature Generator .

Download Link Microsoft CLRInsideOut2008_01.exe

0
source

Source: https://habr.com/ru/post/1787585/


All Articles