将确定性路径代码从 C# 转换为 C++

发布于 2024-10-12 23:27:51 字数 321 浏览 7 评论 0原文

有谁知道如何将其(从 C#)转换为 C++?

string location = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ZigbeeCommUSB)).CodeBase);
location = location.Substring(location.IndexOf("\\") + 1);

谢谢。

编辑:附加信息

这是从 C# 转换为本机 C++。如果有另一种方法来获取当前正在执行的可执行文件的文件路径,我愿意接受想法。谢谢。

Does anyone know how I can convert this (from C#) to C++?

string location = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ZigbeeCommUSB)).CodeBase);
location = location.Substring(location.IndexOf("\\") + 1);

Thanks.

EDIT: Additional Information

This is to convert from C# to native C++. If there is another way to get the file path of the currently executing executable, I am open to ideas. Thanks.

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

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

发布评论

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

评论(2

辞慾 2024-10-19 23:27:51

上面链接中的 Assembly.GetAssembly 示例

Assembly^ SampleAssembly;
// Instantiate a target object.
Int32 Integer1(0);
Type^ Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.  
SampleAssembly = Assembly::GetAssembly( Integer1.GetType() );
// Gets the location of the assembly using file: protocol.
Console::WriteLine( "CodeBase= {0}", SampleAssembly->CodeBase );

如果您结合上述内容,您可能会更接近您想要的做。 如果这是在 Native C++ 中完成的,你会遇到更多的问题,有一个叫做 "Fusion API" 可能会帮助您在 GAC 中查找程序集。

Example of Assembly.GetAssembly from the above link

Assembly^ SampleAssembly;
// Instantiate a target object.
Int32 Integer1(0);
Type^ Type1;
// Set the Type instance to the target class type.
Type1 = Integer1.GetType();
// Instantiate an Assembly class to the assembly housing the Integer type.  
SampleAssembly = Assembly::GetAssembly( Integer1.GetType() );
// Gets the location of the assembly using file: protocol.
Console::WriteLine( "CodeBase= {0}", SampleAssembly->CodeBase );

If you combind the above, you will probably come a bit closer to what you want to do. If this is going to be done in Native C++, you will have a bit more problem, there is something called "Fusion API" that might help you look for assemblies in the GAC.

囚你心 2024-10-19 23:27:51

要检索当前可执行文件的路径,请使用 GetModuleFileName 使用 NULL hModule 参数。

To retrieve the path of the current executable, use GetModuleFileName using a NULL hModule argument.

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