Author Topic: Stumped by a compiler error -fpermissive when calling windows api  (Read 3875 times)

0 Members and 1 Guest are viewing this topic.

Offline blametroi

  • Newbie
  • Posts: 26
    • View Profile
Hi. I'm trying to call the FindFileExA API and I can't figure out how to make my code compile cleanly in QB64. I'm sure the answer will be one of those "oh, duh" things, but I'm new to QB64 and I'm probably not reading all the code correctly. I started with one of the Windows API examples on the Wiki and started adding to it. The included code gets the following error on my system:

Quote
In file included from qbx.cpp:2171:0:
..\\temp\\main.txt: In function 'void QBMAIN(void*)':
..\\temp\\main.txt:151:146: error: invalid conversion from 'int' to 'FINDEX_INFO_LEVELS {aka _FINDEX_INFO_LEVELS}' [-fpermissive]
compilation terminated due to -Wfatal-errors.

And the code:

Code: QB64: [Select]
  1. ' windows api testing, build a set of
  2. ' useful routines
  3. ' starting code is lifted from the qb64.org wiki to
  4. ' bootstrap the effort, then i'll add my own stuff.
  5. '
  6. ' txb 27 December 2018
  7.  
  8. ' use a cmd console window instead of a screen
  9.  
  10. ' Windows API constants
  11. CONST MAX_PATH = 260
  12.  
  13. ' FINDEX_INFO_LEVELS
  14. CONST FindExInfoStandard = 0&
  15. CONST FindExInfoBasic = 1&
  16.  
  17. ' FINDEX_SEARCH_OPS
  18. CONST FindExSearchNameMatch = 0&
  19. CONST FindExSearchLimitToDirectories = 1&
  20. CONST FindExSearchLimitToDevices = 2&
  21.  
  22. ' FILETIME
  23. TYPE FileTime
  24.     LowDateTime AS LONG
  25.     HighDateTime AS LONG
  26.  
  27. ' WIN32_FIND_DATA
  28. TYPE FindFileData
  29.     FileAttributes AS LONG
  30.     CreationTime AS FileTime
  31.     LastAccessTime AS FileTime
  32.     LastWriteTime AS FileTime
  33.     FileSizeHigh AS LONG
  34.     FileSizeLow AS LONG
  35.     reserved0 AS LONG
  36.     reserved1 AS LONG
  37.     FileName AS STRING * MAX_PATH
  38.     AlternateFileName AS STRING * 14
  39.     FileType AS LONG
  40.     CreatorType AS LONG
  41.     FinderFlags AS INTEGER
  42.  
  43. DECLARE LIBRARY 'Directory Information using KERNEL32 provided by Dav
  44.     FUNCTION WINDirectory ALIAS GetWindowsDirectoryA (lpBuffer AS STRING, BYVAL nSize AS LONG)
  45.     FUNCTION SYSDirectory ALIAS GetSystemDirectoryA (lpBuffer AS STRING, BYVAL nSize AS LONG)
  46.     FUNCTION CURDirectory ALIAS GetCurrentDirectoryA (BYVAL nBufferLen AS LONG, lpBuffer AS STRING)
  47.     FUNCTION TempPath ALIAS GetTempPathA (BYVAL nBufferLen AS LONG, lpBuffer AS STRING)
  48.     FUNCTION GetModuleFileNameA (BYVAL hModule AS LONG, lpFileName AS STRING, BYVAL nSize AS LONG)
  49.     FUNCTION FindFirstFileEx ALIAS FindFirstFileExA (lpFileName AS STRING, BYVAL fInfoLevelId AS LONG, lpFindFileData AS FindFileData, BYVAL fSearchOp AS LONG, BYVAL aNull AS LONG, BYVAL AdditionalFlags AS LONG)
  50.     FUNCTION FindClose (hFindFile AS LONG)
  51.  
  52. '=== SHOW WINDOWS DIRECTORY
  53. WinDir$ = SPACE$(144)
  54. Result = WINDirectory(WinDir$, LEN(WinDir$))
  55. IF Result THEN PRINT "WINDOWS DIRECTORY: "; LEFT$(WinDir$, Result)
  56.  
  57. '=== SHOW SYSTEM DIRECTORY
  58. SysDir$ = SPACE$(144)
  59. Result = SYSDirectory(SysDir$, LEN(SysDir$))
  60. IF Result THEN PRINT "SYSTEM DIRECTORY: "; LEFT$(SysDir$, Result)
  61.  
  62. '=== SHOW CURRENT DIRECTORY
  63. CurDir$ = SPACE$(255)
  64. Result = CURDirectory(LEN(CurDir$), CurDir$)
  65. IF Result THEN PRINT "CURRENT DIRECTORY: "; LEFT$(CurDir$, Result)
  66.  
  67. '=== SHOW TEMP DIRECTORY
  68. TempDir$ = SPACE$(100)
  69. Result = TempPath(LEN(TempDir$), TempDir$)
  70. IF Result THEN PRINT "TEMP DIRECTORY: "; LEFT$(TempDir$, Result)
  71.  
  72. '=== SHOW CURRENT PROGRAM
  73. FileName$ = SPACE$(256)
  74. Result = GetModuleFileNameA(0, FileName$, LEN(FileName$))
  75. IF Result THEN PRINT "CURRENT PROGRAM: "; LEFT$(FileName$, Result)
  76.  
  77. ' now try to find all the .bas files in this directory
  78. DIM hfind AS LONG
  79. DIM ffdata AS FindFileData
  80. DIM searchString AS STRING * MAX_PATH
  81. searchString = "*.bas"
  82.  
  83. hfind = FindFirstFileEx(searchString, FindExInfoStandard&, ffdata, 0, FindExSearchNameMatch, 0)
  84. IF hfind < 0 THEN
  85.     PRINT "find first failed"
  86.     PRINT "found ", ffdata.FileName
  87.     Result = FindClose(hfind)
  88.  
  89. ' and done
  90. SYSTEM 0 ' instead of END
  91.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Stumped by a compiler error -fpermissive when calling windows api
