外部“C” char ** environ - Windows - C ++ / CLI [英] extern "C" char** environ - Windows - C++/CLI

查看:210
本文介绍了外部“C” char ** environ - Windows - C ++ / CLI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些旧的linux代码我试图移植到Windows。
当我第一次建立它作为一个直的本地DLL,我没有问题这段代码,但是当我试图使它成为一个混合模式C ++ / CLI DLL,我得到一个未解决的外部对象错误:

I have some old linux code I'm trying to port to Windows. When I first built it as a straight native DLL, I go no issues with this piece of code, but when I tried making it a mixed-mode C++/CLI DLL, I got an unresolved external object error on this:

extern "C" char** environ;

为什么这将适用于本机而不是CLI?

Why would this work for native and not CLI? Any idea how to work around this, or what it even does?

推荐答案

保存环境变量(PATH ,等等)。 C标准(如果我记得正确)要求 environ 指向这些变量的数组。它们也作为 main 入口点函数的第三个参数传递。

That holds the environment variables (PATH, etc, etc). The C standard (if i recall correctly) requires environ to point to an array of these variables. They're also passed as the 3rd argument to the main entry point function.

显然,由于某种原因, C ++ / CLI不会初始化它。

Apparently, for some reason, the C++/CLI doesn't initialize that.

要解决这个问题,你可以自己分配它,并填写 getenv (C)或 Environment.GetEnvironmentVariables (托管C ++)。我不知道有什么就地修复,但它不应该太难。

To fix that, you can allocate it yourself and fill with either either getenv (C) or Environment.GetEnvironmentVariables (Managed C++). I don't know of any in-place fix, but it shouldn't be too hard.

这篇关于外部“C” char ** environ - Windows - C ++ / CLI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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