![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: Helltown
Posts: 162
Rep Power: 4
![]() |
IUPnPNAT COM question
Ok I am trying to use the IUPnPNAT interface to add an entry to router's static port mapping. I instantiate the interface using CoCreateInstance and it returns no error. Then I try to get its port map collection using get_StaticPortMappingCollection and it returns no error but the returned interface's value is 0. Its meant to return a pointer to the interface like before. Is there anything i'm doing wrong?
Thanks in advance =) Code: #include <cstdio>
#include <windows.h>
#include "Natupnp.h."
inline void ReleaseObj(IUnknown* pInterface){
if(pInterface){
pInterface->Release();
}
}
void log(char*arg_0,...) {
char V8[1024];
sprintf(V8, "%s\n", arg_0);
va_list args;
va_start (args, arg_0);
vprintf (V8, args);
va_end (args);
}
int HandleCOMError(HRESULT hr) {
if(hr == S_OK){
//log ("Success");
return 0;
}
if (hr == REGDB_E_CLASSNOTREG){
log ("REGDB_E_CLASSNOTREG: A specified class is not registered in the registration database. Also can indicate that the type of server you requested in the CLSCTX enumeration is not registered or the values for the server types in the registry are corrupt.");
} else if (hr == CLASS_E_NOAGGREGATION){
log ("CLASS_E_NOAGGREGATION: This class cannot be created as part of an aggregate.");
} else if (hr == E_NOINTERFACE){
log ("E_NOINTERFACE: The specified class does not implement the requested interface, or the controlling IUnknown does not expose the requested interface.");
} else if (hr == E_ABORT){
log ("E_ABORT: The operation was aborted. ");
} else if (hr == E_FAIL){
log ("E_FAIL: An unspecified error occurred.");
} else if (hr == E_INVALIDARG){
log ("E_INVALIDARG: One of the parameters is invalid.");
} else if (hr == E_NOTIMPL){
log ("E_NOTIMPL: A specified method is not implemented.");
} else if (hr == E_OUTOFMEMORY){
log ("E_OUTOFMEMORY: The method was unable to allocate required memory. ");
} else if (hr == E_POINTER){
log ("E_POINTER: A pointer passed as a parameter is not valid.");
} else if (hr == E_UNEXPECTED){
log ("E_UNEXPECTED: The method failed for unknown reasons. ");
} else {
log ("Error of value 0x%x", hr);
}
return 1;
}
HRESULT hr;
IUPnPNAT * upnpnat;
IStaticPortMappingCollection * spmaps;
long int count = 0;
int main (int argc, char**args) {
// COM initializze
hr = CoInitialize(NULL);
upnpnat = NULL;
log ("creating UPnPNAT");
hr = CoCreateInstance(CLSID_UPnPNAT, NULL, CLSCTX_INPROC_SERVER, IID_IUPnPNAT, (void **) &upnpnat);
if (HandleCOMError(hr)) {
CoUninitialize();
return 0;
}
log("Getting static port mapping collection");
spmaps = 0;
hr = upnpnat->get_StaticPortMappingCollection(&spmaps);
if (HandleCOMError(hr)) {
ReleaseObj(upnpnat);
CoUninitialize();
return 0;
}
log("Getting static port mapping collection count");
hr = spmaps->get_Count(&count);
if (HandleCOMError(hr)) {
ReleaseObj(upnpnat);
CoUninitialize();
return 0;
}
log("%i static port maps found", count);
log ("releasing UPnPNAT");
//terminate the device finder
ReleaseObj(upnpnat);
upnpnat = NULL;
CoUninitialize();
return 0;
}im using windows xp sp2, using the vc++ 2005 ee compiler set up with platform sdk windows server 2003 sp1 version the above program outputs: creating UPnPNAT Getting static port mapping collection Getting static port mapping collection count
__________________
Spread your wings and fly! Chicken! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Virtual pet site MySQL question | proudnerd | PHP | 6 | May 13th, 2006 7:22 PM |
| Visual Basic 2005 Question | ReubenK | Visual Basic .NET | 3 | Apr 5th, 2006 3:23 PM |
| How to post a question | nnxion | C++ | 10 | Jun 3rd, 2005 11:53 AM |
| How to post a question | nnxion | C++ | 0 | Jun 3rd, 2005 8:55 AM |
| How to post a question | nnxion | C | 0 | Jun 3rd, 2005 8:55 AM |