Passing Messages to 16-Bit Windows

Passing data between 16-bit and 32-bit window procedures via message parameters also requires consideration of the internal representations of the data types passed within the parameter. For system-defined message classes, this is handled automatically by OS/2 Version 2.0, but for application-defined message classes the conversion between addressing schemes must be handled by the application, since the operating system has no way of determining the intended contents of each parameter.

Simple "value" parameters (such as integers, characters, etc.) may be passed without the need for translation. It is recommended that message parameters be constructed using the standard Presentation Manager macros described in Creating Message Parameters.

When a pointer or handle is passed in a message parameter to a 16-bit window procedure, the pointer or handle must be translated to the 16:16 addressing scheme by the application. Since the 16-bit module is unlikely to have been written with code to achieve this conversion, it is the responsibility of the 32-bit module.

Conversion may be achieved using the _Seg16 keyword to explicitly define a 16:16 pointer or handle, which is then placed in a message parameter using the MPFROMP macro. This is illustrated in Figure "Passing a 16:16 Pointer as a Message Parameter".

The resulting message parameter may then be passed to a window in a 16-bit module using the normal WinPostMsg() or WinSendMsg() functions, using a 16:16 window handle obtained in the manner shown in Figure "Creating a 16-bit Window From Within a 32-bit Module". Note that the data structure referenced by the pointer may not be greater than 64 KB in size, and must not cross a segment boundary. This is ensured in Figure "Passing a 16:16 Pointer as a Message Parameter" by using the #pragma seg16 directive, since a structure defined using this pragma will automatically be aligned on a segment boundary by the C Set/2 compiler.

Note also that defining a structure with the #pragma seg16 directive does not implicitly qualify pointers within the structure with the _Seg16 keyword. Such pointers must be explicitly qualified, as shown in Figure "Creating a 16-bit Window From Within a 32-bit Module". Further information on the #pragma seg16 directive can be found in the IBM C Set/2 User's Guide.

A 0:32 pointer may also be converted to a 16:16 pointer using the DosFlattoSel() function provided by OS/2 Version 2.0. This function provides the correct remapping of pointer formats from the 32-bit flat memory model to the 16-bit segmented memory model.


[Back: Creating a Window]
[Next: Passing Messages to 32-Bit Windows]