COM for Windows CE |
The current generation of Windows CE operating systems supports only a simplified subset of the COM services found in Windows 95. Specifically, COM under Windows CE currently has the following limitations:
Since Windows CE supports only in-band (do-it-yourself) concurrency control, a thread that wants to invoke COM objects must use the COINIT_MULTITHREADED flag when calling CoInitializeEx:
In case you're wondering, the legacy CoInitialize API is undefined under Windows CE, and will thus result in a compile-time error if used. Attempting to pass the COINIT_APARTMENTTHREADED flag to CoInitializeEx will result in an E_INVALIDARG error.
The net effect of the lack of out-of-band support for concurrency management is that you are completely responsible for synchronizing access to your objects. ActiveX controls, which have thread affinity due to their use of thread-specific resources, should not be accessed by multiple threads. The common practice of using an apartment threaded singleton to synchronize data shared among multiple client threads does not work under Windows CE. You must instead make explicit calls to thread-synchronization primitives to protect member and global data. As with the desktop version of COM, a thread may call CoCreateInstance or CoGetClassObject to create a new instance of a component. Under Windows CE, the dwClsContext parameter in those calls must be set to CLSCTX_ INPROC_SERVER. In my experience, despite what the documentation says, Windows CE 2.01 will allow you to activate in-process COM objects by specifying CLSCTX_ ALL or CLSCTX_SERVER, but all other versions of Windows CE will return an E_NOTIMPL error if the flag is not explicitly set to CLSCTX_INPROC_SERVER. Additionally, the COSERVERINFO parameter in the call to CoGetClassObject must be NULL since remote servers are not supported.
As the power and prevalence of Windows CE increases, it is likely that Microsoft will eventually introduce Windows CE support for out-of-process servers, remote servers, security, out-of-band concurrency management, and the apartment model. I've heard rumors that future versions of Windows CE will even support a subset of the functionality found in Windows NT Server's Microsoft Message Queuing Service (MSMQ)! With that in mind, you should avoid the temptation to cheat (passing language-specific data types, writing data to [in] parameters with a server method, passing object pointers directly from one thread to another, and so on) while developing COM components for Windows CE. Future versions of Windows CE may cause misbehaved components to break.
Once you've created a Windows CE-based ActiveX control, you'll need to provide a version of it that runs under Windows NT so that it can be used from within design tools (resource or form editors). Here are the steps to take to create a desktop version of your control:
If necessary, add #define statements to the project source code to account for the differences between Windows NT and Windows CE. Beware of the fact that if you compile the project under Windows 95 or Windows 98 (which isn't supported by the toolkit), you'll run into potential problems due to the difference between Unicode and ANSI.
|
|