← Back to team overview

linuxdcpp-team team mailing list archive

[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2594: call CoInitializeEx in the Win UPnP mapper thread

 

------------------------------------------------------------
revno: 2594
author: Big Muscle <http://strongdc.sourceforge.net>
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Sat 2011-08-20 16:16:46 +0200
message:
  call CoInitializeEx in the Win UPnP mapper thread
modified:
  win32/Mapper_WinUPnP.cpp


--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk

Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'win32/Mapper_WinUPnP.cpp'
--- win32/Mapper_WinUPnP.cpp	2011-03-19 15:32:48 +0000
+++ win32/Mapper_WinUPnP.cpp	2011-08-20 14:16:46 +0000
@@ -31,6 +31,10 @@
 #include <natupnp.h>
 	
 bool Mapper_WinUPnP::init() {
+	HRESULT hr = ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
+	if(FAILED(hr))
+		return false;
+
 	if(pUN)
 		return true;
 
@@ -42,13 +46,14 @@
 	OLECHAR iupnps[] = L"{B171C812-CC76-485A-94D8-B6B3A2794E99}";
 	CLSIDFromString(iupnps, &iupnp);
 	pUN = 0;
-	HRESULT hr = CoCreateInstance(upnp, 0, CLSCTX_INPROC_SERVER, iupnp, reinterpret_cast<LPVOID*>(&pUN));
+	hr = ::CoCreateInstance(upnp, 0, CLSCTX_INPROC_SERVER, iupnp, reinterpret_cast<LPVOID*>(&pUN));
 	if(FAILED(hr))
 		pUN = 0;
 	return pUN;
 }
 
 void Mapper_WinUPnP::uninit() {
+	::CoUninitialize();
 }
 
 bool Mapper_WinUPnP::add(const unsigned short port, const Protocol protocol, const string& description) {