FILE: AVIRSCE.EXE Plays an AVI Stored in a Resource .dll FileID: Q173668
|
This article shows you how to play an AVI file stored in a resource .dll
file through Visual Basic. Although you can add an AVI file to a resource
file in Visual Basic and then compile the Visual Basic project into a .dll
file, the AVI file is accessible only through Visual Basic.
An AVI file stored in a resource .dll file compiled in Visual C++ has two
advantages:
The following file is available for download from the Microsoft Software
Library:
~ Avirsce.exe (25Kb)
For more information about downloading files from the Microsoft Software
Library, please see the following article in the Microsoft Knowledge Base:
Q119591 : How to Obtain Microsoft Support Files from Online Services
- Avirsce.vbp (1Kb)-the project file
- Avirsce.vbw (1Kb)-the workspace file
- Form1.frm (2Kb)-the form file
- Module1.bas (5Kb)-the module file
- Readme.txt -you are reading this file
#define IDR_AVI1 101
Q178199 : HOWTO: Create a Resource DLL File Containing an AVI
Option Explicit
Private Sub Command1_Click()
Dim hRsrc As Long
Dim hGlobal As Long
Dim lpString As String
Dim strCmd As String, strReturnVal As String
Dim nbuf As Long
'Identifier for the AVI in the resource file from the resource.h
'file of the resource dll, which must be preceded by '#'.
lpString = "#101" ' <<<<
'Loads the resource
'Change the filename argument in the next line to the path and
'filename of your resource dll file.
hInst = LoadLibrary("<Path resource dll file name>") ' <<<<
hRsrc = FindResource(hInst, lpString, "AVI")
hGlobal = LoadResource(hInst, hRsrc)
lpData = LockResource(hGlobal)
fileSize = SizeofResource(hInst, hRsrc)
Call mmioInstallIOProc(MEY, AddressOf IOProc, _
MMIO_INSTALLPROC + MMIO_GLOBALPROC)
nbuf = 256
'Play the AVI file
strCmd = "open test.MEY+ type avivideo alias test"
strReturnVal = mciSendString(strCmd, 0&, 0&, 0&)
strCmd = "play test wait"
strReturnVal = mciSendString(strCmd, 0&, 0&, 0&)
strCmd = "close test"
strReturnVal = mciSendString(strCmd, 0&, 0&, 0&)
Call mmioInstallIOProc(MEY, vbNull, MMIO_REMOVEPROC)
FreeLibrary hInst
End Sub
Option Explicit
Public lpData As Long
Public fileSize As Long
Public hInst As Long
Public Const MMIO_INSTALLPROC = &H10000 'mmioInstallIOProc:install
'MMIOProc
Public Const MMIO_GLOBALPROC = &H10000000 'mmioInstallIOProc: install
'globally
Public Const MMIO_READ = &H0
Public Const MMIOM_CLOSE = 4
Public Const MMIOM_OPEN = 3
Public Const MMIOM_READ = MMIO_READ
Public Const MMIO_REMOVEPROC = &H20000
Public Const MMIOM_SEEK = 2
Public Const SEEK_CUR = 1
Public Const SEEK_END = 2
Public Const SEEK_SET = 0
Public Const MEY = &H2059454D 'This is the value of "MEY " run
'through FOURCC
'Create a user defined variable for the API function calls
Public Type MMIOINFO
dwFlags As Long
fccIOProc As Long
pIOProc As Long
wErrorRet As Long
htask As Long
cchBuffer As Long
pchBuffer As String
pchNext As String
pchEndRead As String
pchEndWrite As String
lBufOffset As Long
lDiskOffset As Long
adwInfo(4) As Long
dwReserved1 As Long
dwReserved2 As Long
hmmio As Long
End Type
'Finds the specified resource in an executable file. The function
'returns a resource handle that can be used by other functions used
'to load the resource.
Public Declare Function FindResource Lib "kernel32" _
Alias "FindResourceA" _
(ByVal hInstance As Long, _
ByVal lpName As String, _
ByVal lpType As String) _
As Long
'Returns a global memory handle to a resource in the specified
'module. The resource is only loaded after calling the LockResource
'function to get a pointer to the resource data.
Public Declare Function LoadResource Lib "kernel32" _
(ByVal hInstance As Long, _
ByVal hResInfo As Long) _
As Long
'Locks the specified resource. The function returns a 32-bit pointer
'to the data for the resource.
Public Declare Function LockResource Lib "kernel32" _
(ByVal hResData As Long) As Long
'Loads the specified dll file and maps the address space for the
'current process.
Public Declare Function LoadLibrary Lib "kernel32" _
Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
'Frees the specified .dll file loaded with the LoadLibrary function.
Public Declare Function FreeLibrary Lib "kernel32" _
(ByVal hLibModule As Long) As Long
'Copies a block of memory from one location to another.
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(hpvDest As Any, _
hpvSource As Any, _
ByVal cbCopy As Long)
'Installs or removes a custom I/O procedure. This function also
'locates an installed I/O procedure, using its corresponding
'four-character code.
Public Declare Function mmioInstallIOProc Lib "winmm" _
Alias "mmioInstallIOProcA" _
(ByVal fccIOProc As Long, _
ByVal pIOProc As Long, _
ByVal dwFlags As Long) _
As Long
'Sends the specified command string to an MCI device.
Public Declare Function mciSendString Lib "winmm.dll" _
Alias "mciSendStringA" _
(ByVal lpstrCommand As String, _
ByVal lpstrReturnString As Long, _
ByVal uReturnLength As Long, _
ByVal hwndCallback As Long) _
As Long
'Returns the size, in bytes, of the specified resource.
Public Declare Function SizeofResource Lib "kernel32" _
(ByVal hInstance As Long, _
ByVal hResInfo As Long) As Long
'Accesses a unique storage system, such as a database or file
'archive. Install or remove this callback function with the
'mmioInstallIOProc function.
Public Function IOProc _
(ByRef lpMMIOInfo As MMIOINFO, _
ByVal uMessage As Long, _
ByVal lParam1 As Long, _
ByVal lParam2 As Long) _
As Long
Static alreadyOpened As Boolean
Select Case uMessage
Case MMIOM_OPEN
If Not alreadyOpened Then
alreadyOpened = True
lpMMIOInfo.lDiskOffset = 0
End If
IOProc = 0
Case MMIOM_CLOSE
IOProc = 0
Case MMIOM_READ:
Call CopyMemory(ByVal lParam1, ByVal _
lpData + lpMMIOInfo.lDiskOffset, lParam2)
lpMMIOInfo.lDiskOffset = lpMMIOInfo.lDiskOffset + lParam2
IOProc = lParam2
Case MMIOM_SEEK
Select Case lParam2
Case SEEK_SET
lpMMIOInfo.lDiskOffset = lParam1
Case SEEK_CUR
lpMMIOInfo.lDiskOffset = lpMMIOInfo.lDiskOffset + lParam1
lpMMIOInfo.lDiskOffset = fileSize - 1 - lParam1
Case SEEK_END
lpMMIOInfo.lDiskOffset = fileSize - 1 - lParam1
End Select
IOProc = lpMMIOInfo.lDiskOffset
Case Else
IOProc = -1 ' Unexpected msgs. For instance, we do not
' process MMIOM_WRITE in this sample
End Select
End Function ' IOProc
For additional information, please see the following articles in the
Microsoft Knowledge Base:
Q124947 : Retrieving Palette Information From a Bitmap Resource
Q155360 : How to use MCI to Play AVI/WAVE Files From Memory
Keywords : kbsample kbVBp500 kbhowto
Version : WINDOWS:5.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: May 12, 1999