2

I have gave up on creating a GUI directly from the windows API so I'm going to use forms. I would like to multithread my app and wrap the GUI in a class and put it in a separate thread. When I click a button, etc, it would change a value in a struct that will be read from the main thread. My problem is, when I compile my application I get an error with the linker.

1>Core.obj : error LNK2022: metadata operation failed (8013119F) : A TypeRef exists which should, but does not, have a corresponding TypeDef: (dummy): (0x0100001f).

My code for main is as follows.

int main()
{
//create thread object pointer
    boost::thread *GUIThread;
//create pointer to GUIInterface, which contains a member function that
//contains the Application::Run
    GUIInterface *myinterface;
    myinterface = new GUIInterface;

    GUIThread = new boost::thread(boost::bind(&GUIInterface::MainFunction, myinterface));
    return 0;
}

It works fine when creating the class and calling the function in the main thread, but using boost causes problems. I built boost using the correct compiler MSVC-10.0 and the threading library has always worked in the past, but clr just causes problems. Any recommendations on how to fix this? OR if I should just use .net multithreading(if I do, I really need some links to how to use in with c++, most stuff I find is in C#). Thanks.

contrapsych
  • 1,919
  • 4
  • 29
  • 44
  • 1
    You are getting this error because boost::thread uses r-value references. Not supported by the managed linker. You are heading for a train wreck this way, a user interface is not something you can just bolt-on. You must create a single-threaded apartment, a UI is fundamentally thread-unsafe. Not sure how to keep you out of trouble. – Hans Passant Jan 10 '11 at 19:33
  • 1
    Is it possible to build boost without rvalues? – contrapsych Jan 10 '11 at 21:03

1 Answers1

2

There are two problems when using boost::thread in a managed application. The first is the linker error you encountered. The second is an initialization error at application startup if the boost::thread implementation is statically linked with your application.

Both problems are mentioned in an older bug report. I don't know if this has changed in later releases; 1.43 has the same problem. I assume not as the case was closed wontfix.

Chris Ostler
  • 677
  • 4
  • 9