PRB: CreateDialogIndirect() Fails Under Windows 95

Last reviewed: October 3, 1995
Article ID: Q137618
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) version 4.0

SYMPTOMS

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.

CAUSE

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.

RESOLUTION

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.

STATUS

This 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
KBCategory: kbprg kbprb
KBSubcategory: UsrDlg


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 3, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.