Microsoft KB Archive/942234

= An MFC application that uses the GetUserName function may crash on a computer that is running Windows Vista =

Article ID: 942234

Article Last Modified on 11/20/2007

-

APPLIES TO


 * Microsoft Foundation Class Library 4.2

-



SYMPTOMS
Consider the following scenario. On a computer that is running Windows Vista, the Setup.exe file starts a Microsoft Foundation Classes (MFC) application. The MFC application uses the GetUserName function. In this scenario, the MFC application may crash after the MFC application compatibility is set.

This problem occurs if the following conditions are true:
 * The GetUserName function uses the Secur32.dll file.
 * The DllMain function calls the GetUserName function.



CAUSE
This problem occurs because the GetUserName function initializes the Secur32.dll file. However, the DllMain function that is in the Secur32.dll file breaks the initialization afterward.

For more information about the cause of this problem, visit the following Microsoft Developer Network (MSDN) Web site:

http://msdn2.microsoft.com/en-us/library/ms682583.aspx



WORKAROUND
To work around this problem, use one of the following methods.

Method 1
Provide an application manifest for the Setup.exe file. When the requestedExecutionLevel element is present in an embedded application manifest, the requestedExecutionLevel element overrides the installer detection in Windows Vista. You can test this behavior by confirming that the __COMPAT_LAYER environment variable equals &quot;VistaSetUp&quot; in the process.

For example, assume that the setup file is named the Setup.exe file and that the application manifest is named the Setup.exe.manifest file.

Note You must put the application manifest and the setup file in the same folder. You can also embed the application manifest as a resource.

In this example, you can use an application manifest that resembles the following.    Description of your installer program

     For more information about this method, download the &quot;Windows Vista Application Development Requirements for User Account Control Compatibility&quot; document. To do this, visit the following Microsoft Web site:

http://go.microsoft.com/fwlink/?LinkId=81232

Note In this document, refer to the &quot;Installer Detection&quot; section and to the &quot;Step Six: Create and Embed an Application Manifest with Your Application&quot; section.

Method 2
Use Microsoft Application Compatibility Toolkit (ACT) 5.0 to apply the DelayDLLInit feature. The DelayDLLInit feature delays the loading of some .dll files. You can use ACT 5.0 to load the Secur32.dll file before you load the .dll files that call the GetUserName function from the DllMain function. This operation avoids the problem. You must perform this operation for each child process that crashes.

To do this, follow these steps:  Download and then install ACT 5.0. To do this, visit the following Microsoft Web site:

http://technet.microsoft.com/en-us/windowsvista/aa905078.aspx

 Run the Compatibility Administrator (Compatadmin.exe) by using elevated user rights. In the Compatibility Administrator, expand Custom Database, right-click New database (1) [Untitled_1], point to Create New, and then click Application Fix.</li> On the Program information page, type the MFC application name in the Name of the program to be fixed box, type the vendor name in the Name of the vendor for this program box, specify a location in the Program file location box, and then click Next.

Note This information is for the executable file of the MFC application that crashes. This information is not for the Setup.exe file.</li> On the Compatibility Modes page, click None, and then click Next.</li> On the Compatibility Fixes page, click to select the DelayDLLInit check box, and then click Parameters.</li> In the Options for AddProcessParametersFlags dialog box, enter the .dll files that you want to delay in the Command line box, and then click OK.

Notes <ul> Separate the .dll files by using a semicolon .</li> The .dll files are loaded in the reverse order.</li> The .dll file list must contain the .dll files that call the GetUserName function from the DllMain function.</li> To make sure that the application fix is applied, you can click Test Run.</li></ul> </li> Click Next.</li> On the Matching Information page, add attributes to match each file of the MFC application, and then select additional matching files.

Note This step is optional.</li> Click Finish.</li> On the File menu in the Compatibility Administrator, click Save As, specify a database name, and then click OK.</li> In the Save Database dialog box, specify a location, and then save the database as an .sdb file.</li> On the File menu in the Compatibility Administrator, click Install.</li> Run the MFC application.</li></ol>

To distribute the application fix to multiple computers, run the following command at a command prompt by using elevated user rights:

SDBINST 

To uninstall the application fix, use one of the following techniques: <ul> <li>In Control Panel, use Add or Remove Programs.</li> <li>Run the following command at a command prompt by using elevated user rights:

SDBINST -U 

</li></ul>

Keywords: kbexpertiseadvanced kbtshoot kbprb KB942234

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.