Tuesday, July 17, 2007

Using Macros and Environment Variables

The Build utility uses numerous environment variables and macros:

  • Environment variables are set by the SetEnv.bat batch file when you open a Windows Driver Kit (WDK) build environment window.
  • Macros are specified in the sources files. These files must exist in each source code subdirectory.
The distinction between environment variables and macros is weak, because some environment variables can be referenced or changed within "sources" files, and some macros can be defined as environment variables in the build environment window. However, it is recommended that you not attempt to interchange environment variables and build macros in this manner.

Build Utility MacrosSources File 兩個分類下都有macro的list,不同的是Build Utility Macros分類下除了macro之外也可以用來做環境變數的設定

Build Utility Macros


Sources File

以下是一些巨集的介紹,完整的list要連到MSDN去參考

DEFFILE :
This macro definition specifies the name for the module-definition file (.def), known as an export file, for TARGETNAME.

DLLENTRY :
This macro definition specifies the function that is used as the entry point for a .dll file if the value of TARGETTYPE is set equal to DYNLINK. If no value is given for DLLENTRY, the default value is _DllMainCRTStartup

INCLUDES
:
This macro definition specifies additional paths used to find included .h files.
Use this macro only for your private .h file directories because the standard public .h file directories are automatically included. The default value is NULL.

__PROJROOT :
This macro defines the location of a project.

RELEASETYPE :
This macro definition sets two flags: RELEASEDIR and RELEASELIBDIR, which specify which output directory to place binaries and libraries in after they are built.

SOURCELIBS :
This macro definition specifies library (.lib) files to be linked with the module specified in TARGETNAME. The default value is NULL.

SOURCES :
This macro definition contains a list of files that are processed during the build process to become the contents of a library (.lib) file or dynamic-link library (.dll) file.
The list of files consists of assembly files and source files with extensions. These include the following file types: .cxx, .cpp, .c, .asm, .s, .src, .rc, .obj, .ire, .res, .h, .odl, .tlb, .i, .cs, and .resx.
Header files cannot be included in the SOURCES macro definition.

SYNCHRONIZE_DRAIN
:
This macro definition allows you to ensure that all preceding library files are built before building the current directory, which depends on the previous libraries.

TARGETLIBS :
This macro definition specifies additional library (.lib) files and object (.obj) files that should be linked into the target executable (.exe or .dll) file.

TARGETNAME :
This macro definition specifies the name of the .exe or .lib file being built, excluding the file name extension.
Build.exe creates a file named Proj2.extension, where extension can be .lib, .dll, or .exe.

TARGETPATH :
When RELEASETYPE equals CUSTOM, TARGETPATH specifies the object directory into which you are building the target device.

TARGETTYPE :
This macro definition specifies the type of file being built. (exe, lib or dll)
這裡有一篇說明提到TARGETTYPE不只這三種,有興趣可以看看 (不清楚在什麼情況下會用到) -> Utilizing a sources File template

WINCEOEM :
If a component needs to use header files and import libraries from the public projects that it depends on, set this macro definition to 1.
This setting means that the component cannot be used across releases of the system.
This macro definition should be set only by system-level components.

Thursday, July 12, 2007

Stream interface drivers

The most common driver model in Windows CE is the stream interface driver. This driver model has roots in the earliest implementations of Unix. A stream driver exports functions to open, close, read, write, seek, or control the underlying hardware.

The stream interface is appropriate for any I/O device that can be thought of logically as a data source or a data sink. That is, any peripheral that produces or consumes streams of data as its primary function is a good candidate to expose the stream interface. A good example is a serial port device. An example of a device that does not produce or consume data in the traditional sense would be a display device, and indeed, the stream interface is not exposed for controlling display hardware.

A stream interface driver receives commands from the Device Manager and from applications by means of file system calls. The driver encapsulates all of the information that is necessary to translate those commands into appropriate actions on the devices that it controls.

All stream interface drivers, whether they manage built-in devices or installable devices, or whether they are loaded at boot time or loaded dynamically, have similar interactions with other system components.

The following illustrations show the interactions between system components for a generic stream interface driver that manages a built-in device, and for a stream interface driver for a PC Card Client device. Figure below, shows the architecture for stream interface drivers for built-in devices that are loaded by the Device Manager at boot time.




Stream Interface Driver Entry Points
Here and elsewhere, XXX refers to a three character prefix you choose for your device driver. When implementing a stream interface driver replace XXX with a prefix appropriate for your specific implementation.

You can implement a driver with only Init and Deinit entry points and no device prefix. You cannot access this driver using CreateFile.

If DEVFLAGS_NAKEDENTRIES is specified in the driver's Flags registry subkey, the entry point names can be undecorated; for example, Open, Close, and so on. The sample battery driver, which is in %_WINCEROOT%\Public\Common\OAK\Drivers\Battdrvr, is an example of a driver that uses undecorated entry points. The battery driver's registry settings still must include a prefix.

Your implementations of these entry points must be declared for export from your DLL by placing __declspec(dllexport) in front of your function declaration. If you are developing in C++, your entry points must also be declared extern "C" as well.



