SetNetDlg.cpp
上传用户:bjdfmy_886
上传日期:2007-09-01
资源大小:45k
文件大小:19k
源码类别:

网格计算

开发平台:

Visual C++

  1. // SetNetDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "SetNet.h"
  5. #include "SetNetDlg.h"
  6. #include ".setnetdlg.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #endif
  10. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  11. class CAboutDlg : public CDialog
  12. {
  13. public:
  14. CAboutDlg();
  15. // 对话框数据
  16. enum { IDD = IDD_ABOUTBOX };
  17. protected:
  18. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
  19. // 实现
  20. protected:
  21. DECLARE_MESSAGE_MAP()
  22. };
  23. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  24. {
  25. }
  26. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. }
  30. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  31. END_MESSAGE_MAP()
  32. // CSetNetDlg 对话框
  33. CSetNetDlg::CSetNetDlg(CWnd* pParent /*=NULL*/)
  34. : CDialog(CSetNetDlg::IDD, pParent)
  35. {
  36. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  37. }
  38. void CSetNetDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. }
  42. BEGIN_MESSAGE_MAP(CSetNetDlg, CDialog)
  43. ON_WM_SYSCOMMAND()
  44. ON_WM_PAINT()
  45. ON_WM_QUERYDRAGICON()
  46. //}}AFX_MSG_MAP
  47. ON_BN_CLICKED(IDOK, OnBnClickedOk)
  48. END_MESSAGE_MAP()
  49. // CSetNetDlg 消息处理程序
  50. BOOL CSetNetDlg::OnInitDialog()
  51. {
  52. CDialog::OnInitDialog();
  53. // 将“关于...”菜单项添加到系统菜单中。
  54. // IDM_ABOUTBOX 必须在系统命令范围内。
  55. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  56. ASSERT(IDM_ABOUTBOX < 0xF000);
  57. CMenu* pSysMenu = GetSystemMenu(FALSE);
  58. if (pSysMenu != NULL)
  59. {
  60. CString strAboutMenu;
  61. strAboutMenu.LoadString(IDS_ABOUTBOX);
  62. if (!strAboutMenu.IsEmpty())
  63. {
  64. pSysMenu->AppendMenu(MF_SEPARATOR);
  65. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  66. }
  67. }
  68. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  69. //  执行此操作
  70. SetIcon(m_hIcon, TRUE); // 设置大图标
  71. SetIcon(m_hIcon, FALSE); // 设置小图标
  72. // TODO: 在此添加额外的初始化代码
  73. /* CoInitialize(NULL);
  74. CLSID clsid;
  75. CLSIDFromProgID(OLESTR("NetCfg.NetConfig"),&clsid);
  76. CComPtr<INetConfig> pGetRes;//智能指针
  77. pGetRes.CoCreateInstance(clsid);*/
  78. //pGetRes->get
  79. //pGetRes->Hello();
  80. //pGetRes.Release();//小心哦!!请看最后的“注意”
  81. //CoUninitialize();
  82. return TRUE;  // 除非设置了控件的焦点,否则返回 TRUE
  83. }
  84. void CSetNetDlg::OnSysCommand(UINT nID, LPARAM lParam)
  85. {
  86. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  87. {
  88. CAboutDlg dlgAbout;
  89. dlgAbout.DoModal();
  90. }
  91. else
  92. {
  93. CDialog::OnSysCommand(nID, lParam);
  94. }
  95. }
  96. // 如果向对话框添加最小化按钮,则需要下面的代码
  97. //  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  98. //  这将由框架自动完成。
  99. void CSetNetDlg::OnPaint() 
  100. {
  101. if (IsIconic())
  102. {
  103. CPaintDC dc(this); // 用于绘制的设备上下文
  104. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  105. // 使图标在工作矩形中居中
  106. int cxIcon = GetSystemMetrics(SM_CXICON);
  107. int cyIcon = GetSystemMetrics(SM_CYICON);
  108. CRect rect;
  109. GetClientRect(&rect);
  110. int x = (rect.Width() - cxIcon + 1) / 2;
  111. int y = (rect.Height() - cyIcon + 1) / 2;
  112. // 绘制图标
  113. dc.DrawIcon(x, y, m_hIcon);
  114. }
  115. else
  116. {
  117. CDialog::OnPaint();
  118. }
  119. }
  120. //当用户拖动最小化窗口时系统调用此函数取得光标显示。
  121. HCURSOR CSetNetDlg::OnQueryDragIcon()
  122. {
  123. return static_cast<HCURSOR>(m_hIcon);
  124. }
  125. IWbemLocator* g_pLoc = NULL;
  126. IWbemServices* g_pSvc = NULL;
  127. IEnumWbemClassObject* g_pEnum = NULL;
  128. IWbemClassObject* g_pAdapterObject = NULL;
  129. IWbemClassObject* g_pAdapterConfigClass = NULL;
  130. VARIANT g_AdapterConfigPathVal;
  131. #define AE_SET (-1)
  132. #define AE_SUCCESS (0)
  133. USHORT ANWMIInit(PCWSTR pszAdapterName)
  134. {
  135.     HRESULT hres;
  136.     CComBSTR TheQuery = NULL;
  137.     ULONG NumObjects = 0;
  138.     // Step 1: Initialize COM.
  139.     hres =  CoInitializeEx(0, COINIT_MULTITHREADED); 
  140.     if (FAILED(hres))
  141.     {
  142.        OutputDebugString("CoInitializeEx failed!!n");
  143.        return AE_SET;                  
  144.     }
  145.     // Step 2: Set general COM security levels
  146.     // Note: If you are using Windows 2000, you need to specify -
  147.     // the default authentication credentials for a user by using
  148.     // a SOLE_AUTHENTICATION_LIST structure in the pAuthList ----
  149.     // parameter of CoInitializeSecurity ------------------------
  150.     hres =  CoInitializeSecurity(
  151.        NULL, 
  152.        -1,                          // COM negotiates service
  153.        NULL,                        // Authentication services
  154.        NULL,                        // Reserved
  155.        RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication 
  156.        RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation  
  157.        NULL,                        // Authentication info
  158.        EOAC_NONE,                   // Additional capabilities 
  159.        NULL                         // Reserved
  160.    );
  161.     if (FAILED(hres))
  162.     {
  163.        OutputDebugString("CoInitializeSecurity failed!!n");
  164.        return AE_SET;                     
  165.     }
  166.     // Step 3:  Obtain the initial locator to WMI
  167.     hres = CoCreateInstance(
  168.        CLSID_WbemLocator,             
  169.        0, 
  170.        CLSCTX_INPROC_SERVER, 
  171.        IID_IWbemLocator, 
  172.        (LPVOID*)&g_pLoc);
  173.     if (FAILED(hres))
  174.     {
  175.        OutputDebugString("CoCreateInstance failed!!n");
  176.        return AE_SET;                
  177.     }
  178.     // Step 4: Connect to the local rootcimv2 namespace and obtain pointer pSvc to make IWbemServices calls.
  179.     hres = g_pLoc->ConnectServer(
  180.        _bstr_t(L"ROOT\CIMV2"), 
  181.        NULL,
  182.        NULL, 
  183.        0, 
  184.        NULL, 
  185.        0, 
  186.        0, 
  187.        &g_pSvc);
  188.     if (FAILED(hres))
  189.     {
  190.        OutputDebugString("ConnectServer failed!!n");
  191.        return AE_SET;               
  192.     }
  193.     // Step 5:  Set security levels for the proxy
  194.     hres = CoSetProxyBlanket(
  195.        g_pSvc,                        // Indicates the proxy to set
  196.        RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx 
  197.        RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx 
  198.        NULL,                        // Server principal name 
  199.        RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx 
  200.        RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
  201.        NULL,                        // client identity
  202.        EOAC_NONE                    // proxy capabilities 
  203.        );
  204.     if (FAILED(hres))
  205.     {
  206.        OutputDebugString("CoSetProxyBlanket failed!!n");
  207.        return AE_SET;              
  208.     }  
  209. // 通过适配器名称来找到指定的适配器对象.
  210.     TheQuery = L"SELECT * FROM Win32_NetworkAdapterConfiguration WHERE SettingID = ""; 
  211.     TheQuery += pszAdapterName; 
  212.     TheQuery += L""";   
  213.     hres = g_pSvc->ExecQuery(
  214.        //SysAllocString(L"WQL"),
  215.        L"WQL",
  216.        TheQuery, 
  217.        WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY, 
  218.        NULL, 
  219.        &g_pEnum);
  220.     if (FAILED(hres))
  221.     {
  222.        OutputDebugString("ExecQuery failed!!n");
  223.        return AE_SET;              
  224.     }
  225.     // Get the adapter object.
  226.     hres = g_pEnum->Next(WBEM_INFINITE, 1, &g_pAdapterObject, &NumObjects);
  227.     if (SUCCEEDED(hres))
  228.     {
  229.        if (NumObjects < 0)
  230.        {
  231.            OutputDebugString("Can not get the specified adapter!!n");
  232.            return AE_SET;
  233.        }
  234.     }
  235. hres = g_pSvc->GetObject( 
  236.        L"Win32_NetworkAdapterConfiguration", 
  237.        0, 
  238.        NULL, 
  239.        &g_pAdapterConfigClass, 
  240.        NULL);
  241.     if (FAILED(hres))
  242.     {
  243.        OutputDebugString("GetObject failed!!n");
  244.        return AE_SET;               
  245.     }
  246.     hres = g_pAdapterObject->Get(
  247.        L"__RELPATH", 
  248.        0, 
  249.        &g_AdapterConfigPathVal, 
  250.        NULL, 
  251.        NULL);
  252.     if (FAILED(hres))
  253.     {
  254.        OutputDebugString("Get failed!!n");
  255.        return AE_SET;             
  256.     }
  257.     return AE_SUCCESS;
  258. }
  259. void ANWMIRelease()
  260. {
  261.     VariantClear(&g_AdapterConfigPathVal);
  262.     if (g_pAdapterConfigClass)
  263.     {
  264.        g_pAdapterConfigClass->Release();
  265.        g_pAdapterConfigClass = NULL;
  266.     }
  267.     if (g_pAdapterObject)
  268.     {
  269.        g_pAdapterObject->Release();
  270.        g_pAdapterObject = NULL;
  271.     }
  272.     if (g_pEnum)
  273.     {
  274.        g_pEnum->Release();
  275.        g_pEnum = NULL;
  276.     }
  277.     if (g_pSvc)
  278.     {
  279.        g_pSvc->Release();
  280.         g_pSvc = NULL;
  281.     }
  282.     if (g_pLoc)
  283.     {
  284.        g_pLoc->Release(); 
  285.        g_pLoc = NULL;
  286.     }    
  287.     CoUninitialize();
  288. }
  289. typedef struct tagMACDATA
  290. {
  291. DWORD ulStateMask;
  292. DWORD ulIP;
  293. DWORD ulMask;
  294. DWORD ulGateway;
  295. }MACDATA, *PMACDATA;
  296. USHORT ANEnableStaticInVista(PIP_ADAPTER_INDEX_MAP pimAdapter, PMACDATA pData)
  297. {
  298.     HRESULT hres;
  299.     USHORT usStatus = AE_SET;
  300.     //VARIANT AdapterConfigPathVal; 
  301.     //IWbemClassObject* pAdapterConfigClass = NULL;
  302.     IWbemClassObject* pInParamsDefinition = NULL;
  303.     IWbemClassObject* pInParams = NULL;
  304.     struct in_addr in;
  305.     SAFEARRAY* pIpAddress = NULL; 
  306.     SAFEARRAY* pSubnetMask = NULL; 
  307.     SAFEARRAY* pGatewayAddress = NULL;
  308.     SAFEARRAYBOUND bound[1]; 
  309.     long i = 0;
  310.     VARIANT ArrayVal;
  311.     IWbemClassObject* pOutParams = NULL;
  312.     VARIANT varReturnValue;
  313.     //WCHAR address[260];
  314.     CComBSTR IPAddress;
  315.     CComBSTR MASKAddress;
  316.     CComBSTR Gateway;
  317.     if (AE_SUCCESS != ANWMIInit(wcschr(pimAdapter->Name, L'{')))
  318.     {
  319.        goto END;
  320.     }
  321. //    if ((pData->ulStateMask & AS_IP_CHANGED) || (pData->ulStateMask & AS_MASK_CHANGED))
  322.     {
  323.        DWORD dwIP = pData->ulIP;//htonl();
  324.        DWORD dwMask = pData->ulMask;//htonl(pData->ulMask);
  325.        //Get the EnableStatic method and the in-params class.
  326.        hres = g_pAdapterConfigClass->GetMethod(
  327.            L"EnableStatic", 
  328.            0, 
  329.            &pInParamsDefinition, 
  330.            NULL);
  331.        if (FAILED(hres))
  332.        {
  333.            OutputDebugString("GetMethod failed!!n");
  334.            goto END;
  335.        }
  336.        //Get the in-params object.
  337.        hres = pInParamsDefinition->SpawnInstance(0, &pInParams);
  338.        if (FAILED(hres))
  339.        {
  340.            OutputDebugString("SpawnInstance failed!!n");
  341.            goto END;
  342.        }
  343.        //------------------Set the in-params values for ip address.创建一个设置IP的参数
  344.        bound[0].lLbound = 0; 
  345.        bound[0].cElements = 1; 
  346.        pIpAddress = SafeArrayCreate(VT_BSTR, 1, bound); 
  347.        if(pIpAddress == NULL) 
  348.        { 
  349.            OutputDebugString("SafeArrayCreate failed!!n");
  350.            goto END;
  351.        }
  352.        in.s_addr = dwIP;
  353.        //AnsiToUnicode(inet_ntoa(in),address);
  354.        IPAddress = inet_ntoa(in);
  355.        OutputDebugString("the ip address is:");
  356.        OutputDebugStringW(IPAddress);
  357.        hres = SafeArrayPutElement(pIpAddress, &i, (BSTR)IPAddress); 
  358.        if (FAILED(hres)) 
  359.        {
  360.            OutputDebugString("SafeArrayPutElement failed!!n");
  361.            goto END;
  362.        }
  363.    //---------------------------------------------------------------------------------
  364.        //Set the in-params values for subnet mask address. 创建一个设置子网掩码的参数
  365.        pSubnetMask = SafeArrayCreate(VT_BSTR, 1, bound); 
  366.        if(pSubnetMask == NULL) 
  367.        { 
  368.            OutputDebugString("SafeArrayCreate failed!!n");
  369.            goto END;
  370.        }
  371.        in.s_addr = dwMask;
  372.        //AnsiToUnicode(inet_ntoa(in),address);
  373.        MASKAddress = "255.255.255.0";//inet_ntoa(in);
  374.        OutputDebugString("the submask is:n");
  375.        OutputDebugStringW(MASKAddress);
  376.        hres = SafeArrayPutElement(pSubnetMask, &i, (BSTR)MASKAddress); 
  377.        if (FAILED(hres)) 
  378.        {
  379.            OutputDebugString("SafeArrayPutElement failed!!n");
  380.            goto END;
  381.        }
  382.    //---------------------------------------------------------------------------------
  383.        // bind the in-params.
  384.        ArrayVal.parray = pIpAddress; 
  385.        ArrayVal.vt = VT_ARRAY|VT_BSTR; 
  386.        hres = pInParams->Put(L"IPAddress", 0,&ArrayVal, 0);
  387.        ArrayVal.parray = pSubnetMask;
  388.        hres = pInParams->Put(L"SubnetMask", 0,   &ArrayVal, 0);
  389. // Now actually execute the "EnableStatic" method ----执行更改
  390.        hres = g_pSvc->ExecMethod(
  391.            g_AdapterConfigPathVal.bstrVal,
  392.            L"EnableStatic", 
  393.            0,
  394.            NULL, 
  395.            pInParams, 
  396.            &pOutParams, 
  397.            NULL);
  398.        if (FAILED(hres))
  399.        {
  400.            OutputDebugString("ExecMethod failed!!n");
  401.            goto END;
  402.        }
  403.        // Get the return value.
  404.        VariantInit(&varReturnValue);
  405.        hres = pOutParams->Get(_bstr_t(L"ReturnValue"), 0, &varReturnValue, NULL, 0);
  406.        if (FAILED(hres))
  407.        {
  408.            OutputDebugString("Get return value failed!!n");
  409.            goto END;
  410.        }
  411.        // Check the return value.
  412.        if (0 != varReturnValue.lVal)
  413.        {
  414.            char a[100];
  415.            sprintf(a,"%lx", varReturnValue.lVal);
  416.            OutputDebugString("set ip and mask address failed!!n");
  417.            OutputDebugString(a);
  418.            goto END;
  419.        }
  420. /*       VariantClear(&varReturnValue);
  421.        if (pOutParams)
  422.        {
  423.            pOutParams->Release();
  424.            pOutParams = NULL;
  425.        }
  426.        if(pIpAddress) 
  427.        {
  428.            SafeArrayDestroy(pIpAddress); 
  429.            pIpAddress = NULL;
  430.        }
  431.        if(pSubnetMask) 
  432.        {
  433.            SafeArrayDestroy(pSubnetMask);
  434.            pSubnetMask = NULL;
  435.        }
  436.        if (pInParams)
  437.        {
  438.            pInParams->Release();
  439.            pInParams = NULL;
  440.        }
  441.        if (pInParamsDefinition)
  442.        {
  443.            pInParamsDefinition->Release();
  444.            pInParamsDefinition = NULL;
  445.        }*/
  446.     }//ip and subnet mask address
  447. //    if (pData->ulStateMask & AS_GATEWAY_CHANGED)
  448.     {
  449. //       if ((pData->ulStateMask & AS_IP_CHANGED) || (pData->ulStateMask & AS_MASK_CHANGED))
  450.        {
  451.        //    Sleep(5000);
  452.        }
  453.        DWORD dwGateway = htonl(pData->ulGateway);
  454.        //Get the EnableStatic method and the in-params class.
  455.        hres = g_pAdapterConfigClass->GetMethod(
  456.            L"SetGateways", 
  457.            0, 
  458.            &pInParamsDefinition, 
  459.            NULL);
  460.        if (FAILED(hres))
  461.        {
  462.            OutputDebugString("GetMethod failed!!n");
  463.            goto END;
  464.        }
  465.        //Get the in-params object.
  466.        hres = pInParamsDefinition->SpawnInstance(0, &pInParams);
  467.        if (FAILED(hres))
  468.        {
  469.            OutputDebugString("SpawnInstance failed!!n");
  470.            goto END;
  471.        }
  472.        //Set the in-params values for Getewat.
  473.        bound[0].lLbound = 0; 
  474.        bound[0].cElements = 1; 
  475.        pGatewayAddress = SafeArrayCreate(VT_BSTR, 1, bound); 
  476.        if(pGatewayAddress == NULL) 
  477.        {
  478.            OutputDebugString("SafeArrayCreate failed!!n");
  479.            goto END;
  480.        }
  481.        in.s_addr = htonl(dwGateway);
  482.        //AnsiToUnicode(inet_ntoa(in),address);
  483.        Gateway = inet_ntoa(in);
  484.        OutputDebugString("the gateway address is:");
  485.        OutputDebugStringW(Gateway);
  486.        hres = SafeArrayPutElement(pGatewayAddress, &i, (BSTR)Gateway); 
  487.        if (FAILED(hres)) 
  488.        {
  489.            OutputDebugString("SafeArrayPutElement failed!!n");
  490.            goto END;
  491.        }
  492.        // bind the in-params.
  493.        ArrayVal.parray = pGatewayAddress; 
  494.        ArrayVal.vt = VT_ARRAY|VT_BSTR; 
  495.        hres = pInParams->Put(L"DefaultIPGateway", 0,&ArrayVal, 0);
  496.        // Now actually execute the "EnableStatic" method
  497.        hres = g_pSvc->ExecMethod(
  498.            g_AdapterConfigPathVal.bstrVal,
  499.            L"SetGateways", 
  500.            0,
  501.            NULL, 
  502.            pInParams, 
  503.            &pOutParams, 
  504.            NULL);
  505.        if (FAILED(hres))
  506.        {
  507.            OutputDebugString("ExecMethod failed!!n");
  508.            goto END;
  509.        }
  510. // Get the return value.
  511.        VariantInit(&varReturnValue);
  512.        hres = pOutParams->Get(_bstr_t(L"ReturnValue"), 0, &varReturnValue, NULL, 0);
  513.        if (FAILED(hres))
  514.        {
  515.            OutputDebugString("Get return value failed!!n");
  516.            goto END;
  517.        }
  518.        // Check the return value.
  519.        if (0 != varReturnValue.lVal)
  520.        {
  521.            char a[100];
  522.            sprintf(a,"%lx", varReturnValue.lVal);
  523.            OutputDebugString(a);
  524.            goto END;
  525.        }
  526.        VariantClear(&varReturnValue);
  527.        if (pOutParams)
  528.        {
  529.            pOutParams->Release();
  530.            pOutParams = NULL;
  531.        }   
  532.        if (pGatewayAddress)
  533.        {
  534.            SafeArrayDestroy(pGatewayAddress);
  535.            pGatewayAddress = NULL;
  536.        }
  537.        if (pInParams)
  538.        {
  539.            pInParams->Release();
  540.            pInParams = NULL;
  541.        }
  542.        if (pInParamsDefinition)
  543.        {
  544.            pInParamsDefinition->Release();
  545.            pInParamsDefinition = NULL;
  546.        }
  547.     }//Gateway
  548.     usStatus = AE_SUCCESS;
  549. END:
  550.     VariantClear(&varReturnValue);
  551.     if (pOutParams)
  552.     {
  553.        pOutParams->Release();
  554.        pOutParams = NULL;
  555.     }
  556.     if(pIpAddress) 
  557.     {
  558.        SafeArrayDestroy(pIpAddress); 
  559.        pIpAddress = NULL;
  560.     }
  561.     if(pSubnetMask) 
  562.     {
  563.        SafeArrayDestroy(pSubnetMask);
  564.        pSubnetMask = NULL;
  565.     }
  566.     if (pGatewayAddress)
  567.     {
  568.        SafeArrayDestroy(pGatewayAddress);
  569.        pGatewayAddress = NULL;
  570.     }
  571.     if (pInParams)
  572.     {
  573.        pInParams->Release();
  574.        pInParams = NULL;
  575.     }
  576.     if (pInParamsDefinition)
  577.     {
  578.        pInParamsDefinition->Release();
  579.        pInParamsDefinition = NULL;
  580.     }
  581.     ANWMIRelease();
  582.     return usStatus;
  583. }
  584. void CSetNetDlg::OnBnClickedOk()
  585. {
  586. // TODO: 在此添加控件通知处理程序代码
  587. //OnOK();
  588. PIP_ADAPTER_INFO pAdapterInfo = (PIP_ADAPTER_INFO)malloc(sizeof(IP_ADAPTER_INFO));
  589. ULONG ulLen = sizeof(IP_ADAPTER_INFO);
  590. memset(pAdapterInfo, 0, sizeof(IP_ADAPTER_INFO));
  591. DWORD dwError = GetAdaptersInfo( pAdapterInfo, &ulLen );
  592. if (dwError != 0)
  593. {
  594. free(pAdapterInfo);
  595. return;
  596. }
  597. PIP_ADAPTER_INFO pSrc = pAdapterInfo;
  598. //while(pAdapterInfo != NULL)
  599. {
  600. if (pAdapterInfo->Type == MIB_IF_TYPE_ETHERNET)
  601. {
  602. // if (pAdapterInfo->AddressLength < 6)
  603. // continue;
  604. ADAPTER_INFO *pAI = new ADAPTER_INFO;
  605. pAI->bWireless = FALSE;
  606. pAI->strDriverDesc = pAdapterInfo->Description;
  607. pAI->strName = pAdapterInfo->AdapterName;
  608. pAI->strNetMask = pAdapterInfo->IpAddressList.IpMask.String ;
  609. pAI->strNetGate = pAdapterInfo->GatewayList.IpAddress.String;
  610. pAI->strIP = pAdapterInfo->IpAddressList.IpAddress.String;
  611. pAI->bDHCP = (BOOL)pAdapterInfo->DhcpEnabled;
  612. if (pAI->bDHCP)
  613. pAI->strDhcpServer = pAdapterInfo->DhcpServer.IpAddress.String;
  614. //RegGetIP(pAI, pAI->strName.c_str(), 0);
  615. //GetLocalAdapterName(pAI, pAI->strName.c_str());
  616. //m_vecAdapters.push_back(pAI);
  617. }
  618. //pAdapterInfo = pAdapterInfo->Next;
  619. }
  620. IP_ADAPTER_INDEX_MAP strAdapter;
  621. MultiByteToWideChar (CP_ACP, 0, pAdapterInfo->AdapterName, -1, strAdapter.Name, 128);
  622. // wcscpy(strAdapter.Name, pAdapterInfo->AdapterName);
  623. strAdapter.Index = 0;
  624. MACDATA strData;
  625. strData.ulIP = inet_addr(pAdapterInfo->IpAddressList.IpAddress.String);
  626. strData.ulMask = atoi(pAdapterInfo->IpAddressList.IpMask.String);
  627. strData.ulGateway = inet_addr(pAdapterInfo->GatewayList.IpAddress.String);
  628. strData.ulStateMask = 0;
  629. ANEnableStaticInVista(&strAdapter, &strData);
  630. free(pSrc);
  631. }