Iam trying to use the C++ IUPnPNAT interface to achieve automatic port forwarding in a P2P application under windows, and I can't make it work just because it returns allways a NULL object. I was not sure that my router was UPnP capable, because it doesn't show any option in the web interface, but if I install eMule or Skype, they open the ports inmediately and work fine, so the problem must be in my code or in the Microsoft interface. How eMule and Skype do it? Anobody can help me?
If the CoCreateInstance is returning null, then it indicates that the class in question isn't registered on the relevant machine with OLE/COM - the fact that Skype/eMule work is irrelevant, as they probably use a library that is built into the application, and not a COM object.
if you want to have the application work on multiple systems, then you should consider linking directly to the .lib, and not using COM to connect to an object that may or may not be registered on the system at the time that it is being used.
I have experienced the same issue while being connected to a Guest or Public network and doing some debug I have found out that upnpnat.dll was not loading at all at runtime when get_StaticPortMappingCollection(..) was called. This can happen due to security restrictions if you are not connected to a Private network. Can check this in Control Panel -> Network and Sharing Center -> Change advanced sharing settings.
I also had problems when tried to open ports the traditional way.
Bcs of this i have cron runing on every 15 minutes to open or keep open the needed ports.
I doing this on linux, but im sure you are able to do cron jobs on windows too.
Im using this python code to add upnp forwards
From what I understand, Transmission bittorrent client uses the miniupnp library to do it's UPnP port forwarding of routers, however on Ubuntu upnpc (a test client of the miniupnp library) doesn't find any IDG routers, while on another Windows machine on the same networks it works correctly (with the windows binary of upnpc).
3a8082e126