Solved

GetOpenFileName API

Posted on 2000-03-24
5
295 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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 Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

861 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