mercredi 2 novembre 2016

CreateThread passing std::string as argument

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) &param, NULL);

The unmanaged code:

class MyThread
{
    public:
        MyThread();
        static void Start(std::string &param);
};

void MyThread::Start(std::string &param)
{
    std::cout << param << std::endl; <<=== param is empty here
}

Aucun commentaire:

Enregistrer un commentaire