[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

GetOpenFileName API

Posted on 2000-03-24
5
Medium Priority
?
352 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 200 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
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…

834 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