[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

GetOpenFileName API

Posted on 2000-03-24
5
Medium Priority
?
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

656 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