G
Guest
We are having difficulties getting environment variable within native DLL
written in C++ which is loaded by C# .NET assembly, the env var is set by the
..NET assembly.
We have an existing C++ application, and want to access it within C#. So we
wrote Managed C++ wrapper which access the native C++ DLL. The Managed C++
wrapper is compiled as .NET assembly that C# can access.
The native C++ DLL need to have an environment variable set to work
properly. So within the C#, we use:
[DllImport("Kernel32.dll")]
public static extern int SetEnvironmentVariable( string name , string
value );
to set the env var.
But within the native C++ DLL, it will fail when trying to do "getenv()",
with error:
Object reference not set to an instance of an object.
1. If we make the C# application as console application and set env var in
the console before start the C# application, it works. But we can't make the
C# app a console app.
2. If we execute within the C# application a .bat file which prints out the
env var, it shows that the env var is set.
Looks that the native C++ DLL can't getenv() on the env var set within the
C# app.
Any solutions for this?
Thanks a lot.
written in C++ which is loaded by C# .NET assembly, the env var is set by the
..NET assembly.
We have an existing C++ application, and want to access it within C#. So we
wrote Managed C++ wrapper which access the native C++ DLL. The Managed C++
wrapper is compiled as .NET assembly that C# can access.
The native C++ DLL need to have an environment variable set to work
properly. So within the C#, we use:
[DllImport("Kernel32.dll")]
public static extern int SetEnvironmentVariable( string name , string
value );
to set the env var.
But within the native C++ DLL, it will fail when trying to do "getenv()",
with error:
Object reference not set to an instance of an object.
1. If we make the C# application as console application and set env var in
the console before start the C# application, it works. But we can't make the
C# app a console app.
2. If we execute within the C# application a .bat file which prints out the
env var, it shows that the env var is set.
Looks that the native C++ DLL can't getenv() on the env var set within the
C# app.
Any solutions for this?
Thanks a lot.