GetOpenFileName32 doesn't work under Win 2000 
Author Message
 GetOpenFileName32 doesn't work under Win 2000

Hello all !

    I have an application built in Access 2000 which uses the
GetOpenFileName32
API function.  My implementation works OK in Win 9x but in Win 2000
nothing happens.
Here is how I've set it up:

Type tagOPENFILENAME32
     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 Long
End Type

Global Const OFN_READONLY = &H1
Global Const OFN_OVERWRITEPROMPT = &H2
Global Const OFN_HIDEREADONLY = &H4
Global Const OFN_NOCHANGEDIR = &H8
Global Const OFN_SHOWHELP = &H10
Global Const OFN_ENABLEHOOK = &H20
Global Const OFN_ENABLETEMPLATE = &H40
Global Const OFN_ENABLETEMPLATEHANDLE = &H80
Global Const OFN_NOVALIDATE = &H100
Global Const OFN_ALLOWMULTISELECT = &H200
Global Const OFN_EXTENSIONDIFFERENT = &H400
Global Const OFN_PATHMUSTEXIST = &H800
Global Const OFN_FILEMUSTEXIST = &H1000
Global Const OFN_CREATEPROMPT = &H2000
Global Const OFN_SHAREAWARE = &H4000
Global Const OFN_NOREADONLYRETURN = &H8000
Global Const OFN_NOTESTFILECREATE = &H10000
Global Const OFN_NONETWORKBUTTON = &H20000
Global Const OFN_NOLONGNAMES = &H40000
Global Const OFN_EXPLORER = &H80000
Global Const OFN_NODEREFERENCELINKS = &H100000
Global Const OFN_LONGNAMES = &H200000

Global Const OFN_SHAREFALLTHROUGH = 2
Global Const OFN_SHARENOWARN = 1
Global Const OFN_SHAREWARN = 0

Declare Function GetOpenFileName32 _
        Lib "comdlg32.dll" _
        Alias "GetOpenFileNameA" _
            (OPENFILENAME32 As tagOPENFILENAME32) _
        As Long

I have a button on my form which calls the following sub:

Private Sub btnTempDB_Click()

    Dim strTemp As String

    strTemp = Select_DB()
    If Temp_DB <> strTemp Then
        If ReAttach_DB(strTemp, "N") Then
            txtADB.Caption = Temp_DB
        End If
    End If

End Sub

This sub in turn calls the Select_DB() function which attempts to invoke
the open file
dialog box:

Function Select_DB()

    Dim OPENFILENAME32 As tagOPENFILENAME32
    Dim IntI As Integer
    Dim strFilter As String
    Dim strFileName As String
    Dim strFileTitle As String
    Dim strTitle As String
    Dim strDefExt As String
    Dim strinitDir As String

    '*Define the filter string and allocate space in the "c" string
    strFilter = "Databases" & Chr$(0) & "AQ*.mdb" & Chr$(0) & Chr$(0)

    '* Allocate string space for the returned strings.
    strFileName = Chr$(0) & Space$(255) & Chr$(0)
    strFileTitle = Chr$(0) & Space$(255) & Chr$(0)

    '* Give the dialog a caption title.
    strTitle = "Select a Database" & Chr$(0)

    '* If the user does not specify an extension, append TXT.
    strDefExt = "mdb" & Chr$(0)

    '* Set up the defualt directory
    strinitDir = Data_Path & Chr$(0)

    '* Set up the data structure before you call the GetOpenFileName

    OPENFILENAME32.lStructSize = Len(OPENFILENAME32)
    OPENFILENAME32.hwndOwner = Screen.ActiveForm.Hwnd
    OPENFILENAME32.lpstrFilter = strFilter
    OPENFILENAME32.nFilterIndex = 1
    OPENFILENAME32.lpstrFile = strFileName
    OPENFILENAME32.nMaxFile = Len(strFileName)
    OPENFILENAME32.lpstrFileTitle = strFileTitle
    OPENFILENAME32.nMaxFileTitle = Len(strFileTitle)
    OPENFILENAME32.lpstrTitle = strTitle
    OPENFILENAME32.Flags = OFN_FILEMUSTEXIST Or OFN_READONLY
    OPENFILENAME32.lpstrDefExt = strDefExt
    OPENFILENAME32.hInstance = 0
    OPENFILENAME32.lpstrCustomFilter = "0"
    OPENFILENAME32.nMaxCustFilter = 0
    OPENFILENAME32.lpstrInitialDir = strinitDir
    OPENFILENAME32.nFileOffset = 0
    OPENFILENAME32.nFileExtension = 0
    OPENFILENAME32.lCustData = 0
    OPENFILENAME32.lpfnHook = 0
    OPENFILENAME32.lpTemplateName = 0

    '* This will pass the desired data structure to the Windows API,
    '* which will in turn use it to display the Open Dialog form.

     IntI = GetOpenFileName32(OPENFILENAME32)

     If IntI <> 0 Then
         strFileName = OPENFILENAME32.lpstrFile
         strFileName = Left$(strFileName, InStr(strFileName, Chr$(0)) -
1)
         Data_Path = Left$(strFileName, OPENFILENAME32.nFileOffset - 1)
         IntI = WritePrivateProfileString32("Parameters", "Data_Path",
Data_Path, run_path & "\AHQS.INI")
         Select_DB = Right$(strFileName, Len(strFileName) -
OPENFILENAME32.nFileOffset)
     Else
         If Err <> 0 Then
             MsgBox "Error: " & Error & " (" & Err & ")"
         End If
         Select_DB = Temp_DB
     End If

