Powered By Blogger
Tuesday, September 23, 2008

Querying that powerstate of an NIC

This one is a continuation of the last post, Here is a code for chcking the current power state of an NIC
// Returns TRUE if device is enabled otherwise FALSE
BOOL QueryNIC (wchar_t* InterfaceName)
{
TCHAR                           szName[MAX_PATH];
int                             nChars;
TCHAR*                          pszAdapter;
TCHAR                           multiSz[257];
DWORD                           cbBuffer = sizeof(multiSz);
CEDEVICE_POWER_STATE Dx = PwrDeviceUnspecified;    
BOOL bDevPowered = TRUE;

pszAdapter = new TCHAR[wcslen(InterfaceName)+1];
wcscpy_s(pszAdapter,wcslen(InterfaceName)+1,InterfaceName);
nChars = _sntprintf_s(szName,
                                                    MAX_PATH-1,
                                                   MAX_PATH-1,
                                                  _T("%s\\%s"),
                                                                  PMCLASS_NDIS_MINIPORT, 
                                                                   pszAdapter);
szName[MAX_PATH-1]=0;

if(nChars != (-1)) 
::GetDevicePower(szName, POWER_NAME, &Dx);

if (!IsValidDx(Dx))
{
bDevPowered = FALSE;
}
if (D4 == Dx)
{
bDevPowered = FALSE;
}
delete pszAdapter;
return bDevPowered ;
}

9 comments:

Unknown said...

We got the following error after building the code given by you.
C:\WINCE600\public\common\oak\drivers\ethdbg\ncmvnic\.\NICPowerCtrl.cpp(1) : fatal error C1083: Cannot open include file: 'Atlbase.h': No such file or directory.
Please do let us know a solution for this.

Vaisakh P S said...

Hi Keerthana,

I feel the problem would be in your Wince project config. Did you enable ATL and other libraries in your configuration?

Unknown said...

We are new to windows, may I know wat are the other libraries that are to be enabled

Unknown said...

We are using wince 6.0

Vaisakh P S said...

its been sometime since i worked on WinCE. But if i remember correctly, when we are building a windows CE images in project configuration (i.e. the catalog items), we need to enable ATL support in catalog and rebuild platform

After which building the code in public\common\oak\drivers\ethdbg\ncmvnic\.\NICPowerCtrl.cpp should go fine.


The thing is that, on enabling an entry for instance ATL library support, these source files are compiled in to the output OBJDIR and the header are exposed in output SDK directory.

Unknown said...

We have added the code given by you to our miniport driver. Now the build problem regarding header files are solved.But the adapter still remains enabled in our target. The file from where we call the contol fuction for our adapter is not included when we give clean sysgen or rebuild current bsp and subprojects, but it gives error in our call function and regarding headerfile when we build our miniport seperately. should'nt we build our miniport alone??? Do let us know a solution for disabling.

Vaisakh P S said...

Hi Keerthana, you ping me on my gmail id(vaisakhrulez), we can discuss about this in detail

Unknown said...

We are using streamdriver in Usb class driver. We want to know wher init function will be called and created

Unknown said...

How to create a thread in USB. Our requirement is that it should run before the USB device attach is invoked