From 27abce5a11d6c5bfe442ddfe3243ed9a44cf6246 Mon Sep 17 00:00:00 2001 From: Eelke Klein Date: Tue, 27 Dec 2016 10:27:44 +0100 Subject: [PATCH] Added WSAStartup/Cleanup to main. This is something libpq also does when opening and closing connections. This mechanism uses a use count and based on that count dll's are loaded and unloaded. By adding those calls to main we make sure the use count stays above zero for the whole duration of the program. --- main.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index a080bdd..0fdde4e 100644 --- a/main.cpp +++ b/main.cpp @@ -1,11 +1,31 @@ -#include "mainwindow.h" +#include "mainwindow.h" #include +#include + +// Need to link with Ws2_32.lib +#pragma comment(lib, "ws2_32.lib") int main(int argc, char *argv[]) { + + /* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */ + WORD wVersionRequested = MAKEWORD(2, 2); + WSADATA wsaData; + int err = WSAStartup(wVersionRequested, &wsaData); + if (err != 0) { + /* Tell the user that we could not find a usable */ + /* Winsock DLL. */ + printf("WSAStartup failed with error: %d\n", err); + return 1; + } + QApplication a(argc, argv); MainWindow w; w.show(); - return a.exec(); + int result = a.exec(); + + WSACleanup(); + + return result; }