End Function

Can anyone help me to understand why this does not work under Win 2000
?  Any thoughts
would be greatly appreciated.  Thanks a bunch in advance !

Regards,
Mark



Sat, 14 Dec 2002 03:00:00 GMT  
 GetOpenFileName32 doesn't work under Win 2000
Shouldn't you be obtaining the structure length with LenB instead of Len?

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com


Quote:
> Hello all !

>     I have an application built in Access 2000 which uses the
> GetOpenFileName32
> API function.  My implementation works OK in Win 9x but in Win 2000
> nothing happens.
> Here is how I've set it up:

> Type tagOPENFILENAME32
>      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 Long
> End Type

> Global Const OFN_READONLY = &H1
> Global Const OFN_OVERWRITEPROMPT = &H2
> Global Const OFN_HIDEREADONLY = &H4
> Global Const OFN_NOCHANGEDIR = &H8
> Global Const OFN_SHOWHELP = &H10
> Global Const OFN_ENABLEHOOK = &H20
> Global Const OFN_ENABLETEMPLATE = &H40
> Global Const OFN_ENABLETEMPLATEHANDLE = &H80
> Global Const OFN_NOVALIDATE = &H100
> Global Const OFN_ALLOWMULTISELECT = &H200
> Global Const OFN_EXTENSIONDIFFERENT = &H400
> Global Const OFN_PATHMUSTEXIST = &H800
> Global Const OFN_FILEMUSTEXIST = &H1000
> Global Const OFN_CREATEPROMPT = &H2000
> Global Const OFN_SHAREAWARE = &H4000
> Global Const OFN_NOREADONLYRETURN = &H8000
> Global Const OFN_NOTESTFILECREATE = &H10000
> Global Const OFN_NONETWORKBUTTON = &H20000
> Global Const OFN_NOLONGNAMES = &H40000
> Global Const OFN_EXPLORER = &H80000
> Global Const OFN_NODEREFERENCELINKS = &H100000
> Global Const OFN_LONGNAMES = &H200000

> Global Const OFN_SHAREFALLTHROUGH = 2
> Global Const OFN_SHARENOWARN = 1
> Global Const OFN_SHAREWARN = 0

> Declare Function GetOpenFileName32 _
>         Lib "comdlg32.dll" _
>         Alias "GetOpenFileNameA" _
>             (OPENFILENAME32 As tagOPENFILENAME32) _
>         As Long

> I have a button on my form which calls the following sub:

> Private Sub btnTempDB_Click()

>     Dim strTemp As String

>     strTemp = Select_DB()
>     If Temp_DB <> strTemp Then
>         If ReAttach_DB(strTemp, "N") Then
>             txtADB.Caption = Temp_DB
>         End If
>     End If

> End Sub

