Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.7 KiB

  1. #include "pch.h"
  2. #pragma hdrstop
  3. #include <netcon.h>
  4. #include <netconp.h>
  5. #include <tchar.h>
  6. EXTERN_C
  7. VOID
  8. __cdecl
  9. wmain ()
  10. /*
  11. VOID
  12. wmainCRTStartup (
  13. VOID
  14. )
  15. */
  16. {
  17. HRESULT hr;
  18. INetConnectionManager * pconMan;
  19. hr = CoInitializeEx(NULL, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
  20. if (SUCCEEDED(hr))
  21. {
  22. hr = CoCreateInstance(CLSID_ConnectionManager, NULL,
  23. CLSCTX_SERVER | CLSCTX_NO_CODE_DOWNLOAD,
  24. IID_INetConnectionManager,
  25. (LPVOID *)&pconMan);
  26. if (SUCCEEDED(hr))
  27. {
  28. IEnumNetConnection* pEnum;
  29. hr = pconMan->EnumConnections(NCME_DEFAULT, &pEnum);
  30. if (SUCCEEDED(hr))
  31. {
  32. INetConnection* aNetCon [512];
  33. ULONG cNetCon;
  34. hr = pEnum->Next (celems(aNetCon), aNetCon, &cNetCon);
  35. _tprintf(L"Number of connections: %d\r\n", cNetCon);
  36. if (SUCCEEDED(hr))
  37. {
  38. for (ULONG i = 0; i < cNetCon; i++)
  39. {
  40. INetConnection* pNetCon = aNetCon[i];
  41. NETCON_PROPERTIES* pProps;
  42. hr = pNetCon->GetProperties (&pProps);
  43. if (SUCCEEDED(hr))
  44. {
  45. _tprintf(L"Connection name: %s Type: %d\r\n", pProps->pszwName, pProps->MediaType);
  46. if (pProps->MediaType == NCT_LAN && pProps->Status == NCS_MEDIA_DISCONNECTED)
  47. {
  48. _tprintf(L"Connection %s (%s) is currently Disconnected", pProps->pszwName, pProps->pszwDeviceName);
  49. }
  50. if (pProps->dwCharacter & NCCF_INCOMING_ONLY)
  51. {
  52. _tprintf(L"Inbound Connection\r\n");
  53. INetConnectionSysTray* pTray;
  54. hr = pNetCon->QueryInterface(IID_INetConnectionSysTray, reinterpret_cast<void **>(&pTray));
  55. _tprintf(L"QI returned: %x", hr);
  56. if (SUCCEEDED(hr))
  57. {
  58. pTray->IconStateChanged();
  59. }
  60. }
  61. CoTaskMemFree(pProps);
  62. }
  63. ReleaseObj (pNetCon);
  64. }
  65. }
  66. pEnum->Release();
  67. }
  68. pconMan->Release();
  69. }
  70. CoUninitialize();
  71. }
  72. }