从非托管 c++ 调用托管 c# 组件 代码,我如何定义配置

发布于 2024-07-25 11:42:13 字数 213 浏览 2 评论 0原文

我想从非托管 C++ 服务调用 C# 组件。 我需要设置 C# 组件所需的配置项。 config 应该是什么名称以及它应该位于哪里。

例如。 Parentfolder\cplusplusservice.exe

anotherfolder\csharp.dll

我需要 csharp.dll.config 或其等效项。

谢谢,

I want to call a C# component from an unmanaged c++ service. I need to set config items expected by the C# component. What name should be config be and where should it be located.

eg.
parentfolder\cplusplusservice.exe

anotherfolder\csharp.dll

i need csharp.dll.config or its equivalent.

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

余厌 2024-08-01 11:42:13

.config 文件的名称需要与应用程序的名称相同。 当非托管代码首次调用托管代码时,会创建一个 AppDomain,该 AppDomain 控制加载哪个配置文件以及从何处加载。

您需要手动将 .config 文件复制到输出目录并以应用程序名称命名,或者创建一个后期构建来执行此操作。

基本上,适用于纯托管应用程序的 .config 文件所在位置的相同规则也适用于加载托管代码的非托管应用程序。

The .config file needs to be named the same as the application's name. When the unmanaged code first calls into the managed code an AppDomain is created that AppDomain controls which config file is loaded and from where.

You will need to manually copy the .config file to the output directory and name it after the application name or create a post-build to do so.

Basically the same rules that apply to where .config files need to be for pure managed apps apply to unmanaged apps that load managed code.

╰◇生如夏花灿烂 2024-08-01 11:42:13

这取决于托管托管代码的 AppDomain 的创建方式。

例如,如果您将托管代码公开为 COM,它将被加载到默认的 AppDomain 中,并且配置文件将与可执行文件位于同一目录中(在您的情况下为parentfolder\cplusplusservice.exe.config)。

如果您自己创建 AppDomain,则可以控制配置文件的位置。

It depends on how the AppDomain that is hosting your managed code is created.

For example, if you are exposing the managed code as COM, it will be loaded into the default AppDomain, and the configuration file will be in the same directory as the executable (parentfolder\cplusplusservice.exe.config in your case).

If you are creating the AppDomain yourself, you can control where the configuration file is located.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文