Author Topic: Errors running all examples in win-lib.  (Read 2750 times)

0 Members and 1 Guest are viewing this topic.

Offline catclaw

  • Newbie
  • Posts: 10
    • View Profile
Errors running all examples in win-lib.
« on: October 12, 2019, 06:17:55 pm »
Hi!

I was trying out different examples, looking for a solution to a problem, and I wanted to try some of the Windows-libraries.
Turns out that every example creates an error - sometimes not running or anything. (I tried even on a "clean" install, download, extract, run, paste, compile…)
The error output is:
"C++ Compilation failed  (Check .\internal\temp\compilefile.txt"

When I click on it, Notepad opens with this text:

In file included from qbx.cpp:2171:
..\\temp\\main.txt: In function 'void QBMAIN(void*)':
..\\temp\\main.txt:16:124: error: cast from 'HWND' {aka 'HWND__*'} to 'int' loses precision [-fpermissive]
 *__LONG_HWND=(  int32  )FindWindow(NULL,(char*)(qbs_add(qbs_new_txt_len("Color Common Dialog demo",24),func_chr( 0 )))->chr);
                                                                                                                            ^
compilation terminated due to -Wfatal-errors.

For the Color Dialog Box.
It's pretty much the same for rest.
I hope someone can fix that, because that how one learns to code in QB64.

Also - the IDE shows wrong characters for the last 3 Swedish letters åäö.

Thank you for your time and I hope it gets fixed.
I'd like to use the Open File Dialog, instead of writing my own - it would make it easier.

Cheers.

Cheers. ;)

Offline catclaw

  • Newbie
  • Posts: 10
    • View Profile
Re: Errors running all examples in win-lib.
« Reply #1 on: October 12, 2019, 06:26:43 pm »
Same thing with the built-in help examples.
None of them run.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Errors running all examples in win-lib.
« Reply #2 on: October 12, 2019, 07:34:34 pm »
I’d bet a dollar against a dime that you’ve download and using the 64-bit version of QB64.  ;)

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. 
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline catclaw

  • Newbie
  • Posts: 10
    • View Profile
Re: Errors running all examples in win-lib.
« Reply #3 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.  ;)

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.
Yes, I'm running x64, why?
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

« Last Edit: October 13, 2019, 09:38:51 am by catclaw »