0

I have successfully implemented a network application in visual CLR project using boost.asio. but when i tried to use the same code in windows form project with Common "Language Runtime Support (/clr)" which is recommended by boost.asio its not working Error 15 error LNK2022: metadata operation failed (8013119F) : A TypeRef exists which should, but does not, have a corresponding TypeDef: (dummy): (0x01000019).

My question is how can i integrate my network codes done by using boost.asio in windows form project. What i am going to try now is to compile the all the boost.asio implementations as "No Common Language Runtime support" in a different project as dynamic library and link it with the windows form project.

Meanwhile if any of you'll guys have tried it already please help me to save some time.

Navin
  • 554
  • 2
  • 9
  • 31

2 Answers2

1

It seems that youre using boost::thread. According to this bug report , this question, and my personal experience, boost::thread wont work with C++/CLR projects when linked statically. You should put them in an unmanaged library and use that library instead, like you said yourself.

Community
  • 1
  • 1
Mohammad
  • 1,253
  • 1
  • 10
  • 26
  • Do you mean that i should compile the boost.asio codes as dll and use the dll in windows form project ? – Navin Jun 22 '12 at 06:17
  • 1
    The problem is not with boos::asio, but with boost::thread. One way is to link dynamically to boost::thread. The other solution is to use a native wrapper around the boost::thread related parts of your code. – Mohammad Jun 22 '12 at 06:26
  • Well now it is rebuilding properly but when i run it in VS the form is not showing up. i guess the main is not loading. I tried removing all libraries and then including some boost header one by one nad i found out when i include "" only it is happening. Unfortunately no errors or nothing. When i start the main function is not executing. Do you know why this is happening? – Navin Jun 22 '12 at 09:36
  • 1
    Usually including a header does not change runtime behavior, so I'm guessing that after inclusion of asio, you've enabled some code changes too. – Mohammad Jun 22 '12 at 11:45
  • Yes i was thinking the same, but a fresh windows form project with header compiles well, and even runs but the main method is not executing? Mohammad Have you linked a boost/asio and boost thread in the form project? If yes can you share your experience here that would help me to decide what is exactly i am missing here. More than programming a P2P application linking it to a form project is hard. – Navin Jun 25 '12 at 05:10
  • You can post your project and I will take a look at it. – Mohammad Jun 25 '12 at 06:33
  • boost::thread* threadLocalServer = new boost::thread(boost::bind(&Client::client_server_for_ping, &cl)); boost::thread* threadConnect = new boost::thread(boost::bind(&Client::start_TCP_Client, &cl)); boost::thread* threadClientConnect = new boost::thread(boost::bind(&Client::connect_to_client, &cl)); It's simple have these three threads inside a function. How can i call it in a windows form project. The other one is normal fresh windows form project in VS2008 where the main doesn't load when i add boost.asio. – Navin Jun 25 '12 at 07:28
  • The link for the frsh windows form project is below http://www.sendspace.com/file/6edmej – Navin Jun 25 '12 at 07:30
  • The boost/asio is included in interface.cpp – Navin Jun 25 '12 at 07:31
  • 1
    It was clear in the answer. you should dynamically link to boost. [here's how](http://stackoverflow.com/questions/2520234/how-to-link-to-dynamic-boost-libs). – Mohammad Jun 25 '12 at 09:34
0

@ Mohammad I guess i figured it out. I need to manually add form in a empty project and then include boost/asio in that. Loading boost/asio in a windows form project it self doesnt work might be because of the pre compiled headers. Now i have to figure out the boost thread issue. Like you said i'll try the methods you proposed and let you know.

Navin
  • 554
  • 2
  • 9
  • 31
  • 1
    It does work. I've tested it with your sample project. the only problem as I mentioned was with static linking. – Mohammad Jun 25 '12 at 11:31
  • It worked for you? but when i added "BOOST_ALL_DYN_LINK " in my preprocessor settings i got this error "the program can't start because boost_system-vc90-mt-gd-1_49.dll is missing from your computer" but it's actually there in the "C:\Boost\lib\i386" directory. – Navin Jun 25 '12 at 11:47
  • 1
    copy that file next to your exe file. – Mohammad Jun 25 '12 at 11:52
  • Thanks @Mohammad. That worked, so i am gonna mark your prev answer as correct answer... It was very kind enough for you to solve my silly mistakes. Thank again – Navin Jun 25 '12 at 12:55