Extern "C" char ** environ - Windows - C ++ / CLI

I have old Linux code that I am trying to connect to Windows. When I first built it as a direct native DLL, I was not afraid of this piece of code, but when I tried to make it a mixed C ++ / CLI DLL, I had an unresolved external object error:

extern "C" char** environ; 

Why does this work for the native and not for the CLI? Any idea how to get around this or what it does?

+2
source share
1 answer

This contains environment variables (PATH, etc., etc.). The C standard (if I remember correctly) requires the environ point to an array of these variables. They are also passed as the third argument to the main entry function.

Apparently, for some reason, the C ++ / CLI does not initialize this.

To fix this, you can select it yourself and fill in either getenv (C) or Environment.GetEnvironmentVariables (managed by C ++). I do not know any corrections in place, but this should not be too complicated.

+3
source

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


All Articles