Single Access and Multiple Access
A stream interface driver can implement either single access or multiple access by using the hOpenContext parameter passed to all file I/O functions.

To enable multiple access, each call to the XXX_Open function should return a different value for hOpenContext. The device driver must track which return values from XXX_Open are in use.

To enforce single access, only the first call to XXX_Open should return a valid hOpenContext value. As long as this value remains valid, which is until XXX_Close is called for the value, subsequent calls to XXX_Open should return NULL to the calling application to indicate failure.



Stream Interface Driver Functions
XXX_Init
Called when an instance of the driver is loaded. This function is required by drivers loaded by ActivateDeviceEx, ActivateDevice, or RegisterDevice.

The following list shows the tasks this function can perform:

  • Initialize the installed device to a default state.
  • Allocate resources used globally by the device driver.
  • Register a status callback function with PC Card Services.
    When the status of the device changes, the operating system calls this status callback function. For example, the status of a PC Card changes when you insert it or remove it.
  • Map system memory and I/O space to a PC Card device memory and I/O space.
  • Request notification on specific callback events.
  • Register an interrupt callback function for an interrupt-driven device.
    When the device generates an interrupt, the operating system calls this interrupt callback function.

XXX_Deinit
Called when an instance of the driver is unloaded. This function is required by drivers loaded by ActivateDeviceEx, ActivateDevice, or RegisterDevice.

If you have threads blocked in your driver, resources associated with the handle or device instance might not be able to be released. To avoid this, implement the XXX_PreClose (Device Manager) and XXX_PreDeinit (Device Manager) entry points.

XXX_Open
Called when a driver is opened by an application with CreateFile.

When this function executes, your device should allocate the resources that it needs for each open context and prepare for operation. This might involve preparing the device for reading or writing and initializing data structures it uses for operation.

XXX_Close
Called when a driver is closed by the application with CloseHandle.
An application calls the CloseHandle function to stop using a stream interface driver. The hFile parameter specifies the handle associated with the device context. In response to CloseHandle, the operating system invokes XXX_Close.

The file handle specified for hOpenContext is no longer valid after this function returns; if an application tries to perform stream I/O operations on that handle after calling CloseHandle, those operations fail.

XXX_IOControl
Called when the application calls DeviceIoControl. This function might or might not be required, depending on the device capabilities that the driver exposes. This function requires an implementation of XXX_Open and XXX_Close.

XXX_Read
Called when the application calls ReadFile.

XXX_Write
Called when the application calls WriteFile.

XXX_Seek
Called when the application calls SetFilePointer.

After an application calls the SetFilePointer function to move the data pointer in the device, the operating system invokes this function. If your device is capable of opening more than once, this function modifies only the data pointer for the instance specified by hOpenContext.

XXX_PowerUp
Called just before the system resumes. Optional.

The power handler functions, XXX_PowerUp and XXX_PowerDown, execute in kernel mode, and they cannot be pre-empted

XXX_PowerDown
Called just before the system suspends. Optional. It is useful only with devices that can be shut off under software control. Such devices are typically, but not exclusively, PC Cards.

XXX_PreClose
Optional. This function marks the closing handle as invalid and wakes any sleeping threads.

XXX_PreDeinit
This function marks the device instance as invalid and wakes sleeping threads. Required if the XXX_PreClose function is implemented.

Tuesday, June 12, 2007

GOOGLE 超犯規!!

google better than Limewire

難怪會一直被告 ~"~
這要保持低調啊 ><

Monday, June 11, 2007

AJAX

Asynchronous JavaScript And XML(/DHTML)
Ajax 由 HTML、JavaScript™ 技術、DHTML 和 DOM 組成,這一傑出的方法可以將笨拙的 Web 介面轉化成互動性的 Ajax 應用程式。

理解 Ajax 及其工作原理,建置網站的一種有效方法

Ajax開發教程

AJAX討論區 JavaWorld@Taiwan

APP208 Building AJAX applications on IE mobile (MEDC 2007)

AJAX in action (pdf)

Tuesday, June 5, 2007

MEDC 2007

APP321
Building World-Ready Windows Mobile© Applications by Mel Sampat

這堂演講的主題是寫程式的人該如何撰寫
讓application在轉換語言及使用設定(ex 時間日期格式)時可以輕鬆移植

Design strategies

  • Larger Text Fields -> 30% larger is a general rule.
  • Avoid Run-time string composition (各國語法不同 )
ex:
"are you sure you want to delete file?"
"are you sure you want to delete directory?"
"are you sure you want to delete subdirectory?"

char String[] = "are you sure you want to delete";
char FinalString[] = String + object + "?";

  • Avoid reusing resources (指重複相同的名詞但意義上不同會造成翻譯人員的困擾 orz)
  • Use FORMATMESSAGE instead of wsprintf (避免格式化時data buffer不足)
  • Use MUI DLLs (multilingual user interface DLLs)
  • Use NLS APIs (national language support APIs)

International API