12/29/2008

Unclassified Signature Program for WHQL signature

12.3.2.1 WHQL DTM Test Notes
As indicated in the WHQL documentation, before submitting the driver for testing you need to download Microsoft's Driver Test Manager (DTM) (http://www.microsoft.com/whdc/DevTools/WDK/DTM.mspx) and run the relevant tests for your hardware/software. After you have verified that you can successfully pass the DTM tests, create the required logs package and proceed according to Microsoft's documentation.
When running the DTM tests, note the following:
The DTM test class for WinDriver-based drivers should be Unclassified - Universal Device.
The Driver Verifier test is applied to all unsigned drivers found on the test machine. It is therefore important to try and minimize the number of unsigned drivers installed on the test PC (apart from the test driver - windrvr6.sys).
The USB Selective Suspend test requires that the depth of the under-test USB device in the USB devices tree is at least one external hub and no more than two external hubs deep.
The ACPI Stress test requires that the ACPI settings in the BIOS support the S3 power state.
Verify that the /PAE switch is added to the boot flags in the PC's boot.ini file.
The tests submission requires you to provide a *.pdb debug symbol file and an ouput of the PREfast utility (defects.xml). You can find copies of these files for the windrvr6.sys driver in the WinDriverredist directory. When selecting to rename and rebuild the windrvr6.sys driver module, as explained in section 12.2, a new debug symbols file is created for the driver. (The original defects.xml file is also applicable to the rebuilt driver).
Before submitting the file for certification you need to create a new catalog file, which lists your driver and specific INF file(s), and refer to this catalog file from your INF file(s), as explained above [12.3.2].

https://www.jungo.com/st/support/documentation/windriver/910/wdusb_man_mhtml/node71.html

FAQ for Windows Logo Program V. 3.0
https://www.microsoft.com/whdc/winlogo/VistaLogofaq.mspx


Unclassified Signature Program
https://www.microsoft.com/whdc/winlogo/drvsign/dqs.mspx

12/10/2008

DTM Audio Fidelity Test

Audio Fidelity Test:
http://msdn.microsoft.com/en-us/library/bb961150.aspx
http://www.microsoft.com/whdc/whql/audiofidelity.mspx

The training video on Fidelity Test:
http://download.microsoft.com/download/f/0/5/f05a42ce-575b-4c60-82d6-208d3754b2d6/DTM-AudioFidelityTestingLocal_Training.exe
http://download.microsoft.com/download/f/0/5/f05a42ce-575b-4c60-82d6-208d3754b2d6/DTM-AudioFidelityLogs_Training.exe

The equipment:
Windows Vista Logo Testing
http://ap.com/products/2700/vista_testing
The SYS-2722A-M
Microsoft Corporation has selected the Audio Precision SYS-2722A audio analyzer exclusively for its Windows Vista Logo Program Audio Fidelity tests.
To simplify ordering, Audio Precision has created a special product configuration of the SYS-2722A that includes all the filters and cables required by the Microsoft Driver Test Manager.

The details of test (Chinese):
http://ic.newmaker.com/art_28773.html

12/04/2008

Misc Information

1. Using Driver Verifier to identify issues with Windows drivers for advanced users
http://support.microsoft.com/kb/244617
To enable Driver Verifier by editing the registry, follow these steps: Start Registry Editor (Regedt32). Locate the following registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\VerifyDriversEdit the REG_SZ key.Set the REG_SZ key to the case-insensitive names of the drivers that you want to test.

2. Why CreateProcess failed in Unicode project with an access violation.
e.g:
CreateProcess( NULL, _T("test.exe"), NULL, ....) will fail with an unhandled exception in a UNICODE project.

MSDN:
The Unicode version of this function, CreateProcessW, can modify the contents of this string. Therefore, this parameter cannot be a pointer to read-only memory (such as a const variable or a literal string). If this parameter is a constant string, the function may cause an access violation.

