다음을 통해 공유


Tips for Writing ACM Drivers (Windows Embedded CE 6.0)

1/6/2010

The following list contains guidelines for writing ACM drivers:

  • Allocate driver-instance data in response to the DRV_OPEN message. You will usually need some data throughout the life of the driver; for example, you need the module-instance handle to load resource strings. Define a structure containing this data, and then allocate it in response to DRV_OPEN.
    Do not save this structure as a global variable. Instead, return a pointer to the structure as the return value for the DRV_OPEN message. This pointer will be passed back to the driver in every subsequent message, as the first parameter of the DriverProc function. Remember to free this driver-instance data in response to the DRV_CLOSE message.
  • Allocate stream-instance data in response to the ACMDM_STREAM_OPEN message. You will usually need some instance data for each open stream.
    Because there could be several streams open at the same time, you should not store this data as a global variable. Instead, define a structure containing the required data, and then allocate it in response to ACMDM_STREAM_OPEN.
    In that message, the driver is passed a pointer to an ACMDRVSTREAMINSTANCE structure. Store a pointer to the stream-instance data in the dwDriver member and it will be available on every call involving that stream.
    Remember to free the stream-instance data in response to the ACMDM_STREAM_CLOSE message.
  • Avoid using global variables. Defining a single DWORD of global data will use 4 KB of memory in every process that uses the ACM, because your driver is loaded into each process. There is no need to use global data; instead, use the instance data, as described earlier.
  • Be sure that your driver processes the ACMDM_STREAM_CONVERT message as quickly as possible. Perform as much processing as possible in the ACMDM_STREAM_OPEN message.
  • Handle error conditions correctly. You cannot always depend on the success of calls to the USER module, such as LoadString and LoadIcon. In particular, when your codec is used to play system sounds, it may be loaded into a context in which these calls are unable to succeed. Although there will be no opportunity for your codec to display icons or strings in this context, your code must be prepared handle this situation.
  • Store configuration data on a per-user basis. Each user should be able to configure an ACM driver according to personal preferences. Therefore, configuration information should be stored in the HKEY_CURRENT_USER section of the registry.
  • Provide a valid default configuration. Configuration data will usually be stored on a per-user basis; however, in some contexts, such as when playing system sounds, there will be no defined current user. In these situations, calls to the registry will fail. You must provide a default configuration to handle this failure.

See Also

Concepts

ACM Driver Development