WSACleanUp causes an exception <p>My app can switch between Serial and Socket connections, but neither can be open at the same time. So when I try to switch between a Socket to Serial, I delete the Socket connection.</p> <p>The socket based object uses a private class called UsesWinsock (a big shout out to <a href="http://stackoverflow.com/users/7925/len-holgate">Len Holgate</a> here as it is basically his code (it is RAII actually but I never applied it to WSA until I saw him do it)). This simply calls WSAStart and and WSACleanUp.</p> <p>When WSACleanUp is called it tails off into the NTDLL and assembler. @err,hr gives me "The data area passed to a system call is too small" as the HRESULT.</p> <p>I've tried moving the code around: Moving the class in the order it is inherited causes the destruction sequence to change and actually broke the functions out so they were the last things to be called in the destruct sequence. Neither worked.</p> <p>I'm pretty sure I've freed everything that is allocated (there's only 1 socket and a couple of events) and I am stuck - this is a fairly important problem for me.</p> <p><a href="http://www.google.com/search?hl=en&amp;q=%22The+data+area+passed+to+a+system+call+is+too+small%22+WSACleanUp&amp;btnG=Search" rel="nofollow noreferrer">Google is unhelpful returning 4 results of which none solve my problem</a>.</p> <p>Any suggestions?</p>