PRB: CreateDialogIndirect() Fails Under Windows 95ID: Q137618
|
Programs that use CreateDialogIndirect() to create their dialog boxes at run time in Windows 95 may have trouble if the program has been ported from Windows NT or Windows 3.1.
The dialog resource for Windows 95 is the same as Windows NT; that is, all
strings must be in Unicode, and all structures must be DWORD aligned.
Programs ported from Windows NT may find that when they insert strings into
the dialog template resource, they used lstrcpyW() to force the string to
be Unicode or the program itself was called compiled for Unicode. However,
lstrcpyW() is not implemented in Windows 95, so it returns
ERROR_NOT_IMPLEMENTED. To generate Unicode strings in Windows 95, the
program must use MultiByteToWideChar().
Programs ported from 16-bit Windows 3.1 will probably have problems with
the Unicode strings mentioned above and also with the structure alignment.
In 16-bit Windows, dialog box resource structures are aligned on byte
boundaries, so there's no work for the programmer to do. However, in
Win32, all structures must be aligned on DWORD (four-byte) boundaries.
AlignPtr() is a simple helper routine that takes a pointer and returns the
nearest pointer aligned on a DWORD boundary. The program should call this
between all the dialog resource structures.
Use MultiByteToWideChar() to generate Unicode strings in Windows 95, and call AlignPtr(), which takes a pointer and returns the nearest pointer aligned on a DWORD boundary, between all the dialog resource structures to align all structures on DWORD boundries.
This behavior is by design.
//
// AlignPtr - Helper routine. Take an input pointer, return closest
// pointer that is aligned on a DWORD (4 byte) boundary.
//
LPWORD AlignPtr (LPWORD lpIn)
{
ULONG ul;
ul = (ULONG) lpIn;
ul +=3;
ul >>=2;
ul <<=2;
return (LPWORD) ul;
}
Additional query words: porting CreateDialogIndirectParam
Keywords : kbDlg kbResource kbGrpUser kbWinOS95 kbWinOS98
Version :
Platform :
Issue type : kbprb
Last Reviewed: March 6, 1999