FIX: You receive a "The common dialog function failed during initialization" error message when your Visual Basic 6.0 program runs on a Terminal Server and uses the Common Dialog control to open a file (888167)



The information in this article applies to:

  • Microsoft Visual Basic Professional Edition for Windows 6.0
  • Microsoft Visual Basic for Applications 6.0
  • Microsoft Visual Basic Learning Edition for Windows 6.0

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

SYMPTOMS

You have a Microsoft Visual Basic 6.0 program that runs on a Terminal Server, the program uses the Common Dialog control to open a file, and the following conditions are true:
  • The user is using a roaming profile.
  • There is a policy to delete the roaming profile when the user logs off.
When these conditions are true, you may receive an error message that is similar to the following:
Error Info: 32765 The common dialog function failed during initialization. This error frequently occurs when insufficient memory is available.

CAUSE

This bug occurs because the Common Dialog control requires a shell or one of the folders in the profile of the user to start. The Common Dialog control will try the following folders in this order:
  1. A folder that is explicitly specified by the caller of the GetOpenFileName API.
  2. The last-visited folder for the current executable name, stored in the registry under the profile of the user.
  3. The current folder, if any files in the current folder match the default filter that appears in the Files of Type combo box.
  4. The My Documents folder of the user.
  5. The Desktop of the user. This requires a Desktop folder in the profile of the user.

RESOLUTION

To resolve this bug, use the following code sample as a reference. This code sample demonstrates how to use the File Open dialog box in the Comdlg32.dll library.
  1. Start Visual Basic 6.0.
  2. Click Standard EXE.
  3. Add a CommandButton control to Form1.
  4. Add the following code to the Form1 code window.
Option Explicit

       Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _
         "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

       Private Type OPENFILENAME
         lStructSize As Long
         hwndOwner As Long
         hInstance As Long
         lpstrFilter As String
         lpstrCustomFilter As String
         nMaxCustFilter As Long
         nFilterIndex As Long
         lpstrFile As String
         nMaxFile As Long
         lpstrFileTitle As String
         nMaxFileTitle As Long
         lpstrInitialDir As String
         lpstrTitle As String
         flags As Long
         nFileOffset As Integer
         nFileExtension As Integer
         lpstrDefExt As String
         lCustData As Long
         lpfnHook As Long
         lpTemplateName As String
       End Type

       Private Sub Command1_Click()
         Dim OpenFile As OPENFILENAME
         Dim lReturn As Long
         Dim sFilter As String
         OpenFile.lStructSize = Len(OpenFile)
         OpenFile.hwndOwner = Form1.hWnd
         OpenFile.hInstance = App.hInstance
         sFilter = "Batch Files (*.bat)" & Chr(0) & "*.BAT" & Chr(0)
         OpenFile.lpstrFilter = sFilter
         OpenFile.nFilterIndex = 1
         OpenFile.lpstrFile = String(257, 0)
         OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
         OpenFile.lpstrFileTitle = OpenFile.lpstrFile
         OpenFile.nMaxFileTitle = OpenFile.nMaxFile
         OpenFile.lpstrInitialDir = "C:\"
         OpenFile.lpstrTitle = "Use the Comdlg API not the OCX"
         OpenFile.flags = 0
         lReturn = GetOpenFileName(OpenFile)
         If lReturn = 0 Then
            MsgBox "The User pressed the Cancel Button"
         Else
            MsgBox "The user Chose " & Trim(OpenFile.lpstrFile)
         End If
       End Sub

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

Modification Type:MajorLast Reviewed:7/19/2005
Keywords:kbpending kbProgramming kbtshoot kbbug KB888167 kbAudDeveloper