3. Sometimes you may experience CreateFile failed with error code 5(Access is Denied) .
Security descriptors contain the security information associated with securable objects. For most securable objects, you can specify an object's security descriptor in the function call that creates the object.
Specifying a Security Descriptor From an INF File
http://msdn.microsoft.com/en-us/library/aa377450.aspx

For example, the following INF file snippet would create a registry key to which only administrators and the system have access. Note that this example requires administrative privileges.

 [DDInstall]
AddReg=mydevice.reg
 
[mydevice.reg]
include Registry information here
 
[mydevice.reg.Security]
"D:P(A;CI;GA;;;BA)(A;CI;GA;;;SY)"

SDDL for Device Objects
http://msdn.microsoft.com/en-us/library/ms794693.aspx

11/28/2008

How To Get PCMCIA Socket Information

The sample code performs the following steps:
Uses the IoGetDeviceObjectPointer function to obtain the device object and corresponding file object.
Initializes the PCMCIA_SOCKET_INFORMATION structure for the socket for which the information is sought.
Uses the IoBuildDeviceIoControlRequest function to allocate and set up an I/O request packet (IRP) for a device control request (the IOCTL_SOCKET_INFORMATION structure). This request should be sent at PASSIVE_LEVEL to the PCMCIA bus driver.
Passes the IRP down and waits for the result.

http://support.microsoft.com/kb/256161/en-us/

