CACETrbNetConnectionImpl* CACETrbNetAcceptorImpl::make_handler() { INetAcceptor* acceptor = getAcceptor(); if (!acceptor) { return NULL; } CACETrbNetConnectionImpl* connImpl = new CACETrbNetConnectionImpl(); INetConnection* conn = NULL; if (!acceptor->onMakeHandler(connImpl, conn)) { return NULL; } conn->setClient(false); connImpl->setNetConnection(conn); return connImpl; }
HRESULT WINAPI CNetConnectionPropertyUi::Connect( HWND hwndParent, DWORD dwFlags) { if (!pCon) return E_POINTER; //FIXME if (dwFlags & NCUC_NO_UI) return pCon->Connect(); return E_FAIL; }
HRESULT WINAPI CNetConnectionPropertyUi::SetConnection(INetConnection* pCon) { if (this->pCon) this->pCon->Release(); if (!pCon) return E_POINTER; this->pCon = pCon; pCon->AddRef(); return S_OK; }
HRESULT WINAPI CNetConnectionPropertyUi::AddPages( HWND hwndParent, LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam) { HPROPSHEETPAGE hProp; BOOL ret; HRESULT hr = E_FAIL; INITCOMMONCONTROLSEX initEx; initEx.dwSize = sizeof(initEx); initEx.dwICC = ICC_LISTVIEW_CLASSES; if(!InitCommonControlsEx(&initEx)) return E_FAIL; hr = pCon->GetProperties(&pProperties); if (FAILED(hr)) return hr; hProp = InitializePropertySheetPage(MAKEINTRESOURCEW(IDD_NETPROPERTIES), LANPropertiesUIDlg, (LPARAM)this, pProperties->pszwName); if (hProp) { ret = (*pfnAddPage)(hProp, lParam); if (ret) { hr = NOERROR; } else { DestroyPropertySheetPage(hProp); } } return hr; }
HRESULT CLanStatus::InitializeNetTaskbarNotifications() { NOTIFYICONDATAW nid; HWND hwndDlg; INetConnectionManager *pNetConMan; IEnumNetConnection *pEnumCon; INetConnection *pNetCon; NETCON_PROPERTIES* pProps; HRESULT hr; ULONG Count; ULONG Index; NOTIFICATION_ITEM * pItem, *pLast = NULL; LANSTATUSUI_CONTEXT * pContext; TRACE("InitializeNetTaskbarNotifications\n"); if (m_pHead) { pItem = m_pHead; while (pItem) { hr = pItem->pNet->GetProperties(&pProps); if (SUCCEEDED(hr)) { ZeroMemory(&nid, sizeof(nid)); nid.cbSize = sizeof(nid); nid.uID = pItem->uID; nid.hWnd = pItem->hwndDlg; nid.uFlags = NIF_STATE; if (pProps->dwCharacter & NCCF_SHOW_ICON) nid.dwState = 0; else nid.dwState = NIS_HIDDEN; nid.dwStateMask = NIS_HIDDEN; Shell_NotifyIconW(NIM_MODIFY, &nid); NcFreeNetconProperties(pProps); } pItem = pItem->pNext; } return S_OK; } /* get an instance to of IConnectionManager */ //hr = CoCreateInstance(&CLSID_ConnectionManager, NULL, CLSCTX_INPROC_SERVER, &IID_INetConnectionManager, (LPVOID*)&pNetConMan); hr = INetConnectionManager_Constructor(NULL, IID_INetConnectionManager, (LPVOID*)&pNetConMan); if (FAILED(hr)) { ERR("INetConnectionManager_Constructor failed\n"); return hr; } hr = pNetConMan->EnumConnections(NCME_DEFAULT, &pEnumCon); if (FAILED(hr)) { ERR("EnumConnections failed\n"); pNetConMan->Release(); return hr; } Index = 1; do { hr = pEnumCon->Next(1, &pNetCon, &Count); if (hr == S_OK) { TRACE("new connection\n"); pItem = static_cast<NOTIFICATION_ITEM*>(CoTaskMemAlloc(sizeof(NOTIFICATION_ITEM))); if (!pItem) break; pContext = static_cast<LANSTATUSUI_CONTEXT*>(CoTaskMemAlloc(sizeof(LANSTATUSUI_CONTEXT))); if (!pContext) { CoTaskMemFree(pItem); break; } ZeroMemory(pContext, sizeof(LANSTATUSUI_CONTEXT)); pContext->uID = Index; pContext->pNet = pNetCon; pItem->uID = Index; pItem->pNext = NULL; pItem->pNet = pNetCon; hwndDlg = CreateDialogParamW(netshell_hInstance, MAKEINTRESOURCEW(IDD_STATUS), NULL, LANStatusDlg, (LPARAM)pContext); if (hwndDlg) { ZeroMemory(&nid, sizeof(nid)); nid.cbSize = sizeof(nid); nid.uID = Index++; nid.uFlags = NIF_MESSAGE; nid.uVersion = 3; nid.uCallbackMessage = WM_SHOWSTATUSDLG; nid.hWnd = hwndDlg; hr = pNetCon->GetProperties(&pProps); if (SUCCEEDED(hr)) { CopyMemory(&pItem->guidItem, &pProps->guidId, sizeof(GUID)); if (!(pProps->dwCharacter & NCCF_SHOW_ICON)) { nid.dwState = NIS_HIDDEN; nid.dwStateMask = NIS_HIDDEN; nid.uFlags |= NIF_STATE; } if (pProps->Status == NCS_MEDIA_DISCONNECTED || pProps->Status == NCS_DISCONNECTED || pProps->Status == NCS_HARDWARE_DISABLED) nid.hIcon = LoadIcon(netshell_hInstance, MAKEINTRESOURCE(IDI_NET_OFF)); else if (pProps->Status == NCS_CONNECTED) nid.hIcon = LoadIcon(netshell_hInstance, MAKEINTRESOURCE(IDI_NET_IDLE)); if (nid.hIcon) nid.uFlags |= NIF_ICON; wcscpy(nid.szTip, pProps->pszwName); nid.uFlags |= NIF_TIP; } pContext->hwndStatusDlg = hwndDlg; pItem->hwndDlg = hwndDlg; if (Shell_NotifyIconW(NIM_ADD, &nid)) { if (pLast) pLast->pNext = pItem; else m_pHead = pItem; pLast = pItem; Index++; } else { ERR("Shell_NotifyIconW failed\n"); CoTaskMemFree(pItem); } if (nid.uFlags & NIF_ICON) DestroyIcon(nid.hIcon); } else ERR("CreateDialogParamW failed\n"); } } while (hr == S_OK); m_lpNetMan = pNetConMan; pEnumCon->Release(); return S_OK; }
HRESULT DoTheWork (INetSharingManager * pNSM) { // add a port mapping to every firewalled or shared connection INetSharingEveryConnectionCollection * pNSECC = NULL; HRESULT hr = pNSM->get_EnumEveryConnection (&pNSECC); int LastErrorCode = 0; if (!pNSECC) return ICS_Error_FailGetEvery; else { // enumerate connections IEnumVARIANT * pEV = NULL; IUnknown * pUnk = NULL; hr = pNSECC->get__NewEnum (&pUnk); if (pUnk) { hr = pUnk->QueryInterface (__uuidof(IEnumVARIANT), (void**)&pEV); pUnk->Release(); }else{ return ICS_Error_FailGetNewEnum; } if (pEV) { VARIANT v; VariantInit (&v); while (S_OK == pEV->Next (1, &v, NULL)) { if (V_VT (&v) == VT_UNKNOWN) { INetConnection * pNC = NULL; V_UNKNOWN (&v)->QueryInterface (__uuidof(INetConnection), (void**)&pNC); if (pNC) { INetConnectionProps * pNCP = NULL; pNSM->get_NetConnectionProps (pNC, &pNCP); if (!pNCP) wprintf (L"failed to get NetConnectionProps!\r\n"); else { // check properties for firewalled or shared connection NETCON_MEDIATYPE MediaType; pNCP->get_MediaType(&MediaType); NETCON_STATUS Status; pNCP->get_Status(&Status); BSTR DevName; pNCP->get_DeviceName(&DevName); if (MediaType & (NCM_LAN | NCM_SHAREDACCESSHOST_LAN | NCM_PHONE) && Status == NCS_CONNECTED && QString(_com_util::ConvertBSTRToString(DevName)).indexOf("hosted network", 0, Qt::CaseInsensitive)==-1 && QString(_com_util::ConvertBSTRToString(DevName)).indexOf("virtual", 0, Qt::CaseInsensitive)==-1 && QString(_com_util::ConvertBSTRToString(DevName)).indexOf("teamviewer", 0, Qt::CaseInsensitive)==-1) { // got a shared/firewalled connection INetSharingConfiguration * pNSC = NULL; hr = pNSM->get_INetSharingConfigurationForINetConnection (pNC, &pNSC); if (!pNSC) wprintf (L"can't make INetSharingConfiguration object!\r\n"); else { hr = pNSC->EnableSharing(ICSSHARINGTYPE_PRIVATE); if(hr!=S_OK){ LastErrorCode = ICS_Error_EnableSharing; }else{ BSTR Name; pNCP->get_Name(&Name); QMessageBox msg; msg.setText(QString("Network: %1 %2 %3").arg(_com_util::ConvertBSTRToString(Name)).arg(_com_util::ConvertBSTRToString(DevName)).arg(Status)); msg.exec(); return 0; } pNSC->Release(); } } pNCP->Release(); } pNC->Release(); } } VariantClear (&v); } pEV->Release(); }else{ return ICS_Error_FailGetEnumVariant; } pNSECC->Release(); } if(LastErrorCode!=0) return LastErrorCode; return hr; }