在 C# 中创建一个 STL std::set 并封送至 c++

发布于 2024-12-28 20:10:53 字数 180 浏览 1 评论 0原文

实现这一目标的最佳方法是什么?我有一个文件名列表,是在 C# Windows 服务中生成的。我最终需要将它们放入 STL 集中,并将其推送到文件映射。我假设实际上在 C# 中创建这个结构要么是被禁止的,要么就是太困难而不值得,但是我可以使用一个本机 dll 返回一个指向它创建的集合的指针,然后在文件映射中传递该指针吗?这里的任何想法都会有帮助!

What would be the best way to achieve this? I've got a list of filenames, generated in a C# windows service. I need to ultimately get them into an STL set, and push that to a filemapping. I assume actually creating this structure in C# is either prohibited, or just too difficult to be worthwhile, but could I use a native dll that returns a pointer to the set it created, that I then pass along in the filemapping? Any thoughts here would be helpful!

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

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

发布评论

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

评论(1

雪若未夕 2025-01-04 20:10:53

在 C# 中创建 std::set 并不实际。然而,可以通过 PInvoke 将名称集合传递到 C 中,并将它们放入其中的 std::set 中。

extern "C" {

  void PassNames(const wchar** ppNames, int nameCount) {
    std:set<std::string> nameSet;
    for (int i = 0; i < nameCount; i++) {
      nameSet.insert(ppNames[i]);
    }

    PassOfTheSet(nameSet);
  }
}

然后,您可以使用 PInvoke 从 C# 调用此函数,从而将数据传递到本机

[DllImport("TheDllName.dll")
public static extern void PassNames(string[] names, int nameCount);

Creating a std::set in C# is not really practical. However it is possible to communicate the collection of names into C via PInvoke and put them into an std::set there.

extern "C" {

  void PassNames(const wchar** ppNames, int nameCount) {
    std:set<std::string> nameSet;
    for (int i = 0; i < nameCount; i++) {
      nameSet.insert(ppNames[i]);
    }

    PassOfTheSet(nameSet);
  }
}

Then you could call this function from C# using PInvoke and hence pass of the data to native

[DllImport("TheDllName.dll")
public static extern void PassNames(string[] names, int nameCount);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文