1
QB64 Discussion / Re: Errors running all examples in win-lib.
« on: October 13, 2019, 09:21:47 am »I’d bet a dollar against a dime that you’ve download and using the 64-bit version of QB64. ;)Yes, I'm running x64, why?
A lot of those examples were written when we only offered a 32-bit version of QB64. Change those DECLARE LIBRARY routines to be _INTEGER64, instead of LONG, and the issue will go away.
I changed all LONG to _INTEGER64
I'm trying to build a video-player for a drone project.
The code that plays the video, works fine for me, although I still haven't figured out the options to pass, for controls, etc. or getting information, like POINT (x,y) from a frame, etc - so it's a work i progress.
I added the Open File Dialog, from the examples (and in the built-in help) - but it just produces errors,
Code: [Select]
'=============
'QB64VIDEO.BAS
'=============
'Plays a video file in QB64 via MCI commands (WINDOWS ONLY)
'Coded by Dav, forgot what year...
'NOTE: This demo plays a sample video name davpiano.wmv.
DECLARE DYNAMIC LIBRARY "WINMM"
FUNCTION mciSendStringA% (lpstrCommand AS STRING, lpstrReturnString AS STRING, BYVAL uReturnLength AS INTEGER, BYVAL hwndCallback AS INTEGER)
' mciSendStringA function plays media files and returns the following:
' 0 = command sucessful
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' lpstrCommand is the MCI command string (and optional flags) to send.
' lpstrReturnString is a string that holds any return information.
' uReturnLength is the length of the lpstrReturnString string passed.
' NOTE: If lpstrCommand given doesn't retun a value then lpstrReturnString
' can be empty and uReturnLength can be set to 0.
' hwndCallback contains a callback window handle (only if the Notify flag used in lpstrCommand)
'====================================================================
FUNCTION mciGetErrorStringA% (BYVAL dwError AS INTEGER, lpstrBuffer AS STRING, BYVAL uLength AS INTEGER)
' mciGetErrorStringA returns error info if the mciSendStringA failed.
' dwError is the return value from the mciSendString function.
' lpstrBuffer string holds the error information returned by the function.
' uLength is the length of the lpstrBuffer string buffer.
'====================================================================
END DECLARE
DECLARE CUSTOMTYPE LIBRARY
FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$)
END DECLARE
' Dialog flag constants (use + or OR to use more than 1 flag value)
CONST OFN_ALLOWMULTISELECT = &H200& ' Allows the user to select more than one file, not recommended!
CONST OFN_CREATEPROMPT = &H2000& ' Prompts if a file not found should be created(GetOpenFileName only).
CONST OFN_EXTENSIONDIFFERENT = &H400& 'Allows user to specify file extension other than default extension.
CONST OFN_FILEMUSTEXIST = &H1000& ' Chechs File name exists(GetOpenFileName only).
CONST OFN_HIDEREADONLY = &H4& ' Hides read-only checkbox(GetOpenFileName only)
CONST OFN_NOCHANGEDIR = &H8& ' Restores the current directory to original value if user changed
CONST OFN_NODEREFERENCELINKS = &H100000& 'Returns path and file name of selected shortcut(.LNK) file instead of file referenced.
CONST OFN_NONETWORKBUTTON = &H20000& ' Hides and disables the Network button.
CONST OFN_NOREADONLYRETURN = &H8000& ' Prevents selection of read-only files, or files in read-only subdirectory.
CONST OFN_NOVALIDATE = &H100& ' Allows invalid file name characters.
CONST OFN_OVERWRITEPROMPT = &H2& ' Prompts if file already exists(GetSaveFileName only)
CONST OFN_PATHMUSTEXIST = &H800& ' Checks Path name exists (set with OFN_FILEMUSTEXIST).
CONST OFN_READONLY = &H1& ' Checks read-only checkbox. Returns if checkbox is checked
CONST OFN_SHAREAWARE = &H4000& ' Ignores sharing violations in networking
CONST OFN_SHOWHELP = &H10& ' Shows the help button (useless!)
'--------------------------------------------------------------------------------------------
DEFINT A-Z
TYPE FILEDIALOGTYPE
lStructSize AS _INTEGER64 ' For the DLL call
hwndOwner AS _INTEGER64 ' Dialog will hide behind window when not set correctly
hInstance AS _INTEGER64 ' Handle to a module that contains a dialog box template.
lpstrFilter AS _OFFSET ' Pointer of the string of file filters
lpstrCustFilter AS _OFFSET
nMaxCustFilter AS _INTEGER64
nFilterIndex AS _INTEGER64 ' One based starting filter index to use when dialog is called
lpstrFile AS _OFFSET ' String full of 0's for the selected file name
nMaxFile AS _INTEGER64 ' Maximum length of the string stuffed with 0's minus 1
lpstrFileTitle AS _OFFSET ' Same as lpstrFile
nMaxFileTitle AS _INTEGER64 ' Same as nMaxFile
lpstrInitialDir AS _OFFSET ' Starting directory
lpstrTitle AS _OFFSET ' Dialog title
flags AS _INTEGER64 ' Dialog flags
nFileOffset AS INTEGER ' Zero-based offset from path beginning to file name string pointed to by lpstrFile
nFileExtension AS INTEGER ' Zero-based offset from path beginning to file extension string pointed to by lpstrFile.
lpstrDefExt AS _OFFSET ' Default/selected file extension
lCustData AS _INTEGER64
lpfnHook AS _INTEGER64
lpTemplateName AS _OFFSET
END TYPE
DECLARE DYNAMIC LIBRARY "comdlg32" ' Library declarations using _OFFSET types
FUNCTION GetOpenFileNameA& (DIALOGPARAMS AS FILEDIALOGTYPE) ' The Open file dialog
FUNCTION GetSaveFileNameA& (DIALOGPARAMS AS FILEDIALOGTYPE) ' The Save file dialog
END DECLARE
' Do the Open File dialog call!
Filter$ = "*.*"
Flags& = OFN_FILEMUSTEXIST + OFN_NOCHANGEDIR + OFN_READONLY ' add flag constants here
OFile$ = GetOpenFileName$(" ", ".\", Filter$, 1, Flags&, hWnd&)
IF OFile$ = "" THEN ' Display Open dialog results
PRINT "You must pick a file."
ELSE
END IF
filename$= OFile$
IF NOT _FILEEXISTS(filename$) THEN
PRINT filename$ + " " + "not found."
END
END IF
handle& = _NEWIMAGE(1024, 768, 32) '<===== The x/y size of my video
SCREEN handle&
DO UNTIL _SCREENEXISTS: _LIMIT 30: LOOP 'be sure screen exists before using in this way
title$ = "QB64 Video Player - " + filename$
_TITLE title$
hwnd& = FindWindow(0, title$ + CHR$(0))
ReturnString$ = SPACE$(255): ErrorString$ = SPACE$(255)
a% = mciSendStringA%("open " + filename$ + " style popup", ReturnString$, LEN(ReturnString$), 0)
IF a% THEN
x% = mciGetErrorStringA%(a%, ErrorString$, LEN(ErrorString$))
PRINT ErrorString$
END
ELSE
a2% = mciSendStringA%("window " + filename$ + " handle " + STR$(hwnd&), ReturnString$, LEN(ReturnString$), 0)
b% = mciSendStringA%("play " + filename$, "", 0, 0)
'=== Play video...
DO
_LIMIT 30
'you can add pause/resume routine here if you want...
LOOP UNTIL INKEY$ <> ""
x% = mciSendStringA%("stop " + filename$, "", 0, 0)
x% = mciSendStringA%("close " + filename$, "", 0, 0)
END IF
The original code:
Code: [Select]
'=============
'QB64VIDEO.BAS
'=============
'Plays a video file in QB64 via MCI commands (WINDOWS ONLY)
'Coded by Dav, forgot what year...
'NOTE: This demo plays a sample video name davpiano.wmv.
DECLARE DYNAMIC LIBRARY "WINMM"
FUNCTION mciSendStringA% (lpstrCommand AS STRING, lpstrReturnString AS STRING, BYVAL uReturnLength AS INTEGER, BYVAL hwndCallback AS INTEGER)
' mciSendStringA function plays media files and returns the following:
' 0 = command sucessful
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' lpstrCommand is the MCI command string (and optional flags) to send.
' lpstrReturnString is a string that holds any return information.
' uReturnLength is the length of the lpstrReturnString string passed.
' NOTE: If lpstrCommand given doesn't retun a value then lpstrReturnString
' can be empty and uReturnLength can be set to 0.
' hwndCallback contains a callback window handle (only if the Notify flag used in lpstrCommand)
'====================================================================
FUNCTION mciGetErrorStringA% (BYVAL dwError AS INTEGER, lpstrBuffer AS STRING, BYVAL uLength AS INTEGER)
' mciGetErrorStringA returns error info if the mciSendStringA failed.
' dwError is the return value from the mciSendString function.
' lpstrBuffer string holds the error information returned by the function.
' uLength is the length of the lpstrBuffer string buffer.
'====================================================================
END DECLARE
DECLARE CUSTOMTYPE LIBRARY
FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$)
END DECLARE
' Dialog flag constants (use + or OR to use more than 1 flag value)
CONST OFN_ALLOWMULTISELECT = &H200& ' Allows the user to select more than one file, not recommended!
CONST OFN_CREATEPROMPT = &H2000& ' Prompts if a file not found should be created(GetOpenFileName only).
CONST OFN_EXTENSIONDIFFERENT = &H400& 'Allows user to specify file extension other than default extension.
CONST OFN_FILEMUSTEXIST = &H1000& ' Chechs File name exists(GetOpenFileName only).
CONST OFN_HIDEREADONLY = &H4& ' Hides read-only checkbox(GetOpenFileName only)
CONST OFN_NOCHANGEDIR = &H8& ' Restores the current directory to original value if user changed
CONST OFN_NODEREFERENCELINKS = &H100000& 'Returns path and file name of selected shortcut(.LNK) file instead of file referenced.
CONST OFN_NONETWORKBUTTON = &H20000& ' Hides and disables the Network button.
CONST OFN_NOREADONLYRETURN = &H8000& ' Prevents selection of read-only files, or files in read-only subdirectory.
CONST OFN_NOVALIDATE = &H100& ' Allows invalid file name characters.
CONST OFN_OVERWRITEPROMPT = &H2& ' Prompts if file already exists(GetSaveFileName only)
CONST OFN_PATHMUSTEXIST = &H800& ' Checks Path name exists (set with OFN_FILEMUSTEXIST).
CONST OFN_READONLY = &H1& ' Checks read-only checkbox. Returns if checkbox is checked
CONST OFN_SHAREAWARE = &H4000& ' Ignores sharing violations in networking
CONST OFN_SHOWHELP = &H10& ' Shows the help button (useless!)
'--------------------------------------------------------------------------------------------
DEFINT A-Z
TYPE FILEDIALOGTYPE
lStructSize AS LONG ' For the DLL call
hwndOwner AS LONG ' Dialog will hide behind window when not set correctly
hInstance AS LONG ' Handle to a module that contains a dialog box template.
lpstrFilter AS _OFFSET ' Pointer of the string of file filters
lpstrCustFilter AS _OFFSET
nMaxCustFilter AS LONG
nFilterIndex AS LONG ' One based starting filter index to use when dialog is called
lpstrFile AS _OFFSET ' String full of 0's for the selected file name
nMaxFile AS LONG ' Maximum length of the string stuffed with 0's minus 1
lpstrFileTitle AS _OFFSET ' Same as lpstrFile
nMaxFileTitle AS LONG ' Same as nMaxFile
lpstrInitialDir AS _OFFSET ' Starting directory
lpstrTitle AS _OFFSET ' Dialog title
flags AS LONG ' Dialog flags
nFileOffset AS INTEGER ' Zero-based offset from path beginning to file name string pointed to by lpstrFile
nFileExtension AS INTEGER ' Zero-based offset from path beginning to file extension string pointed to by lpstrFile.
lpstrDefExt AS _OFFSET ' Default/selected file extension
lCustData AS LONG
lpfnHook AS LONG
lpTemplateName AS _OFFSET
END TYPE
DECLARE DYNAMIC LIBRARY "comdlg32" ' Library declarations using _OFFSET types
FUNCTION GetOpenFileNameA& (DIALOGPARAMS AS FILEDIALOGTYPE) ' The Open file dialog
FUNCTION GetSaveFileNameA& (DIALOGPARAMS AS FILEDIALOGTYPE) ' The Save file dialog
END DECLARE
' Do the Open File dialog call!
Filter$ = "*.*"
Flags& = OFN_FILEMUSTEXIST + OFN_NOCHANGEDIR + OFN_READONLY ' add flag constants here
OFile$ = GetOpenFileName$(" ", ".\", Filter$, 1, Flags&, hWnd&)
IF OFile$ = "" THEN ' Display Open dialog results
PRINT "You must pick a file."
ELSE
END IF
filename$= OFile$
IF NOT _FILEEXISTS(filename$) THEN
PRINT filename$ + " " + "not found."
END
END IF
handle& = _NEWIMAGE(1024, 768, 32) '<===== The x/y size of my video
SCREEN handle&
DO UNTIL _SCREENEXISTS: _LIMIT 30: LOOP 'be sure screen exists before using in this way
title$ = "QB64 Video Player - " + filename$
_TITLE title$
hwnd& = FindWindow(0, title$ + CHR$(0))
ReturnString$ = SPACE$(255): ErrorString$ = SPACE$(255)
a% = mciSendStringA%("open " + filename$ + " style popup", ReturnString$, LEN(ReturnString$), 0)
IF a% THEN
x% = mciGetErrorStringA%(a%, ErrorString$, LEN(ErrorString$))
PRINT ErrorString$
END
ELSE
a2% = mciSendStringA%("window " + filename$ + " handle " + STR$(hwnd&), ReturnString$, LEN(ReturnString$), 0)
b% = mciSendStringA%("play " + filename$, "", 0, 0)
'=== Play video...
DO
_LIMIT 30
'you can add pause/resume routine here if you want...
LOOP UNTIL INKEY$ <> ""
x% = mciSendStringA%("stop " + filename$, "", 0, 0)
x% = mciSendStringA%("close " + filename$, "", 0, 0)
END IF