gpt4 book ai didi

c++ - 如何制作托管 (clr) 多线程 C++ .dll?

转载 作者:太空狗 更新时间:2023-10-29 23:02:54 24 4
gpt4 key购买 nike

我正在尝试用 C++ 创建一个需要多线程支持的托管 .dll。我在 visual Studio 2013 中开发,使用平台工具集版本 v120。我需要它成为托管程序集的原因是因为需要将程序集集成到 LabView 中。

按照 Creating and Using a Managed Assembly in VC++ 2010 中的步骤操作给出了很好的结果。但我显然需要实现更复杂的东西,当我包含线程并编写以下代码时:

#pragma once
#include <thread>

using namespace System;
using namespace std;


namespace MultiThread_module {

public ref class multiThreadingTest
{
public:
String^ GetVersion();
int someNumber;

private:

thread testThread;
};
}

我收到以下错误:

"thread" is not supported when compiling with /clr or /clr:pure.

a member of a managed class cannot be of a non-managed class type

error directive: ERROR: Concurrency Runtime is not supported when compiling /clr.

error directive: is not supported when compiling with /clr or /clr:pure.

我的一个 friend 说,如果不使用像 boost 这样的外部包,就不可能在 Visual Studio 中编写多线程代码。这似乎不太可能,因为多线程已经在 C# 和 VB 中存在很长时间了!

所以,如果您能让我知道我做错了什么,我会很高兴或者如果用 C++ 开发托管多线程 .dll 真的很难?

最佳答案

您可以使用托管线程库:System.Threading.Thread .

#pragma once

using namespace System;
using namespace std;
using namespace System::Threading;


namespace MultiThread_module {

public ref class multiThreadingTest
{
public:
String^ GetVersion();
int someNumber;

private:

Thread^ testThread;
};
}

关于c++ - 如何制作托管 (clr) 多线程 C++ .dll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27137634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com