1

Sub Main()

    'Declare a variable as a FileDialog object.
    Dim fd As FileDialog

    'Create a FileDialog object as a File Picker dialog box.
    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    'Declare a variable to contain the path
    'of each selected item. Even though the path is a String,
    'the variable must be a Variant because For Each...Next
    'routines only work with Variants and Objects.
    Dim vrtSelectedItem As Variant

    'Use a With...End With block to reference the FileDialog object.
    With fd

        'Use the Show method to display the File Picker dialog box and return the user's action.
        'The user pressed the action button.
        If .Show = -1 Then

            'Step through each string in the FileDialogSelectedItems collection.
            For Each vrtSelectedItem In .SelectedItems

                'vrtSelectedItem is a String that contains the path of each selected item.
                'You can use any file I/O functions that you want to work with this path.
                'This example simply displays the path in a message box.
                MsgBox "The path is: " & vrtSelectedItem

            Next vrtSelectedItem
        'The user pressed Cancel.
        Else
        End If
    End With

    'Set the object variable to Nothing.
    Set fd = Nothing

End Sub

2

******************************************************

********************************************************

******************************************************

'************** WinAPI function **************

'http://www.shrinkwrapvb.com/avihelp/avihlp_1.htm

'Feel free to replace cFileDlg.cls class with the VB Common Dialog ocx if

' you really want to

'The AVIFileOpen function accepts the same OF flags as the OpenFile API 

' function

 

Dim res As Long 'result code
Dim ofd As cFileDlg 'OpenFileDialog class
Dim szFile As String 'filename

'Get the name of an AVI file to work with
Set ofd = New cFileDlg
With ofd
    .OwnerHwnd = Me.hWnd
    .Filter = "AVI Files|*.avi"
    .DlgTitle = "Open AVI File"
End With
res = ofd.VBGetOpenFileName(szFile)
If res = False Then GoTo ErrorOut

ErrorOut:
    If pAVIFile <> 0 Then
        Call AVIFileRelease(pAVIFile)
'// closes the file
    End If

    If (rc <> AVIERR_OK) Then
'if there was an error then show feedback to user
        MsgBox "There was an error working with the file:" _
                & vbCrLf & szFile, vbInformation, App.Title
    End If

'******************************************

For our simple test program, put the following line of code in Form_Load:

Call AVIFileInit '// opens AVIFile library

And put the following line of code in Form_Unload:

Call AVIFileExit '// releases AVIFile library

'******************************************

The next step is to be able to open the AVI file that the user selects from the common dialog and get a PAVIFILE handle which can be passed to other AVIFile functions as necessary.  We use the AVIFileOpen function to do this.  Add these 2 lines of code to the command button click event

Dim pAVIFile as Long 'pointer to AVI File (PAVIFILE handle)

res = AVIFileOpen(pAVIFile, szFile, OF_SHARE_DENY_WRITE, 0&)