> This sub in turn calls the Select_DB() function which attempts to invoke
> the open file
> dialog box:

> Function Select_DB()

>     Dim OPENFILENAME32 As tagOPENFILENAME32
>     Dim IntI As Integer
>     Dim strFilter As String
>     Dim strFileName As String
>     Dim strFileTitle As String
>     Dim strTitle As String
>     Dim strDefExt As String
>     Dim strinitDir As String

>     '*Define the filter string and allocate space in the "c" string
>     strFilter = "Databases" & Chr$(0) & "AQ*.mdb" & Chr$(0) & Chr$(0)

>     '* Allocate string space for the returned strings.
>     strFileName = Chr$(0) & Space$(255) & Chr$(0)
>     strFileTitle = Chr$(0) & Space$(255) & Chr$(0)

>     '* Give the dialog a caption title.
>     strTitle = "Select a Database" & Chr$(0)

>     '* If the user does not specify an extension, append TXT.
>     strDefExt = "mdb" & Chr$(0)

>     '* Set up the defualt directory
>     strinitDir = Data_Path & Chr$(0)

>     '* Set up the data structure before you call the GetOpenFileName

>     OPENFILENAME32.lStructSize = Len(OPENFILENAME32)
>     OPENFILENAME32.hwndOwner = Screen.ActiveForm.Hwnd
>     OPENFILENAME32.lpstrFilter = strFilter
>     OPENFILENAME32.nFilterIndex = 1
>     OPENFILENAME32.lpstrFile = strFileName
>     OPENFILENAME32.nMaxFile = Len(strFileName)
>     OPENFILENAME32.lpstrFileTitle = strFileTitle
>     OPENFILENAME32.nMaxFileTitle = Len(strFileTitle)
>     OPENFILENAME32.lpstrTitle = strTitle
>     OPENFILENAME32.Flags = OFN_FILEMUSTEXIST Or OFN_READONLY
>     OPENFILENAME32.lpstrDefExt = strDefExt
>     OPENFILENAME32.hInstance = 0
>     OPENFILENAME32.lpstrCustomFilter = "0"
>     OPENFILENAME32.nMaxCustFilter = 0
>     OPENFILENAME32.lpstrInitialDir = strinitDir
>     OPENFILENAME32.nFileOffset = 0
>     OPENFILENAME32.nFileExtension = 0
>     OPENFILENAME32.lCustData = 0
>     OPENFILENAME32.lpfnHook = 0
>     OPENFILENAME32.lpTemplateName = 0

>     '* This will pass the desired data structure to the Windows API,
>     '* which will in turn use it to display the Open Dialog form.

>      IntI = GetOpenFileName32(OPENFILENAME32)

>      If IntI <> 0 Then
>          strFileName = OPENFILENAME32.lpstrFile
>          strFileName = Left$(strFileName, InStr(strFileName, Chr$(0)) -
> 1)
>          Data_Path = Left$(strFileName, OPENFILENAME32.nFileOffset - 1)
>          IntI = WritePrivateProfileString32("Parameters", "Data_Path",
> Data_Path, run_path & "\AHQS.INI")
>          Select_DB = Right$(strFileName, Len(strFileName) -
> OPENFILENAME32.nFileOffset)
>      Else
>          If Err <> 0 Then
>              MsgBox "Error: " & Error & " (" & Err & ")"
>          End If
>          Select_DB = Temp_DB
>      End If

> End Function

> Can anyone help me to understand why this does not work under Win 2000
> ?  Any thoughts
> would be greatly appreciated.  Thanks a bunch in advance !

> Regards,
> Mark



Sat, 14 Dec 2002 03:00:00 GMT  
 GetOpenFileName32 doesn't work under Win 2000
Mark,

Quote:
>    OPENFILENAME32.lpstrCustomFilter = "0"

That's the line that causes it to fail (at least it was when I tried
it here). A zero as a string is very different from the number zero.
Simply remove the line, or if you want to include it, change it to
look like below, and it should work.

OPENFILENAME32.lpstrCustomFilter = vbNullString

Mattias

____________________________________________

    http://hem.spray.se/mattias.sjogren/



Sat, 14 Dec 2002 03:00:00 GMT  
 GetOpenFileName32 doesn't work under Win 2000
