Powered By Blogger
Saturday, October 25, 2008

Controlling a Stream Interface Driver

Special thanks to Bruce Eitman

/*
* Function to query the active drivre list using a search string
*/
VOID QueryDriver (const WCHAR* lpcParam)
{
DEVMGR_DEVICE_INFORMATION devmgrInfo;
devmgrInfo.dwSize=sizeof(DEVMGR_DEVICE_INFORMATION);
HANDLE hDevRes = FindFirstDevice (DeviceSearchByDeviceName, lpcParam,
&devmgrInfo);
if (INVALID_HANDLE_VALUE != hDevRes)
{
do
{
DBG_PRINT(_T("%d , %d , %s, %s, %s, %s\n"),
devmgrInfo.hDevice,
devmgrInfo.hParentDevice,
devmgrInfo.szLegacyName,
devmgrInfo.szDeviceKey,
devmgrInfo.szDeviceName,
devmgrInfo.szLegacyName );
}while (FindNextDevice(hDevRes,&devmgrInfo));
FindClose (hDevRes);
}
else
{
DWORD dwErrorCode = GetLastError();
DBG_PRINT(_T("QueryDriver , code: %d\n"),dwErrorCode);
}
return;
}


--------------------
/*
* Function to load a driver, when provided the driver registry key
*/
VOID LoadDriver (const WCHAR* lpcParam)
{
HANDLE hDriverShell = INVALID_HANDLE_VALUE;
hDriverShell = ActivateDeviceEx( lpcParam,NULL,0,NULL);

if (hDriverShell != INVALID_HANDLE_VALUE && hDriverShell != 0)
{
}
else
{
DWORD dwErrorCode = GetLastError();
DBG_PRINT(TEXT("LoadDriver: Failed to activate driver %d\n"), GetLastError() );
}
return;
}

--------------------
/*
* Function to unload a driver, when provided the diver name
*/
VOID UnloadDriver (const WCHAR* lpcParam)
{
DEVMGR_DEVICE_INFORMATION devmgrInfo;
devmgrInfo.dwSize=sizeof(DEVMGR_DEVICE_INFORMATION);
HANDLE hDevRes = FindFirstDevice (DeviceSearchByDeviceName, lpcParam,
&devmgrInfo);
if (INVALID_HANDLE_VALUE != hDevRes)
{
do
{
DeactivateDevice(devmgrInfo.hDevice);
}while (FindNextDevice(hDevRes,&devmgrInfo));
FindClose (hDevRes);
}
else
{
DWORD dwErrorCode = GetLastError();
DBG_PRINT(_T("QueryDriver , code: %d\n"),dwErrorCode);
}
return;
}

--------------------

Monday, October 13, 2008

Fixing Thread names in CeLog Output

When you are debugging on a standalone system (i.e. which is not connected to platform builder, using corecon), you may need to get the celog CLG file and review the performace data for the session in Kernel Tracker

But the file which you are getting will not have the thread information, it will only have the identifiers for each thread instead of the names. The names of the thread can be acquired using the Readlog utility. First copy the CLG file you obtained from the system into the build release directory and execute the following command :
Readlog -fixthreads celog.clg output.clg

Now output.clg file will have the thread names fixed up.

Fixing Thread Names With Readlog (http://msdn.microsoft.com/en-us/library/aa935935.aspx)