2016-01-21 96 views

回答

0

此错误似乎发生在System.Win.Bluetooth中的TWinBluetoothSocket.Destroy例程期间。出于某种原因,尽管未使用蓝牙,但在C++应用程序中调用了TWinBluetoothSocket析构函数。

问题是WSACleanup()被TWinBluetoothSocket析构函数调用,但WSAStartup()从未被调用,所以WSACleanup()返回一个错误。

在Mongo驱动程序用于C++应用程序时,即使TFDConnection在Delphi单元中,只要在设计或运行时选择了Mongo驱动程序并将Connected设置为true,就会发生这种情况。

没有需要MongoDB服务器来重现此;只需在按钮点击处理程序中设置为“已连接”即可。当然,因为没有MongoDB服务器会发生错误,但是当应用程序退出时会发生此错误。

的解决方法是把这个在构造函数(从https://msdn.microsoft.com/en-us/library/windows/desktop/ms742213(v=vs.85).aspx)现在

WORD wVersionRequested; 
WSADATA wsaData; 
int err; 
/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ 
wVersionRequested = MAKEWORD(2, 2); 
err = WSAStartup(wVersionRequested, &wsaData); 
if (err != 0) 
    { 
    ShowMessage("err nonzero"); 
    } 

,调用WSAStartup()被调用,所以WSACleanup()不返回一个错误,并且应用程序可以关闭。