Re: How to add IOCTL_NDIS_REBIND_ADAPTER definition to my platform?

From: Sujith (sujithss_at_hotmail.com)
Date: 07/30/04


Date: Fri, 30 Jul 2004 14:33:30 +0530

hi,
have you implemented the 'IOCTL_NDIS_REBIND_ADAPTER' inside your
OEMIoControl function?
Regards
Sujith
"Selin Metin" <nospam@nospam.com.tr> wrote in message
news:%23A7thLhdEHA.3988@tk2msftngp13.phx.gbl...
> Hi everyone,
>
> I'm trying to change the IP of my device at runtime. I wrote an
application
> for this which gets the network parameters and sets the registry keys
> according to the user input. I checked my application both with the
emulator
> and the cepc. After I change the settings from DHCP assigned address to
the
> static IP address, I can see the newly assigned address in the Network and
> Dial-up Connections\<my_adapter_name> dialog box. However when I type
> ipconfig /all in the command prompt I get the old DHCP assigned network
> parameters.
>
> AFAIK, I have to unbind my adapter and rebind it again for the changes to
> take effect, but when I try to do this I get the following error:
>
> E:\WINCE420\PUBLIC\IcopDene\Commtrans\IPSetting.cpp(387) : error C2065:
> 'IOCTL_NDIS_REBIND_ADAPTER' : undeclared identifier
> Error PB2505: Error executing cl.exe.
>
> When I include the ntddndis.h file to my application I get other
definition
> errors for the following:
>
> C:\Program Files\Microsoft eMbedded C++
> 4.0\Common\EVC\MyProjects\CommTrans\IPSetting.cpp(388) : error C2065:
> 'CTL_CODE' : undeclared identifier
> C:\Program Files\Microsoft eMbedded C++
> 4.0\Common\EVC\MyProjects\CommTrans\IPSetting.cpp(388) : error C2065:
> 'FILE_DEVICE_PHYSICAL_NETCARD' : undeclared identifier
> C:\Program Files\Microsoft eMbedded C++
> 4.0\Common\EVC\MyProjects\CommTrans\IPSetting.cpp(388) : error C2065:
> 'METHOD_OUT_DIRECT' : undeclared identifier
> C:\Program Files\Microsoft eMbedded C++
> 4.0\Common\EVC\MyProjects\CommTrans\IPSetting.cpp(388) : error C2065:
> 'FILE_ANY_ACCESS' : undeclared identifier
> Error executing cl.exe.
>
> CommTrans.exe - 4 error(s), 0 warning(s)
>
> I tried to link the ndislib.lib module to my project but this didn't help.
> How can I correctly achieve this?
> This is my code:
>
>
////////////////////////////////////////////////////////////////////////////
> ////////////////////
> CString str;
> DWORD Addr;
> TCHAR szTemp[256];
> HKEY hKey;
> LONG hRes;
> DWORD Len;
> BYTE lpBuffer;
>
>
> _tcscpy (szTemp, TEXT("Comm\\"));
> _tcscat (szTemp, (LPWSTR)(LPCTSTR)m_szAdapterName);
> _tcscat (szTemp, TEXT("\\Parms\\TcpIp"));
> hKey = NULL;
> hRes = RegOpenKeyEx (HKEY_LOCAL_MACHINE, szTemp, 0, 0, &hKey);
> if (ERROR_SUCCESS == hRes && hKey != NULL)
> {
> lpBuffer = 0;
> RegSetValueEx (hKey, TEXT("EnableDHCP"), 0, REG_DWORD,
> &lpBuffer, sizeof(DWORD));
>
> GetDlgItem(IDC_IPADDRESS)->GetWindowText(str);
> Addr = StringToAddr((LPWSTR)(LPCTSTR)str);
> if (!IsValidIPAddress(Addr))
> return;
> IPAddrToStr (szTemp, Addr);
> Len = _tcslen(szTemp)+1;
> szTemp[Len++] = TEXT('\0');
> RegSetValueEx (hKey, TEXT("IpAddress"), 0, REG_MULTI_SZ,
> (BYTE *)szTemp, sizeof(TCHAR)*Len);
>
> GetDlgItem(IDC_SUBNETMASK)->GetWindowText(str);
> Addr = StringToAddr((LPWSTR)(LPCTSTR)str);
> if (!IsValidIPAddress(Addr))
> return;
> IPAddrToStr (szTemp, Addr);
> Len = _tcslen(szTemp)+1;
> szTemp[Len++] = TEXT('\0');
> RegSetValueEx (hKey, TEXT("Subnetmask"), 0, REG_MULTI_SZ,
> (BYTE *)szTemp, sizeof(TCHAR)*Len);
>
> GetDlgItem(IDC_DEFGATEWAY)->GetWindowText(str);
> if (!str.IsEmpty()) {
> Addr = StringToAddr((LPWSTR)(LPCTSTR)str);
> if (!IsValidIPAddress(Addr))
> return;
> }
> else
> Addr = 0;
> IPAddrToStr (szTemp, Addr);
> Len = _tcslen(szTemp)+1;
> szTemp[Len++] = TEXT('\0');
> RegSetValueEx (hKey, TEXT("DefaultGateway"), 0, REG_MULTI_SZ,
> (BYTE *)szTemp, sizeof(TCHAR)*Len);
>
> GetDlgItem(IDC_PRIMARYDNS)->GetWindowText(str);
> if (!str.IsEmpty()) {
> Addr = StringToAddr((LPWSTR)(LPCTSTR)str);
> if (!IsValidIPAddress(Addr))
> return;
> }
> else
> Addr = 0;
> IPAddrToStr (szTemp, Addr);
> Len = _tcslen(szTemp)+1;
> szTemp[Len++] = TEXT('\0');
> RegSetValueEx (hKey, TEXT("DNS"), 0, REG_MULTI_SZ,
> (BYTE *)szTemp, sizeof(TCHAR)*Len);
>
> GetDlgItem(IDC_PRIMARYWINS)->GetWindowText(str);
> if (!str.IsEmpty()) {
> Addr = StringToAddr((LPWSTR)(LPCTSTR)str);
> if (!IsValidIPAddress(Addr))
> return;
> }
> else
> Addr = 0;
> IPAddrToStr (szTemp, Addr);
> Len = _tcslen(szTemp)+1;
> szTemp[Len++] = TEXT('\0');
> RegSetValueEx (hKey, TEXT("WINS"), 0, REG_MULTI_SZ,
> (BYTE *)szTemp, sizeof(TCHAR)*Len);
>
> RegCloseKey (hKey);
> }
>
> // Open the NDIS driver.
> HANDLE hNdis = CreateFile(_T("NDS0:"), GENERIC_READ | GENERIC_WRITE,
> 0, NULL, OPEN_EXISTING, 0, NULL );
>
> // Send the device command.
> TCHAR errs[ 512 ];
> DWORD xcount;
> if (DeviceIoControl(hNdis, IOCTL_NDIS_REBIND_ADAPTER, m_szAdapterName,
> _tcslen(m_szAdapterName) + sizeof(TCHAR), // buf contains the name of
the
> adapter
> NULL, 0, &xcount, NULL ) )
> {
> OutputDebugString( _T( "Adapter rebound\r\n" ) );
> }
> else
> {
> _stprintf( errs, _T("DeviceIoControl failed. error = %d\r\n"),
> GetLastError());
> OutputDebugString(errs);
> }
>
> CloseHandle(hNdis);
>
////////////////////////////////////////////////////////////////////////////
> /////////////////////////////
>
>



Relevant Pages