Solved

GetOpenFileName API

Posted on 2000-03-24
5
287 Views
Last Modified: 2008-02-26
HI,
  I am using GetOpenFileName function in comdlg32.dll, which works for windows 95 and 98, but doesn't work under NT 4.0. Any ideas? Is anyone has any example for that?

Thanks in advance,
Munny
0
Comment
Question by:MunnyPatel
  • 3
  • 2
5 Comments
 
LVL 9

Expert Comment

by:BrianWren
ID: 2653947
In what way does it not work?

Please be explicit.  

Could you post your declaration, and also the actual API call?
0
 

Author Comment

by:MunnyPatel
ID: 2654158
Hi BrianWren,
  Here's the code. It doesn't open up the File Open Dialog box in NT.

Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameW" (pOpenFileName As OPENFILENAME) As Long

Dim openFile As OPENFILENAME

Function GetOpenFile()

    Dim APIResults As Long
    Dim sFilter As String
    sFilter = "Text Files (*.txt)" & Chr(0) & "*.TXT" & Chr(0)

    openFile.lStructSize = Len(openFile
    openFile.hwndOwner = 0&
    openFile.lpstrFilter = sFilter
    openFile.lpstrCustomFilter = 0
    openFile.nMaxCustFilter = 0
    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 = "Test"
    openFile.Flags = 0
    openFile.nFileOffset = 0
    openFile.nFileExtension = 0
    openFile.lpstrDefExt = "txt" & Chr$(0)
    openFile.lCustData = 0
    openFile.lpfnHook = 0
    openFile.lpTemplateName = 0
   
    APIResults = GetOpenFileName(openFile)
    If APIResults <> 0 Then        
        GetOpenFile = True
    Else
        GetOpenFile = False
    End If

End Function
0
 
LVL 9

Accepted Solution

by:
BrianWren earned 50 total points
ID: 2654244
I modifies it as follows, and it is working for me on an NT 4.0 machine.

(The sFilter is not working right though...)

________________________________________________________________________________

Option Compare Database
Option Explicit

Declare Function GetOpenFileName _
        Lib "comdlg32.dll" _
        Alias "GetOpenFileNameW" (pOpenFileName As OPENFILENAME) As Long

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


Dim openFile As OPENFILENAME

Function GetOpenFile()

    Dim APIResults As Long
    Dim sFilter As String
    sFilter = "Text Files (*.txt)" & Chr$(0) & "*.TXT" & Chr$(0)

    openFile.lStructSize = Len(openFile)
    openFile.hwndOwner = 0&
    openFile.lpstrFilter = sFilter
    openFile.lpstrCustomFilter = 0
    openFile.nMaxCustFilter = 0
    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 = "Test"
    openFile.flags = 0
    openFile.nFileOffset = 0
    openFile.nFileExtension = 0
    openFile.lpstrDefExt = "txt" & Chr$(0)
    openFile.lCustData = 0
    openFile.lpfnHook = 0
    openFile.lpTemplateName = 0
     
    APIResults = GetOpenFileName(openFile)
    If APIResults <> 0 Then
        openFile.lpstrFile = RmvNulls(openFile.lpstrFile)
        openFile.lpstrFileTitle = RmvNulls(openFile.lpstrFileTitle)
        GetOpenFile = True
    Else
        GetOpenFile = False
    End If

End Function


Public Function RmvNulls(str As String) As String

    Dim i As Integer
    Dim s As String
   
    For i = 1 To Len(str)
         If Mid$(str, i, 1) <> Chr$(0) Then
              s = s & Mid$(str, i, 1)
         End If
    Next i

    RmvNulls = s

End Function

________________________________________________________________________________


Brian
0
 

Author Comment

by:MunnyPatel
ID: 2654349
Thank you very much BrianWren
0
 
LVL 9

Expert Comment

by:BrianWren
ID: 2654462
You're welcome!
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question