PRB: CreateDialogIndirect() Fails Under Windows 95Last reviewed: October 3, 1995Article ID: Q137618 |
The information in this article applies to:
SYMPTOMSPrograms 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.
CAUSEThe 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.
RESOLUTIONUse 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.
STATUSThis behavior is by design.
MORE INFORMATION
// // 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 reference words: porting Win95 4.00 CreateDialogIndirectParam
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |