Microsoft KB Archive/888167

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

Article ID: 888167

Article Last Modified on 7/19/2005

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic for Applications 6.0
 * Microsoft Visual Basic 6.0 Learning Edition

-



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 &quot;comdlg32.dll&quot; Alias _ &quot;GetOpenFileNameA&quot; (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 = &quot;Batch Files (*.bat)&quot; & Chr(0) & &quot;*.BAT&quot; & 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 = &quot;C:\&quot; OpenFile.lpstrTitle = &quot;Use the Comdlg API not the OCX&quot; OpenFile.flags = 0 lReturn = GetOpenFileName(OpenFile) If lReturn = 0 Then MsgBox &quot;The User pressed the Cancel Button&quot; Else MsgBox &quot;The user Chose &quot; & 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 &quot;Applies to&quot; section.

Keywords: kbtshoot kbbug kbprogramming kbpending KB888167

-

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

© Microsoft Corporation. All rights reserved.