Solved

GetOpenFileName API

Posted on 2000-03-24
5
268 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you very much BrianWren
0
 
LVL 9

Expert Comment

by:BrianWren
Comment Utility
You're welcome!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
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.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now