kernel_memory_dump

Otkrivanje uredjaja na ruteru ba, !

Jan 20th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.73 KB | None | 0 0
  1. #include <windows.h>
  2. #include <upnp.h>
  3. #include <stdio.h>
  4.  
  5. #pragma comment(lib, "ole32.lib")
  6. #pragma comment(lib, "oleaut32.lib")
  7. #pragma comment(lib, "user32.lib")
  8.  
  9. class CUPnPDeviceFinderCallback : public IUPnPDeviceFinderCallback
  10. {
  11. public:
  12.     CUPnPDeviceFinderCallback()
  13.     {
  14.         m_lRefCount = 0;
  15.     };
  16.    
  17.     STDMETHODIMP QueryInterface(REFIID iid, LPVOID* ppvObject)
  18.     {
  19.         HRESULT hr = S_OK;
  20.        
  21.         if(NULL == ppvObject)
  22.         {
  23.             hr = E_POINTER;
  24.         }
  25.         else
  26.         {
  27.             *ppvObject = NULL;
  28.         }
  29.        
  30.         if(SUCCEEDED(hr))
  31.         {
  32.             if(IsEqualIID(iid, IID_IUnknown) || IsEqualIID(iid, IID_IUPnPDeviceFinderCallback))
  33.             {
  34.                 *ppvObject = static_cast<IUPnPDeviceFinderCallback*>(this);
  35.                 AddRef();
  36.             }
  37.             else
  38.             {
  39.                 hr = E_NOINTERFACE;
  40.             }
  41.         }
  42.        
  43.         return hr;
  44.     };
  45.    
  46.     STDMETHODIMP_(ULONG) AddRef()
  47.     {
  48.         return ::InterlockedIncrement(&m_lRefCount);
  49.     };
  50.    
  51.     STDMETHODIMP_(ULONG) Release()
  52.     {
  53.         LONG lRefCount = ::InterlockedDecrement(&m_lRefCount);
  54.         if(0 == lRefCount)
  55.         {
  56.             delete this;
  57.         }
  58.        
  59.         return lRefCount;
  60.     };
  61.    
  62.     STDMETHODIMP DeviceAdded(LONG lFindData, IUPnPDevice* pDevice)
  63.     {
  64.         HRESULT hr = S_OK;
  65.  
  66.         //You should save pDevice so that it is accessible outside the scope of this method.
  67.  
  68.         BSTR UniqueDeviceName;
  69.         hr = pDevice->get_UniqueDeviceName(&UniqueDeviceName);
  70.         if (SUCCEEDED(hr))
  71.         {
  72.             BSTR FriendlyName;
  73.             hr = pDevice->get_FriendlyName(&FriendlyName);
  74.             if (SUCCEEDED(hr))
  75.             {
  76.                 printf("Device Added: udn: %S, name: %S\n", FriendlyName, UniqueDeviceName);
  77.                 ::SysFreeString(FriendlyName);
  78.             }
  79.             ::SysFreeString(UniqueDeviceName);
  80.         }
  81.         return hr;
  82.        
  83.     };
  84.    
  85.     STDMETHODIMP DeviceRemoved(LONG lFindData, BSTR bstrUDN)
  86.     {
  87.         printf("Device Removed: udn: %S", bstrUDN);
  88.         return S_OK;
  89.     };
  90.    
  91.     STDMETHODIMP SearchComplete(LONG lFindData)
  92.     {
  93.         return S_OK;
  94.     };
  95.    
  96.    
  97.    
  98. private:
  99.     LONG m_lRefCount;
  100.    
  101. };
  102.  
  103. HRESULT FindUPnPDevice(BSTR TypeURI)
  104. {
  105.     HRESULT
  106.                 {
  107.                     // STA threads must pump messages
  108.                     MSG Message;
  109.                     BOOL bGetMessage; hr = S_OK;
  110.    
  111.     IUPnPDeviceFinderCallback* pUPnPDeviceFinderCallback = new CUPnPDeviceFinderCallback();
  112.     if(NULL != pUPnPDeviceFinderCallback)
  113.     {
  114.         pUPnPDeviceFinderCallback->AddRef();
  115.         IUPnPDeviceFinder* pUPnPDeviceFinder;
  116.         hr = CoCreateInstance(CLSID_UPnPDeviceFinder, NULL, CLSCTX_INPROC_SERVER,
  117.             IID_IUPnPDeviceFinder, reinterpret_cast<void**>(&pUPnPDeviceFinder));
  118.         if(SUCCEEDED(hr))
  119.         {
  120.             LONG lFindData;
  121.             hr = pUPnPDeviceFinder->CreateAsyncFind(TypeURI, 0, pUPnPDeviceFinderCallback, &lFindData);
  122.             if(SUCCEEDED(hr))
  123.             {
  124.                 hr = pUPnPDeviceFinder->StartAsyncFind(lFindData);
  125.                 if(SUCCEEDED(hr))
  126.                     while(bGetMessage = GetMessage(&Message, NULL, 0, 0) && -1 != bGetMessage)
  127.                     {
  128.                         DispatchMessage(&Message);      
  129.                     }
  130.                 }
  131.                 pUPnPDeviceFinder->CancelAsyncFind(lFindData);
  132.             }
  133.             pUPnPDeviceFinder->Release();
  134.         }
  135.         pUPnPDeviceFinderCallback->Release();
  136.     }
  137.     else
  138.     {
  139.         hr = E_OUTOFMEMORY;
  140.     }
  141.    
  142.     return hr;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment