I need to create a thread in a managed C++ code (CLR) to call an unmanaged C++ class member function passing a std::string
as a parameter. The thread is being called, but the received std::string
is being received as an empty string:
The managed code:
std::string param;
CreateThread(0, NULL, (LPTHREAD_START_ROUTINE) &MyThread.Start, &MyThread, (DWORD) ¶m, NULL);
The unmanaged code:
class MyThread
{
public:
MyThread();
static void Start(std::string ¶m);
};
void MyThread::Start(std::string ¶m)
{
std::cout << param << std::endl; <<=== param is empty here
}
Specifically in your case, you're passing &MyThread
as the thread function parameter and passing the param
as the dwCreationFlags
parameter of the CreateThread
function, which specifies thread creation options.
Additionally, you'll need to make sure you keep param
around for the lifetime of the thread.
Hope that helps.