« Reply #1 on: December 27, 2018, 10:45:13 pm »
I just ran into the same error the other day.  My issue was trying to assign a LONG value to a 64-bit hwnd handle.  64-bit offsets are 8-bytes, and need to be defined as _INTEGER64 or else they overflow and don’t point to the proper place in memory.

You may try changing your  variable types and see if that corrects the issue for you.  (I’m not current at the PC and can’t test the theory.)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: Stumped by a compiler error -fpermissive when calling windows api
« Reply #2 on: December 27, 2018, 10:58:50 pm »
Instead of DECLARE LIBRARY try DECLARE CUSTOMTYPE LIBRARY.

Offline blametroi

  • Newbie
  • Posts: 26
    • View Profile
Re: Stumped by a compiler error -fpermissive when calling windows api
« Reply #3 on: December 28, 2018, 07:39:20 am »
Thanks guys.

Fillippe's suggestion gets me compiling and running. No intelligible output yet, but there's a start.

Steve, aren't my programs 32-bit when compiled? Why would I need an 8 byte handle?

EDIT: Using CustomType and changing the search string to include a trailing chr$(0) gets me results!

In testing I saw that only the FindFirstFileExA and FindClose need to be defined as CustomType. Indeed, using CustomType on the original calls broke that code and nothing intelligible was returned.

So, thanks again and I'm moving forward. Fun times.
« Last Edit: December 28, 2018, 07:54:22 am by blametroi »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Stumped by a compiler error -fpermissive when calling windows api
« Reply #4 on: December 29, 2018, 06:26:03 am »
Yeah a good land to explore...

A first philosophycal thinking:
It may be useful a tutorial both for Windows API both OtherOses API (Linux/MacOs)
or is the project that only Windows coder can do something more with QB64?

What experience and knowledge is needed to do this?

Programming isn't difficult, only it's  consuming time and coffee

Offline blametroi

  • Newbie
  • Posts: 26
    • View Profile
Re: Stumped by a compiler error -fpermissive when calling windows api
« Reply #5 on: December 29, 2018, 06:55:55 am »
A first philosophycal thinking:
It may be useful a tutorial both for Windows API both OtherOses API (Linux/MacOs)
or is the project that only Windows coder can do something more with QB64?

What experience and knowledge is needed to do this?

When getting into a new language/environment I have a few things I like to do. Hex dumps, directory lists, file copies, etc. I document my code along the way (see access violation calling FindNextFileA) so it might be useful as a tutorial or sample code at some point.

I know I could have called the shell to get a directory list as a text file, but I'm philosophically opposed to doing so :)

I only run in Windows these days, but I imagine the concepts will apply to Linux or OS X.

As far as experience/knowledge, someone needs to be able to understand a C header file and have a clear understanding of the difference between BY VALUE vs BY REFERENCE.