Jonathan,

Quote:
>Shouldn't you be obtaining the structure length with LenB instead of Len?

It doesn't matter in this case - both Len and LenB returns the correct
size (76).

Mattias

____________________________________________



Sat, 14 Dec 2002 03:00:00 GMT  
 GetOpenFileName32 doesn't work under Win 2000
It worked !!  Thank you very much Mattias !  It was an easy fix too (my
favourite kind ;-)  ).

Regards,
Mark

Quote:

> Mark,

> >    OPENFILENAME32.lpstrCustomFilter = "0"

> That's the line that causes it to fail (at least it was when I tried
> it here). A zero as a string is very different from the number zero.
> Simply remove the line, or if you want to include it, change it to
> look like below, and it should work.

> OPENFILENAME32.lpstrCustomFilter = vbNullString

> Mattias

> ____________________________________________

>     http://hem.spray.se/mattias.sjogren/



Sat, 14 Dec 2002 03:00:00 GMT  
 GetOpenFileName32 doesn't work under Win 2000
Hi Mark,

Haven't tested this, but it appears that the structure has three extra
members in win2K. So you could try adding three longs to the end of your
current structure, then when calling it, check to see if on win2k, if so set
it's length to lenb(OFN) else set it to Lenb(ofn)-12.  If that doesn't work
try declaring two different structures .

Bill.


Quote:
> Hello all !

>     I have an application built in Access 2000 which uses the
> GetOpenFileName32
> API function.  My implementation works OK in Win 9x but in Win 2000
> nothing happens.
> Here is how I've set it up:

> Type tagOPENFILENAME32
>      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 Long
> End Type

> Global Const OFN_READONLY = &H1
> Global Const OFN_OVERWRITEPROMPT = &H2
> Global Const OFN_HIDEREADONLY = &H4
> Global Const OFN_NOCHANGEDIR = &H8
> Global Const OFN_SHOWHELP = &H10
> Global Const OFN_ENABLEHOOK = &H20
> Global Const OFN_ENABLETEMPLATE = &H40
> Global Const OFN_ENABLETEMPLATEHANDLE = &H80
> Global Const OFN_NOVALIDATE = &H100
> Global Const OFN_ALLOWMULTISELECT = &H200
> Global Const OFN_EXTENSIONDIFFERENT = &H400
> Global Const OFN_PATHMUSTEXIST = &H800
> Global Const OFN_FILEMUSTEXIST = &H1000
> Global Const OFN_CREATEPROMPT = &H2000
> Global Const OFN_SHAREAWARE = &H4000
> Global Const OFN_NOREADONLYRETURN = &H8000
> Global Const OFN_NOTESTFILECREATE = &H10000
> Global Const OFN_NONETWORKBUTTON = &H20000
> Global Const OFN_NOLONGNAMES = &H40000
> Global Const OFN_EXPLORER = &H80000
> Global Const OFN_NODEREFERENCELINKS = &H100000
> Global Const OFN_LONGNAMES = &H200000

> Global Const OFN_SHAREFALLTHROUGH = 2
> Global Const OFN_SHARENOWARN = 1
> Global Const OFN_SHAREWARN = 0

> Declare Function GetOpenFileName32 _
>         Lib "comdlg32.dll" _
>         Alias "GetOpenFileNameA" _
>             (OPENFILENAME32 As tagOPENFILENAME32) _
>         As Long

> I have a button on my form which calls the following sub:

> Private Sub btnTempDB_Click()

>     Dim strTemp As String

>     strTemp = Select_DB()
>     If Temp_DB <> strTemp Then
>         If ReAttach_DB(strTemp, "N") Then
>             txtADB.Caption = Temp_DB
>         End If
>     End If

> End Sub

> This sub in turn calls the Select_DB() function which attempts to invoke
> the open file
> dialog box:

> Function Select_DB()

>     Dim OPENFILENAME32 As tagOPENFILENAME32
>     Dim IntI As Integer
>     Dim strFilter As String
>     Dim strFileName As String
>     Dim strFileTitle As String
>     Dim strTitle As String
>     Dim strDefExt As String
>     Dim strinitDir As String

