2

I have native dll project which I use from C# via CLI wrapper. In Initialize method of dll i'm calling

WSAStartup(MAKEWORD(2, 2), &data);

This works fine. Now I"ve decided to move entire dll to boost::asio (because I will port it to Linux and I want to enable /Za compiler option).

The question is - where and how should I replace WSAStartup call?

  • move it to CLI wrapper or to the top-level C# project?
  • replace it with some boost::asio call (which method to call?)
MD XF
  • 7,860
  • 7
  • 40
  • 71
Oleg Vazhnev
  • 23,239
  • 54
  • 171
  • 305

1 Answers1

2

Boost.Asio initialises Winsock before main() - it uses a static object for this purpose. Here is an excerpt from winsock_init.hpp:

// Static variable to ensure that winsock is initialised before main, and
// therefore before any other threads can get started.
static const winsock_init<>& winsock_init_instance = winsock_init<>(false);

So, in your case Winsock will get initialised on dll load.

(That's said, I'm afraid you can't compile Asio under Windows with /Za, but you also don't have to do this in order to make your code portable to Linux.)

Igor R.
  • 14,716
  • 2
  • 49
  • 83