Page 1 of 1

[win xp] UPnP

Posted: Thu Nov 30, 2006 7:03 am
by lexvictory
i know some of you like to disable UPnP on windows xp, but i use it, so i have implemented the interfaces to control a router using UPnP (xp only)

u can download the include file and and example file Here
the example code only finds router(s) and then displays all of the mapped ports on it, but the other bits shouldnt be hard to work out.
example code is also very messy.... but thats because i translated it from c++...

this is first time ive had to define interfaces and then get them working....
the code works in both unicode and ascii modes :D

Posted: Thu Nov 30, 2006 7:33 am
by DarkDragon
Link doesn't work.

Posted: Thu Nov 30, 2006 7:38 am
by lexvictory
grr, it did that to me the first time i tested it, then it worked....

gimme a sec and i'll put it on a different host

Posted: Thu Nov 30, 2006 7:40 am
by lexvictory
ok, link updated in first post

it was coz the first host i had it on is a sometimes stupid free host....

Posted: Thu Nov 30, 2006 10:46 am
by Dreglor
yes this code is very ugly, and seams very unsafe
Line 40: - Invalid memory access.

Code: Select all

If piPortMappingCollection\get__NewEnum(@piUnk) = #S_OK
it dies as the result of Line 36

Code: Select all

nat\get_StaticPortMappingCollection(@piPortMappingCollection.IStaticPortMappingCollection)
the function did not create the piPortMappingCollection Interface and left as null
it also does not return anything so testing it for #S_OK does nothing
but it does post an error into system which reads
The requested lookup key was not found in any active activation context.
I'm not sure what it means...

Posted: Thu Nov 30, 2006 10:53 am
by lexvictory
Dreglor wrote: I'm not sure what it means...
neither am i

and i do know its very very messy and not completely safe....
but it is only my first attempt at OOP stuff....


the code works everytime for me, apart from when my router doesnt respond (a reboot of the router fixed that), but ive never gotten that error....

Posted: Thu Nov 30, 2006 11:06 am
by lexvictory
ok, made the code a bit safer, but its just as messy....
(it is only an example)

i reuploaded it as well of course

edit: fixed a little error (after it was uploaded :x )

Posted: Wed Mar 04, 2009 8:29 am
by superadnim
I'm interested in using the upnp interface to open a port for a chat service I'm working on. Currently it fails to run on most routed connections due to the lack of port forwarding; however on most cases upnp is enabled and I'd like to use it.

Posted: Thu Mar 05, 2009 12:52 am
by lexvictory
In my experience, using the XP (and vista?) interfaces to control UPnP is a bad idea.
I've had numerous failures - even having to restart the computer (or the router) for it to start working again.

I started working on a native UPnp interface here
Which does only slightly less than this code does. (the other doesn't list mapped ports)

Both codes will probably require a lot of work to convert to PB 4.30