>     '*Define the filter string and allocate space in the "c" string
>     strFilter = "Databases" & Chr$(0) & "AQ*.mdb" & Chr$(0) & Chr$(0)

>     '* Allocate string space for the returned strings.
>     strFileName = Chr$(0) & Space$(255) & Chr$(0)
>     strFileTitle = Chr$(0) & Space$(255) & Chr$(0)

>     '* Give the dialog a caption title.
>     strTitle = "Select a Database" & Chr$(0)

>     '* If the user does not specify an extension, append TXT.
>     strDefExt = "mdb" & Chr$(0)

>     '* Set up the defualt directory
>     strinitDir = Data_Path & Chr$(0)

>     '* Set up the data structure before you call the GetOpenFileName

>     OPENFILENAME32.lStructSize = Len(OPENFILENAME32)
>     OPENFILENAME32.hwndOwner = Screen.ActiveForm.Hwnd
>     OPENFILENAME32.lpstrFilter = strFilter
>     OPENFILENAME32.nFilterIndex = 1
>     OPENFILENAME32.lpstrFile = strFileName
>     OPENFILENAME32.nMaxFile = Len(strFileName)
>     OPENFILENAME32.lpstrFileTitle = strFileTitle
>     OPENFILENAME32.nMaxFileTitle = Len(strFileTitle)
>     OPENFILENAME32.lpstrTitle = strTitle
>     OPENFILENAME32.Flags = OFN_FILEMUSTEXIST Or OFN_READONLY
>     OPENFILENAME32.lpstrDefExt = strDefExt
>     OPENFILENAME32.hInstance = 0
>     OPENFILENAME32.lpstrCustomFilter = "0"
>     OPENFILENAME32.nMaxCustFilter = 0
>     OPENFILENAME32.lpstrInitialDir = strinitDir
>     OPENFILENAME32.nFileOffset = 0
>     OPENFILENAME32.nFileExtension = 0
>     OPENFILENAME32.lCustData = 0
>     OPENFILENAME32.lpfnHook = 0
>     OPENFILENAME32.lpTemplateName = 0

>     '* This will pass the desired data structure to the Windows API,
>     '* which will in turn use it to display the Open Dialog form.

>      IntI = GetOpenFileName32(OPENFILENAME32)

>      If IntI <> 0 Then
>          strFileName = OPENFILENAME32.lpstrFile
>          strFileName = Left$(strFileName, InStr(strFileName, Chr$(0)) -
> 1)
>          Data_Path = Left$(strFileName, OPENFILENAME32.nFileOffset - 1)
>          IntI = WritePrivateProfileString32("Parameters", "Data_Path",
> Data_Path, run_path & "\AHQS.INI")
>          Select_DB = Right$(strFileName, Len(strFileName) -
> OPENFILENAME32.nFileOffset)
>      Else
>          If Err <> 0 Then
>              MsgBox "Error: " & Error & " (" & Err & ")"
>          End If
>          Select_DB = Temp_DB
>      End If

> End Function

> Can anyone help me to understand why this does not work under Win 2000
> ?  Any thoughts
> would be greatly appreciated.  Thanks a bunch in advance !

> Regards,
> Mark



Sun, 15 Dec 2002 03:00:00 GMT  
 GetOpenFileName32 doesn't work under Win 2000
Hi Jonathon,

well spotted !


Quote:
> Shouldn't you be obtaining the structure length with LenB instead of Len?

<SNIP>

Mark, try Jonathon's suggestion.



Sun, 15 Dec 2002 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Win 2000 Offline files doesn't work with mdb

2. Why doesn't this code work on win 2000

3. My Listbox Won't Ignore Me (WM_SETREDRAW doesn't work)

4. CreatQueryDef In Access 2000 Doesn't Work?

5. ADO Help doesn't work from within Access 2000

6. OpenDatabase doesn't work in Access 2000

7. An access 95 program doesn't work on access 2000

8. Code doesn't work on windows 2000

9. Gettype for Windows 2000 doesn't work?

10. ListType Property doesn't work with Word 2000

11. How ironic, the HPC 2000 SDK Download page doesn't work

12. Program from access 97 won't work in access 2000

 

 
Powered by phpBB® Forum Software