=============
This method is obsolete in Vista. Under Vista, PCMCIA device is no longer a named device object, (it's Securing Device Object now).


Maybe we can refer to “ntddpcm.h” under \winddk\version\inc\ddk, to turn on PCMCIA interface.

// Note: The IOCTL interface to pcmcia host controllers is turned off by
// default. These IOCTLs are provided for testing purposes only. To
// turn on this interface, add the following registry value:
// HKLM\SYSTEM\CurrentControlSet\Services\Pcmcia\Parameters\IoctlInterface : REG_DWORD : 1
//

#define IOCTL_PCMCIA_BASE FILE_DEVICE_CONTROLLER

#define DD_PCMCIA_DEVICE_NAME \\\\.\\Pcmcia

//
// IoControlCode values for this device.
//

#define IOCTL_GET_TUPLE_DATA CTL_CODE(IOCTL_PCMCIA_BASE, 3000, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_SOCKET_INFORMATION CTL_CODE(IOCTL_PCMCIA_BASE, 3004, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_PCMCIA_HIDE_DEVICE CTL_CODE(IOCTL_PCMCIA_BASE, 3010, METHOD_BUFFERED, FILE_WRITE_ACCESS)
#define IOCTL_PCMCIA_REVEAL_DEVICE CTL_CODE(IOCTL_PCMCIA_BASE, 3011, METHOD_BUFFERED, FILE_WRITE_ACCESS)

http://msdn.microsoft.com/en-us/library/ms789729.aspx
The PCMCIA IOCTL interface is enabled only if HKLM\SYSTEM\CurrentControlSet\Services\Pcmcia\Parameters\IoctlInterface (REG_DWORD) is set to 1. The IOCTL interface is turned off by default. This is valid for Windows XP, Windows Server 2003, Windows Vista, and Windows Server 2008.

11/06/2008

Banned API in Windows

http://download.microsoft.com/download/2/e/b/2ebac853-63b7-49b4-b66f-9fd85f37c0f5/banned.h
/***
* banned.h - list of Microsoft Security Development Lifecycle banned APIs
*
* Purpose:
* This include file contains a list of banned API which should not be used in new code and
* removed from legacy code over time
* History
* 01-Jan-2006 - mikehow - Initial Version
* 22-Apr-2008 - mikehow - Updated to SDL 4.1, commented out recommendations and added memcpy
*
***/
#ifndef _INC_BANNED
# define _INC_BANNED
#endif
#ifdef _MSC_VER
// Some of these functions are Windows specific
# pragma once
# pragma deprecated (strcpy, strcpyA, strcpyW, wcscpy, _tcscpy, _mbscpy, StrCpy, StrCpyA, StrCpyW, lstrcpy, lstrcpyA, lstrcpyW, _tccpy, _mbccpy)
# pragma deprecated (strcat, strcatA, strcatW, wcscat, _tcscat, _mbscat, StrCat, StrCatA, StrCatW, lstrcat, lstrcatA, lstrcatW, StrCatBuff, StrCatBuffA, StrCatBuffW, StrCatChainW, _tccat, _mbccat)
# pragma deprecated (wnsprintf, wnsprintfA, wnsprintfW, sprintfW, sprintfA, wsprintf, wsprintfW, wsprintfA, sprintf, swprintf, _stprintf, _snwprintf, _snprintf, _sntprintf)
# pragma deprecated (wvsprintf, wvsprintfA, wvsprintfW, vsprintf, _vstprintf, vswprintf)
# pragma deprecated (_vsnprintf, _vsnwprintf, _vsntprintf, wvnsprintf, wvnsprintfA, wvnsprintfW)
# pragma deprecated (strncpy, wcsncpy, _tcsncpy, _mbsncpy, _mbsnbcpy, StrCpyN, StrCpyNA, StrCpyNW, StrNCpy, strcpynA, StrNCpyA, StrNCpyW, lstrcpyn, lstrcpynA, lstrcpynW)
# pragma deprecated (strncat, wcsncat, _tcsncat, _mbsncat, _mbsnbcat, StrCatN, StrCatNA, StrCatNW, StrNCat, StrNCatA, StrNCatW, lstrncat, lstrcatnA, lstrcatnW, lstrcatn)
# pragma deprecated (strtok, _tcstok, wcstok, _mbstok)
# pragma deprecated (makepath, _tmakepath, _makepath, _wmakepath)
# pragma deprecated (_splitpath, _tsplitpath, _wsplitpath)
# pragma deprecated (scanf, wscanf, _tscanf, sscanf, swscanf, _stscanf, snscanf, snwscanf, _sntscanf)
//# pragma deprecated (_itoa, _itow, _i64toa, _i64tow, _ui64toa, _ui64tot, _ui64tow, _ultoa, _ultot, _ultow)
# pragma deprecated (gets, _getts, _gettws)
# pragma deprecated (IsBadWritePtr, IsBadHugeWritePtr, IsBadReadPtr, IsBadHugeReadPtr, IsBadCodePtr, IsBadStringPtr)
# pragma deprecated (CharToOem, CharToOemA, CharToOemW, OemToChar, OemToCharA, OemToCharW, CharToOemBuffA, CharToOemBuffW)
//# pragma deprecated (alloca, _alloca)
# pragma deprecated (strlen, wcslen, _mbslen, _mbstrlen, StrLen, lstrlen)
# pragma deprecated (memcpy, RtlCopyMemory, CopyMemory)
#else
#ifdef __GNUC__
// Some of these functions are Windows specific, so you may want to add *nix specific banned function calls
# pragma GCC poison strcpy strcpyA strcpyW wcscpy _tcscpy _mbscpy StrCpy StrCpyA StrCpyW lstrcpy lstrcpyA lstrcpyW _tccpy _mbccpy
# pragma GCC poison strcat strcatA strcatW wcscat _tcscat _mbscat StrCat StrCatA StrCatW lstrcat lstrcatA lstrcatW StrCatBuff StrCatBuffA StrCatBuffW StrCatChainW _tccat _mbccat
# pragma GCC poison wnsprintf wnsprintfA wnsprintfW sprintfW sprintfA wsprintf wsprintfW wsprintfA sprintf swprintf _stprintf _snwprintf _snprintf _sntprintf
# pragma GCC poison wvsprintf wvsprintfA wvsprintfW vsprintf _vstprintf vswprintf
# pragma GCC poison _vsnprintf _vsnwprintf _vsntprintf wvnsprintf wvnsprintfA wvnsprintfW
# pragma GCC poison strncpy wcsncpy _tcsncpy _mbsncpy _mbsnbcpy StrCpyN StrCpyNA StrCpyNW StrNCpy strcpynA StrNCpyA StrNCpyW lstrcpyn lstrcpynA lstrcpynW
# pragma GCC poison strncat wcsncat _tcsncat _mbsncat _mbsnbcat StrCatN StrCatNA StrCatNW StrNCat StrNCatA StrNCatW lstrncat lstrcatnA lstrcatnW lstrcatn
# pragma GCC poison strtok _tcstok wcstok _mbstok
# pragma GCC poison makepath _tmakepath _makepath _wmakepath
# pragma GCC poison _splitpath _tsplitpath _wsplitpath
# pragma GCC poison scanf wscanf _tscanf sscanf swscanf _stscanf snscanf snwscanf _sntscanf
//# pragma GCC poison _itoa _itow _i64toa _i64tow _ui64toa _ui64tot _ui64tow _ultoa _ultot _ultow
# pragma GCC poison gets _getts _gettws
# pragma GCC poison IsBadWritePtr IsBadHugeWritePtr IsBadReadPtr IsBadHugeReadPtr IsBadCodePtr IsBadStringPtr
# pragma GCC poison CharToOem CharToOemA CharToOemW OemToChar OemToCharA OemToCharW CharToOemBuffA CharToOemBuffW
//# pragma GCC poison alloca _alloca
# pragma GCC poison strlen wcslen _mbslen _mbstrlen StrLen lstrlen
# pragma GCC poison memcpy RtlCopyMemory CopyMemory
#endif
#endif /* _INC_BANNED */

10/19/2008

How to get you NIC MAC address

Here is a good reference, Thanks Khalid!
http://www.codeguru.com/Cpp/I-N/network/networkinformation/article.php/c5451/

Here is my code, just a little modification on Khaild's:



9/24/2008

How to "Refresh" Device Manager by programming

We are talking about: Device Manager->Action->Scan for hardware changes
The following CM APIs should work:



9/22/2008

Error LNK2019: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(wchar_t *)"

Error 2 error LNK2019: unresolved external symbol "char * __stdcall _com_util::ConvertBSTRToString(wchar_t *)" (?ConvertBSTRToString@_com_util@@YGPADPA_W@Z) referenced in function "public: char const * __thiscall _bstr_t::Data_t::GetString(void)const " (?GetString@Data_t@_bstr_t@@QBEPBDXZ) main.obj CPUTest

I met this error when programming a WMI C++ query application.

Research:
MSDN Says :When calling a function in a static library or DLL that takes a wchar_t type (note that BSTR and LPWSTR resolve to wchar_t*), you may get an LNK2001 unresolved external symbol error.This error is caused by the /Zc:wchar_t compiler option, which is set to on by default in new MFC projects. This option causes the compiler to treat wchar_t as a native type. Before Visual C++ .NET, wchar_t was treated as an unsigned short.If the main project and library do not use the same setting for /Zc:wchar_t, this will cause a mismatch of function signatures. To avoid this problem, rebuild the library with the /Zc:wchar_t compiler option, or turn it off in the main project using the Treat wchar_t as Built-in Type setting on the Language property page in the Property Pages dialog box.

Solution:
Add this:
#ifdef _DEBUG
# pragma comment(lib, "comsuppwd.lib")
#else
# pragma comment(lib, "comsuppw.lib")
#endif
# pragma comment(lib, "wbemuuid.lib")


Reference:
ConvertStringToBSTR
http://msdn.microsoft.com/en-us/library/t58y75c0.aspx

8/28/2008

PAE, 4GT and AWE

PAE: Physical Address Extension
4GT: 4-gigabyte tuning
AWE: Address Windowing Extensions
  • PAE allows the operating system to access and use more than 4 GB of physical memory. PAE also enables several advanced system and processor features, such as hardware-enabled Data Execution Prevention (DEP), Non-Uniform Memory Architecture (NUMA) and the ability to add memory to a system while it is running (hot-add memory), so it can also be used on computers that have less than 4 GB of memory. PAE is supported only on 32-bit versions of Windows; 64-bit versions of Windows do not support PAE.
  • 4GT extends the 32-bit user virtual address space from 2 GB to up to 3 GB.
  • AWE is a set of APIs that allows a process to allocate non-paged physical memory and then dynamically map portions of this memory into the virtual address space of the process.
  • When neither 4GT nor AWE are being used, the amount of physical memory that a single 32-bit process can use is limited by the size of its address space (2 GB). In this case, a PAE-enabled system can still make use of more than 4 GB of RAM to run multiple processes at the same time or to cache file data in memory.
  • 4GT can be used with or without PAE. However, some versions of Windows limit the maximum amount of physical memory that can be supported when 4GT is used. On such systems, booting with 4GT enabled causes the operating system to ignore any memory in excess of the limit. For details, see Memory Limits for Windows Releases.
  • AWE does not require PAE or 4GT but is often used together with PAE to allocate more than 4 GB of physical memory from a single 32-bit process.

8/27/2008

USB Device ENUMERATION PROCESS

( Copy From Microchip AN1003)


The following summarizes the steps involved in theenumeration of a USB device and explains how thedevice goes from Powered to Default, Address and theConfigured state during the enumeration process.

1. User plugs a USB device into a USB port. The hub provides power to the port and the device isin the Powered state.

2. The hub detects the device.

3. The hub uses an interrupt pipe to report the event to the host.

4. Host sends Get_Port_Status request to obtain more information about the device.

5. Hub detects whether device is Low-Speed orFull-Speed operation and sends the information to the host in response to Get_Port_Status.

6. Host sends a Set_Port_Feature request, asking the hub to reset the port.

7. Hub resets the device.

8. Host learns if a Full-Speed device supports High-Speed operation (using Chirp K signal).

9. Host verifies if the device has exited the Reset state using Get_Port_Status.

10. At this point, the device is in the Default state(device is ready to respond to control transfersover the default pipe at Endpoint 0, default address is 00h and the device can draw up to100 mA from the bus).

11. Host sends Get_Descriptor to learn the maximum packet size (Note: eighth byte of the device descriptor is bMaxPacketSize).

12. The host assigns an address by sending a Set_Address request. Device is now in the Address state.
13. Host sends Get_Descriptor to learn more about the device. The host responds by sending the descriptor followed by all other subordinate descriptors.

14. Host assigns and loads a device driver.

15. Host’s device driver selects a configuration bysending a Set_Configuration request. The device is now in the Configured state.

16. Host assigns drivers for interfaces in composite devices.

17. If the hub detects an overcurrent, or if the host requests the hub to remove power, the device will be unpowered by the USB bus. In this case, the device and host cannot communicate and the device is in the Attached state.

18. If the device does not see any activity on the busfor 3 ms, it goes into the Suspend state. The device consumes minimal bus power in thisstate.

8/26/2008

Composite USB device




A device that contains more than one interface descriptor is known as a composite USB device. Each interface in a composite USB device is numbered.









USB Device Stack for Windows XP and Later



The PCI bus driver enumerates the USB host controllers in the system and creates a PDO for each one. In Windows XP (SP1 and later) and Windows Server 2003, the operating system supports USB 2.0 and can enumerate both USB 2.0-compliant and USB 1.1-compliant hardware. If both sorts of controller are present on the same controller card in a version of Windows that supports USB 2.0, the PCI bus driver creates two separate PDOs, one for each controller. Only one PDO is shown in the figure. After creating a PDO for the host controller, the system loads the port driver, usbport.sys, and its accompanying miniports (not shown in the figure). The port driver then creates an FDO for the host controller.
The port driver enumerates the root hub. The usbhub.sys driver enumerates all other USB hubs. The figure only shows one level of hub device objects, but USB allows daisy-chaining of hub devices, so there could potentially be many more hub device objects in the tree. The hub driver detects and enumerates the USB composite keyboard device and creates a PDO for it.
In Windows XP and later versions of the operating system, the generic parent facility is implemented by a separate driver called the USB composite client generic parent driver. For a detailed discussion of this driver, see USB Common Class Generic Parent Driver. When the system detects a composite device, it loads the generic parent driver, which creates an FDO for the device as a whole. Afterwards, the generic parent driver creates separate PDOs for each interface of the composite device. In Windows 2000, these actions are performed by the hub driver. For more information, see USB Device Stack for Windows 2000.
In the example illustrated in the figure, the composite device consists of a HID-compliant keyboard interface and a HID-compliant power keys interface. The hub driver creates a separate PDO for each interface. After that, the HID class driver creates an FDO for each interface.

8/25/2008

PnP Device Installation

1. Plug the device into the computer.
2. The device is enumerated. the bus driver notifies the kernel-mode PnP manager that the list of devices on the bus has changed. The Kernel-mode PnP manager sends IRPs(IRP_MN_QUERY_ID, IRP_MN_QUERY_CAPABILITIES) to bus driver to gather information about the new device, such as HadwardID, CompatibleIDs and device capabilities.
3. The kernel_mode PnP manager notifies user-mode PnP manager that there is a device to be installed. The user-mode PnP manager tries to perform a server-side installation(quiet intallation)
4. The user-mode PnP manager creates a new process using rundll32.exe and launches newdev.dll to install the device.
5. newdev.dll calls SteupAPI(device installation functions) and CfgMgr API(PnP configuration manager functions) to carry out its installation tasks. If a device without "in box" drivers is plugged in before the operating system is installed, Device Manager will display the device as "unknown".
6. The class installer and co-installer, if any, can participate in the installation by handling DIF requests.
7. Setup transfers control to kernel mode to load drivers and start the device.
Once Setup has selected the best driver for the device, copied the appropriate driver files, registered any device-specific co-installers, and registered any device interfaces, it transfer control to kernel mode to load the drivers ans start the device.
8. The (Kernel mode?) PnP manager loads appropriate function driver and any optional filter drivers for the device. ...
a. The PnP manager calls DriverEntry routine for any required driver that is not yet loaded.
b. Then the PnP manager calls the AddDevice routine for earch driver, starting with lower-filter drivers, then the function driver, and, lastly, any upper filter driver.
c. The PnP manager assigns resources to the device, if required, and sends IRP_MN_START_DEVICE to the device's drivers.
9. Installer can change device settings or install application SW, in finish-install wizard pages( or finish-install actions in Vista above)

I suppose in step 7, Setup has done the select-copy-register driver thing, device manager could refresh automatically once. (deivice will display "Unknown" to a named device).
and then in step8, PnP manger to load driver in stack and start device, device manger could refresh automatically the 2nd time.

8/20/2008

Display JPG in ATL

• Tools: VC2005 (ATL8.0)

• 2 possible ways:
1. using the OleLoadPicture function and the IPicture interface
http://msdn.microsoft.com/en-us/magazine/cc301454.aspx
2. ATL CImage Class
http://msdn.microsoft.com/en-us/library/bwea7by5(VS.80).aspx
CImage calls GDIPlus in the end... Gdiplus.dll is included with Windows XP, which is also included in Win2000SP4.

• How to package the ActiveX ATL in a Web page
1. Use the depends.exe to check dependency
2. Pack VC2005 redistrubution package...
[C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x86\ vcredist_x86.exe]
3. ReferenceHow to package MFC controls in a Web page[KB167158]
http://support.microsoft.com/kb/167158/
http://topic.csdn.net/u/20071024/16/f820f776-ff31-4e25-954c-195f2c7e40b0.html

[msvcr80.dll]
FileVersion=8,00,50727,42
hook=mfc80installer

[mfc80installer]
file-win32-x86=http://192.168.1.117/helloactivex/mfc80.cab run=%EXTRACT_DIR%vcredist_x86.exe

opening...

I will move http://computer.mblogger.cn/firing here.