QB64.org Forum

Active Forums => Programs => Topic started by: SpriggsySpriggs on August 18, 2020, 01:34:50 pm

Title: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 18, 2020, 01:34:50 pm
This collection is now hosted on GitHub but will show updates to the package here as well.

This package contains API usage for REST (https://en.wikipedia.org/wiki/Representational_state_transfer), HTTP, HTTPS, WinAPI (https://docs.microsoft.com/en-us/windows/win32/apiindex/windows-api-list) (Shell32, User32, Kernel32, etc.), and Cross-platform C++ Libraries. Each one is unique in some way.

Inside the collection is:

Quote
REST, HTTP, HTTPS API using CURL, urlmon, _OPENCONNECTION (Windows)
Address Validation API (smartystreets.com)
Currency Exchange Rate API (exchangerate-api.com)
Profanity Check/Censor API (purgomalum.com)
Phone Number Verification API (apilayer.com)
Insult Generator API (evilinsult.com)
Sentiment API (sentimapi)
Breaking News API (newsapi.org)
Kitten Image Replacer API (placekitten)
Image from Hash API (robohash)
Screenshot of Webpage API (screenshotlayer.com)
NASA Astronomy Pic of the Day API (nasa.gov) Updated 08/20/2020 Updated with source I had posted elsewhere. Much more efficient code.
DCUO Census API (daybreakcensus)
Online Movie Database API (omdb) Updated 10/18/2020 (Using Wininet WinAPI for internet connectivity)
Lyrics API (lyrics.ovh)
Weather API using GeoLocation from IP Address (various API vendors) Added 08/18/20 since it was missing from collection
Owlbot Dictionary API Added 08/19/2020
Genderize API Added 09/20/2020
QR Tag API Added 09/20/2020
Gravatar Image from email address hash API (gravatar, wordpress) Updated 10/18/2020 (Using Wininet WinAPI for internet connectivity)

WinAPI Libraries (Windows)
UuidCreate, UuidCreateSequential, UuidHash (rpcrt4, Wininet) UUID Creation and MAC Address Lookup (uuidtools and macvendors.com) Updated 10/17/2020
SHFileOperation (Shell32) Added 09/22/2020
GetComputerName, GetUsername (Kernel32 , Advapi32) Added 09/22/2020
FindExecutableA (Shell32) Added 09/26/2020
ShellAboutA (Shell32) Added 09/26/2020
mciSendStringA (WINMM) Record and playback audio (updated source with ffmpeg waveform drawing.) Added 09/26/2020
DoEnvironmentSubstA, GetEnvironmentVariableA, ExpandEnvironmentStringsA (Shell32) (Works similarly to ENVIRON$ but with some extra functionality and speed. Added 09/26/2020
ExractIcon, DrawIcon (Shell32 , User32) Added 09/27/2020
SetWindowPos, GetForegroundWindow (User32) Credit to Pete and visionmercer, original post here (https://www.qb64.org/forum/index.php?topic=1365.msg105588#msg105588) Added 09/27/2020
AnimateWindow (User32) Added 09/30/2020
FlashWindow/FlashWindowEx (User32) Added 10/02/2020
capCreateCaptureWindow (Avicap32) Records webcam footage to AVI file Added 10/02/2020
OpenProcess, TerminateProcess (Kernel32) Kill process by name or PID Added 10/05/2020
MessageBeep (User32) Plays WAV audio for common message sounds Added 10/05/2020
OpenClipboard, GetClipboardData (User32) Added 10/07/2020
GetBinaryType (Kernel32) Added 10/09/2020
GetTempPath, GetTempFileName (Kernel32) Added 10/09/2020
GetDateFormat, GetCurrencyFormat (Kernel32) Added 10/09/2020
OpenProcess, ReadProcessMemory, WriteProcessMemory (Kernel32) Complete rewrite 02/17/21 (Peeping Tom, a powerful PEEK/POKE library for QB64)
XInputGetState, XInputSetState, XInputGetBatteryInformation (Xinput1_4) Tests an XInput enabled controller Added 10/26/2020
(Wininet) Various Wininet FTP functions for uploading, downloading, directory listing, etc. Added 11/17/2020
SHOpenWithDialog (Shell32) Invokes the "Open With" dialog in Windows Added 02/06/2021

Cross-Platform Libraries (Windows, Macintosh, and Linux)
pipecom $INCLUDE file that pipes console output to QB64. Win (using WinAPI), Mac, and Linux (using C libraries).Added 02/12/2021
encodeBase64, decodeBase64 (Crypt32, base64 (Linux and Mac)) Added 11/05/2020
mapvar, getmappedvalue (mappedvar) Header file that creates variables mapped to strings. Added 12/20/2020
(preproc) Header file that allows for usage of multiple preprocessor macros available to us in C++. Added 12/23/2020

Miscellaneous APIs / Libraries
hid_read, hid_write (hidapi) Provides HID access to devices over Bluetooth and USB connection (Windows) Test source for interfacing with Nintendo Switch Pro Controller over Bluetooth HID. Added 12/07/2020.

https://github.com/SpriggsySpriggs/Spriggsys-API-Collection (https://github.com/SpriggsySpriggs/Spriggsys-API-Collection)

Link (https://mega.nz/file/Tn42gbRK#70zC0etdyZZc6u0QRNrvGGbVowwZn-Bo-oLWJv6AU-c) to a 7zip folder containing just ffmpeg for the mciSendStringA waveform functionality

Note: All libraries with the exception of the Cross Platform libraries are written on and for Windows 10 64 bit (and should also work with 32 bit). Now that I am using WSL2 (Windows Subsystem for Linux) I am also developing libraries for Linux. See here (https://www.qb64.org/forum/index.php?topic=3152.msg124219#msg124219) for a post about installing WSL2 on Windows 10 to use Linux on your machine.

Enjoy
Title: Re: Spriggsy's API Collection
Post by: bplus on August 18, 2020, 03:56:11 pm
Good to see these in single package.

One of these days (yeah sure, well maybe) I hope to sit down and see how you put these together generally.

It's smart to use Windows resources, that makes you resourceful! ;-)
Title: Re: Spriggsy's API Collection
Post by: bplus on August 18, 2020, 09:15:36 pm
Walter, it's nice to hear from you again!
Title: Re: Spriggsy's API Collection
Post by: FellippeHeitor on August 18, 2020, 09:35:26 pm
Daniel Dionne who goes online by [banned user], among other nicknames, has made public death threats to me and even gone on to mention my family and child in hate messages sent via several platforms.

All because he was denied the right to break our terms of service. Which we then gave up in his case because of the annoyance.

He was not welcome anymore for disrespectful behavior and he is now forever not welcome anymore due to the death threats. I have not taken it to authorities yet, especially given his personal condition and physical location. I'm keeping the records though.

Mentioning him won't be tolerated any longer. Defending him on our platform is not welcome.

Anyone else from the list of haters Walter mentions, himself included, are welcome to express themselves elsewhere.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 18, 2020, 09:41:30 pm
Updated source code for OMDB API with scratch made HTTP GET statement. Works much faster than urlmon and would allow for compatibility with Linux (except for the image download, which uses HTTPS and so requires urlmon)
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 18, 2020, 10:17:29 pm
@[banned user] , I'd rather you promote this other language and server in "Off-Topic" so it doesn't muddle up this thread.
Title: Re: Spriggsy's API Collection
Post by: bplus on August 18, 2020, 10:44:59 pm
@SpriggsySpriggs

Is there one of these that is most general or best to start a study of?
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 18, 2020, 10:53:28 pm
Updated 08/18/20 with source code for Weather API using Geolocation from IP address.
Title: Re: Spriggsy's API Collection
Post by: bplus on August 18, 2020, 10:59:05 pm
@SpriggsySpriggs

Well I just tried NASA pic of day and it seems to hang on a big black screen.

Have you checked the code from the package? Why are all the bas files double titled with - Merged.BAS?
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 18, 2020, 10:59:58 pm
Is there one of these that is most general or best to start a study of?
@bplus I'd take a look at the weather API. It uses several different API endpoints. I'll have to eventually update it with my JSON parsing functions but for a starter it should be good. Gives a nice look at how each one is slightly different and how I make them work together. I'd also recommend you look at the OMDB API and News API so you can see how I use my JSON parsing functions to read the responses. The OMDB API uses both a scratch made GET statement using OPENCLIENT and urlmon to download the image response so check that out for doing HTTP (HTTP only in scratch made GET. HTTPS can be used in urlmon and CURL) GET statements. Sentim API uses CURL to pass custom headers so check that one out for HTTPS that uses custom headers.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 18, 2020, 11:04:33 pm
@SpriggsySpriggs

Well I just tried NASA pic of day and it seems to hang on a big black screen.

Have you checked the code from the package? Why are all the bas files double titled with - Merged.BAS?
@bplus Nothing is missing in the package. The issue isn't from my code, it's because they (NASA) run on UTC time so they are in the next day. When the API requests "today's" image it is actually going to be using tomorrow's date since in UTC time right now it is 3 AM tomorrow and the picture for tomorrow doesn't exist yet. Run it in the morning (I'd say no earlier than 6 AM) and you will see an image. Something might be amiss with my API key. It could be expired for non-usage. I'll have to check. As for the Merged part of each source code's title, I mentioned in the original post I used Source Merger to grab all my $INCLUDEs so as to not have any dependencies missing and I didn't change the file names so I remember that I did already merge them and to keep doing so.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 19, 2020, 10:58:36 am
@bplus I found the issue. It isn't necessarily my code or my API key. It's because they didn't have an image in the JSON response. They just had a youtube link. There was no image to load. Last night it was because it was UTC time. Today it is because they didn't respond with an image. Nothing I can do about it. I assumed they would always have an image link.
Title: Re: Spriggsy's API Collection
Post by: bplus on August 19, 2020, 11:06:30 am
Yes, thanks all the others I tried worked. Figures I pick the one that doesn't to start with. EDIT: Don't mean to imply it's on Spriggys end with his code. NASA? another government agency who only works under very certain conditions, you would think Pic of the Day would be posted all day or until they come back from holiday and had another one to replace it. :)

If you filter the Insult app through the Profanity app, it would have nothing to say ;-))

Man the terminology is like from a different world and language. But time to try something new, for me, now that I have String Math mostly off my bucket list.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 19, 2020, 11:27:58 am
@bplus I was wracking my brain last night trying to figure out where the issue was and immediately assumed it was because of UTC time which at the moment it was. Then when I tried it this morning and it still didn't work I compared the merged version with my original one and nothing was different. Ran both, no picture. Then I commented out the file deletion and looked at the response and saw that they were using a video link. I don't get why they would say Pic of the Day but use a video instead. They could have at least put some kind of picture in the response. Oh well. And I wasn't insulted or anything I was just trying to narrow down where the issue came from. I need to eventually hunt down who it was who wrote the Source Merger code because I can't remember who made it. I was going to make an InForm version of it and give credit to them for the original source. I need to search the forums.
Title: Re: Spriggsy's API Collection
Post by: bplus on August 19, 2020, 11:35:29 am
Speaking of the bucket list there was a very old item about looking up words or subjects in dictionaries or encyclopedia's as a core part to some Sci Fi master AI App that could demonstrate the appearance of understanding of human text.

I guess IBM beat me to it with Watson but something in Basic beyond ELIZA of 50 years ago would be cool.

Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 19, 2020, 11:38:55 am
There is a public API for one of the well-known encyclopedias/dictionaries. I might look into that. It could be an interesting project.
Title: Re: Spriggsy's API Collection
Post by: Dav on August 19, 2020, 12:18:46 pm
Lol at "If you're API and you know it clap your hands". :)

- Dav
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 19, 2020, 06:40:04 pm
Updated collection with Owlbot Dictionary API on 08/19/2020 at 6:37 PM. The API works very similar to the OMDB API in that I have a console window to display some info from the JSON response and a regular screen to show the image from the response. Below is a screenshot of the new API working:

 
Title: Re: Spriggsy's API Collection
Post by: bplus on August 20, 2020, 03:23:43 pm
Now that I can get a pic from NASA, I worked on a better display of the description and image:
Code: QB64: [Select]
  1. _TITLE "NASA Pic of the Day, spacebar to toggle between image and description" ' b+ mod of Spriggsy's code
  2. DIM fl&, fr&, i&, d&, picTitle$, description$, toggle, k$, lp, scalePic
  3. DIM nlines, lineLength, yStart, startPlace, endPlace, markPlace, xoff, yoff, poff
  4. _DELAY .25
  5. PRINT "One moment please, accessing and assembling data for NASA picture of the day."
  6. i& = NASApod
  7. IF i& <> 0 THEN
  8.     fl& = _LOADFONT(ENVIRON$("SYSTEMROOT") + "\Fonts\bahnschrift.ttf", 40)
  9.     fr& = _LOADFONT(ENVIRON$("SYSTEMROOT") + "\Fonts\bahnschrift.ttf", 20)
  10.     _ICON i&
  11.     d& = _NEWIMAGE(_WIDTH, _HEIGHT, 32)
  12.     _DEST d&
  13.     COLOR , &H00000000 ' clear background
  14.     _FONT fr&
  15.     lineLength = _WIDTH - 2 * .1 * _WIDTH
  16.     nlines = _PRINTWIDTH(description$) / lineLength + 2
  17.     yStart = (_HEIGHT - _FONTHEIGHT(fr&) * nlines) / 2
  18.     startPlace = 1: endPlace = startPlace + 1
  19.     FOR lp = 0 TO nlines
  20.         WHILE _PRINTWIDTH(MID$(description$, startPlace, endPlace - startPlace + 1)) < lineLength
  21.             endPlace = endPlace + 1
  22.             IF endPlace > LEN(description$) THEN endPlace = LEN(description$): EXIT WHILE
  23.         WEND
  24.         markPlace = endPlace
  25.         WHILE MID$(description$, endPlace, 1) <> " "
  26.             endPlace = endPlace - 1
  27.             IF endPlace <= startPlace THEN endPlace = markPlace: EXIT WHILE
  28.         WEND
  29.         poff = .1 * _WIDTH + (lineLength - _PRINTWIDTH(MID$(description$, startPlace, endPlace - startPlace + 1))) / 2
  30.         _PRINTSTRING (poff, yStart + _FONTHEIGHT(fr&) * lp), MID$(description$, startPlace, endPlace - startPlace + 1)
  31.         startPlace = endPlace + 1
  32.         endPlace = startPlace + 2
  33.         IF endPlace > LEN(description$) THEN EXIT FOR
  34.     NEXT
  35.     _FONT fl&
  36.     _PRINTSTRING ((_WIDTH - _PRINTWIDTH(picTitle$)) / 2, 50), picTitle$
  37.  
  38.     _DEST 0 ' OK show time
  39.     IF _WIDTH / _WIDTH(i&) < _HEIGHT / _HEIGHT(i&) THEN
  40.         scalePic = _WIDTH / _WIDTH(i&)
  41.         yoff = (_HEIGHT - scalePic * _HEIGHT(i&)) / 2
  42.     ELSE
  43.         scalePic = _HEIGHT / _HEIGHT(i&)
  44.         xoff = (_WIDTH - scalePic * _WIDTH(i&)) / 2
  45.     END IF
  46.     DO
  47.         COLOR , &HFF000000: CLS
  48.         k$ = INKEY$
  49.         IF k$ = " " THEN toggle = 1 - toggle
  50.         IF toggle THEN
  51.             _PUTIMAGE (xoff, yoff)-STEP(scalePic * _WIDTH(i&), scalePic * _HEIGHT(i&)), i&, 0
  52.         ELSE
  53.             _PUTIMAGE , d&, 0
  54.         END IF
  55.         _DISPLAY
  56.         _LIMIT 60
  57.     LOOP UNTIL _KEYDOWN(27)
  58.     PRINT "Sorry no pic available now. Press any..."
  59.     SLEEP: END
  60.  
  61. FUNCTION NASApod&
  62.     DIM URL AS STRING
  63.     DIM URLFile AS STRING
  64.     DIM nasapic AS STRING
  65.     DIM nasarequest AS STRING
  66.     SHARED picTitle AS STRING
  67.     SHARED description AS STRING
  68.     DIM a%
  69.     URLFile = "nasapod.json"
  70.     URL = "https://api.nasa.gov/planetary/apod?api_key=w8uuw4gfVqpcnaTI3g02zJizTgtOaXJtaAmASebV"
  71.     a% = API_request(URL, URLFile)
  72.     DIM U AS INTEGER
  73.     U = FREEFILE
  74.     OPEN URLFile FOR BINARY AS #U
  75.     IF LOF(U) <> 0 THEN
  76.         nasarequest = SPACE$(LOF(U))
  77.         GET #U, , nasarequest
  78.     ELSE
  79.         CLOSE #U
  80.         KILL URLFile
  81.         NASApod = 0
  82.         EXIT FUNCTION
  83.     END IF
  84.     CLOSE #U
  85.     KILL URLFile
  86.     picTitle = GetKey("title", nasarequest)
  87.     description = GetKey("explanation", nasarequest)
  88.     nasapic = GetKey("hdurl", nasarequest)
  89.     URLFile = "nasapod.jpg"
  90.     URL = nasapic
  91.     a% = API_request(URL, URLFile)
  92.     OPEN URLFile FOR BINARY AS #U
  93.     IF LOF(U) <> 0 THEN
  94.         NASApod = _LOADIMAGE(URLFile, 32)
  95.     ELSE
  96.         CLOSE #U
  97.         KILL URLFile
  98.         NASApod = 0
  99.     END IF
  100.     CLOSE #U
  101.     KILL URLFile
  102.     FUNCTION URLDownloadToFileA (BYVAL pCaller AS LONG, szURL AS STRING, szFileName AS STRING, BYVAL dwReserved AS LONG, BYVAL lpfnCB AS LONG)
  103. FUNCTION API_request (URL AS STRING, File AS STRING)
  104.     API_request = URLDownloadToFileA(0, URL + CHR$(0), File + CHR$(0), 0, 0)
  105. FUNCTION GetKey$ (keyname AS STRING, JSON AS STRING)
  106.     DIM jkey AS STRING
  107.     jkey = JSON
  108.     IF INSTR(jkey, CHR$(34) + keyname + CHR$(34)) THEN
  109.         jkey = MID$(jkey, INSTR(jkey, CHR$(34) + keyname + CHR$(34)) + LEN(keyname))
  110.         jkey = MID$(jkey, INSTR(jkey, ":") + 1)
  111.         jkey = String.Replace(jkey, "\" + CHR$(34), "'")
  112.         IF MID$(jkey, 1, 1) = CHR$(34) THEN
  113.             jkey = MID$(jkey, 2)
  114.         END IF
  115.         jkey = MID$(jkey, 1, INSTR(jkey, CHR$(34)) - 1)
  116.         IF RIGHT$(jkey, 1) = "," THEN
  117.             jkey = MID$(jkey, 1, LEN(jkey) - 1)
  118.         END IF
  119.     ELSE
  120.         GetKey = ""
  121.     END IF
  122.     GetKey = jkey
  123. SUB GetAllKey (keyname AS STRING, JSON AS STRING, ParseKey() AS STRING)
  124.     DIM unchangejson AS STRING
  125.     DIM jkey AS STRING
  126.     DIM x
  127.     unchangejson = JSON
  128.     DO
  129.         IF INSTR(unchangejson, CHR$(34) + keyname + CHR$(34)) THEN
  130.             x = x + 1
  131.             REDIM _PRESERVE ParseKey(x) AS STRING
  132.             unchangejson = MID$(unchangejson, INSTR(unchangejson, CHR$(34) + keyname + CHR$(34)) + LEN(keyname))
  133.             jkey = unchangejson
  134.             jkey = MID$(jkey, INSTR(jkey, ":") + 1)
  135.             jkey = String.Replace(jkey, "\" + CHR$(34), "'")
  136.             IF MID$(jkey, 1, 1) = CHR$(34) THEN
  137.                 jkey = MID$(jkey, 2)
  138.             END IF
  139.             jkey = MID$(jkey, 1, INSTR(jkey, CHR$(34)) - 1)
  140.             IF RIGHT$(jkey, 1) = "," THEN
  141.                 jkey = MID$(jkey, 1, LEN(jkey) - 1)
  142.             END IF
  143.             ParseKey(x) = jkey
  144.         END IF
  145.     LOOP UNTIL INSTR(unchangejson, CHR$(34) + keyname + CHR$(34)) = 0
  146. FUNCTION String.Replace$ (a AS STRING, b AS STRING, c AS STRING)
  147.     DIM j
  148.     DIM r$
  149.     j = INSTR(a, b)
  150.     IF j > 0 THEN
  151.         r$ = LEFT$(a, j - 1) + c + String.Replace(RIGHT$(a, LEN(a) - j + 1 - LEN(b)), b, c)
  152.     ELSE
  153.         r$ = a
  154.     END IF
  155.     String.Replace = r$
  156.  

Only one sample to work with, tomorrow this code could be rubbish ;-))
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 20, 2020, 06:14:24 pm
That's pretty neat, @bplus ! I like the formatting of the text! What an excellent picture for today, too!
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 20, 2020, 10:40:44 pm
Updated NASA Picture of the Day API with source code I had posted elsewhere in the forum. Much better code. Uses the date to get the day's picture so you don't have to worry about the picture possibly being not there yet (but doesn't fix the issue of if they don't even put a picture link in the JSON response). Can be used as a screensaver by building the EXE and changing the extension to SCR, right-clicking it, and pressing install. Works pretty well. If left running, it updates automatically at 5 AM local. (I used it myself on my work computer as my screensaver. Was pretty neat. I could come in every day and see a new image on my desktop.) @bplus , I think your modification would be good to merge with this different version of my NASA Pic of the day. I will look at your code and mine and modify them to make one source and then update the source in the zip folder.
Title: Re: Spriggsy's API Collection
Post by: loudar on August 28, 2020, 08:19:21 am
I have just now realized how beautiful bahnschrift can look! Really cool stuff.
Title: Re: Spriggsy's API Collection
Post by: bplus on August 28, 2020, 12:54:18 pm
"The Valley of Orion" really cool today!
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 29, 2020, 11:56:06 pm
@bplus Yes, very beautiful! Today's is quite nice as well!
@loudar Yeah, I was just browsing the Fonts folder and happened upon it. Was wanting something that looked nice and smooth.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 05, 2020, 05:29:16 pm
Will try to update this soon. Been busy with looking for a job and other things.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 20, 2020, 09:13:23 pm
Updated 09:11 PM 09/20/2020. Added Genderize API which checks probability of gender of name based on two letter country ID entered. The test code I have only returns back either male or female. You can comment out the KILL command in the API_request function to see the full JSON response which has also the probability either way.

bUt iT's 2020!1!111!!!!!
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 20, 2020, 09:32:36 pm
Updated 09:31 PM with QR Tag API which takes a URL and generates a QR code that will take you to the website you provide.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 22, 2020, 07:52:12 pm
09/22/2020 Added SHFileOperationA functions from WinAPI. The example program allows to delete a file to recycle bin rather than permanently.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 22, 2020, 11:01:43 pm
11:00 PM 09/22/2020 Updated my source for the SHFileOperationA WinAPI with the rest of the functionality in that set. It can now Copy, Move, Rename, and Recycle (all with confirmation dialogs, if the criteria is met).
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 22, 2020, 11:08:30 pm
11:06 09/22/2020 Added Kernel32 and Advapi32 WinAPI usage for getting computer name and username. Works in 32 bit AND 64 bit.

11:33 PM 09/22/2020 Added Shell32 function to SHFileOperation WinAPI code which allows you to empty the recycle bin with confirmation. Even though it isn't SHFileOperation, it is still part of the same DLL and since it has something to do with the recycle bin I felt it was appropriate to add it to that one in particular.

1:33 AM 09/23/2020 Added Shell32 function SHQueryRecycleBin to the SHFileOperation WinAPI code which queries the Recycle Bin and shows how many files are contained in it and how much space the bin is currently occupying on disk.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 25, 2020, 04:54:52 pm
Updated 09/25/2020 at 4:54 PM

Added Gravatar profile picture from email hash API to zip. Program uses MD5 library from @RhoSigma
Attached is a screenshot from the program showing my Gravatar picture:

Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 25, 2020, 11:53:04 pm
Updated 11:50 PM on 09/26/2020

Added FindExecutableA from Shell32 WinAPI to zip folder. This allows you to find whatever program is set in the registry as being the default for opening the file that is passed to the function. For instance, if you pass it a BAS file and you have QB64 set as the default, it returns the path to the executable for QB64. Here is a screenshot of the program showing me the path to my QB64 executable after passing it a BM file:

 
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 26, 2020, 12:10:38 am
Updated 12:08 PM on 09/26/2020

Added ShellAboutA from Shell32 WinAPI to zip. This function allows you to have a custom about page pop up in a program. This isn't an about page like you find in most programs. This gives a little information about the Windows license and allows for a custom title and description. Nothing too fancy.

Screenshot:
 [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Spriggsy's API Collection
Post by: badger on September 26, 2020, 01:09:24 pm
Hello

I will take a look at these.

I would like to ask if you ever heart if a dos database manager call btrieve. It use be owned by novel but now it has grown into a sql/btrieve type think that is awful exspensive. I was wondering if you would like to take on the challenge of maybe doing something like this. It gave quick basic 4.5 4 million record capibility. I know sql is the thing but i dont like sql so just thought i would ask.

Badger
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 26, 2020, 09:53:01 pm
Updated 09/26/2020 at 09:50 PM

Added mciSendStringA function from WINMM WinAPI with source code showing the ability to record and playback audio. This code records from the default microphone. Once you press any key while it is recording it plays back the audio it heard.

Attached is a recording a made with the program:
    
And a screenshot of the program in action:
 


Also, I've renamed the files inside the zip folder so they have a better nomenclature.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 26, 2020, 11:46:55 pm
Updated 09/26/2020 at 11:43 PM

Added DoEnvironmentSubstA function from Shell32 WinAPI. This performs nearly the same task as ENVIRON$ which is built into QB64 but allows for quicker return of the variables as well as the ability to call more than one at a time in the same line. For instance:
Code: QB64: [Select]
  1. PRINT Env("%homepath% %allusersprofile% %username%")

It works roughly twice as fast as the built-in ENVIRON$ function. This is included in my zip as a demo with a file containing some sample variable names for the test. It's mostly being added as a demo to show API usage rather than me telling you to start using this rather than the built-in. Personally, I will use the code that I wrote just because I like the flexibility.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 27, 2020, 12:26:06 am
Updated 12:24 AM on 09/27/2020

Added ExtractIcon from Shell32 WinAPI & DrawIcon and DestroyIcon from User32 WinAPI. This source shows extracting the handle for an icon from a program, loading it, and displaying it on the screen. Unfortunately, there appears to be a display issue so in order to keep the icon visible I have to loop the DrawIcon at about 120 FPS. Not sure what causes this but if someone wishes to dive into it then they may do so.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 27, 2020, 01:07:27 am
Updated 1:06 AM on 09/27/2020

Added SetWindowPos and GetForegroundWindow from User32 WinAPI, courtesy of Pete and visionmercer. Original post here:https://www.qb64.org/forum/index.php?topic=1365.msg105588#msg105588 (https://www.qb64.org/forum/index.php?topic=1365.msg105588#msg105588)

This function allows the running program to be the topmost program even when clicking elsewhere on the screen.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 27, 2020, 01:31:31 am
Added source to show a waveform of the recording made with mciSendStringA. It uses ffmpeg to show a waveform from the wav file that is created. Here is a screenshot of a waveform I made from a recording:

 
.

Updated 09/27/2020 Had a bug in my code for mciSendStringA for the waveform creation. Bug is now fixed.

Updated (once again) 09/27/2020 Made subs and functions and allowed for STEREO recording in a much higher quality!!!!!
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on September 30, 2020, 01:12:33 am
Updated 01:11 AM on 09/30/2020

Added AnimateWindow function which allows you to Fade in and fade out as well as wipe left and right. Works in 64 and 32 bit. Have fun with animated windows!
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 02, 2020, 02:59:41 am
Updated 02:57 AM on 10/02/2020

Added FlashWindow/FlashWindowEx functions from User32 WinAPI. This allows you to flash the taskbar icon for your program. This only works when the program does not have the foreground focus. Useful for getting the user's attention back to your program window. Here is a screenshot showing the taskbar flashing:

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
It might not seem like much but it's one more WinAPI thing that can be included :)
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 02, 2020, 11:07:22 pm
Updated 10/02/2020 at 11:03 PM

Added capCreateCaptureWindow from Avicap32 which allows you to open your webcam driver and record a video! Recording is stopped by making the program either lose focus or pressing the ESCAPE key. Can be played back using my modified version of code by @Dav below:

Here are some YouTube videos showing videos I recorded with the code I posted in my collection:

Recorded using my ElGato capture card from my PS4!

Recorded using a VIRTUAL WEBCAM through my code!

Just footage from my webcam


My version of Dav's code for playing AVI videos:
Code: QB64: [Select]
  1.     FUNCTION mciSendStringA% (lpstrCommand AS STRING, lpstrReturnString AS STRING, BYVAL uReturnLength AS INTEGER, BYVAL hwndCallback AS INTEGER)
  2.     ' mciSendStringA function plays media files and returns the following:
  3.     ' 0 = command sucessful
  4.     ' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  5.     ' lpstrCommand is the MCI command string (and optional flags) to send.
  6.     ' lpstrReturnString is a string that holds any return information.
  7.     ' uReturnLength is the length of the lpstrReturnString string passed.
  8.     ' NOTE: If lpstrCommand given doesn't retun a value then lpstrReturnString
  9.     '       can be empty and uReturnLength can be set to 0.
  10.     ' hwndCallback contains a callback window handle (only if the Notify flag used in lpstrCommand)
  11.     '====================================================================
  12.     FUNCTION mciGetErrorStringA% (BYVAL dwError AS INTEGER, lpstrBuffer AS STRING, BYVAL uLength AS INTEGER)
  13.     ' mciGetErrorStringA returns error info if the mciSendStringA failed.
  14.     ' dwError is the return value from the mciSendString function.
  15.     ' lpstrBuffer string holds the error information returned by the function.
  16.     ' uLength is the length of the lpstrBuffer string buffer.
  17.     '====================================================================
  18.  
  19. 'DECLARE CUSTOMTYPE LIBRARY
  20. '    FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$)
  21. 'END DECLARE
  22.  
  23.  
  24. handle& = _NEWIMAGE(640, 480, 32)
  25. SCREEN handle&
  26.  
  27.  
  28. _TITLE "QB64 Video"
  29. hwnd& = _WINDOWHANDLE 'FindWindow(0, "QB64 Video" + CHR$(0))
  30.  
  31. ReturnString$ = SPACE$(255)
  32. ErrorString$ = SPACE$(255)
  33. filename$ = "Video.avi" '<========== video file to play
  34.  
  35. a% = mciSendStringA%("open " + filename$ + " parent " + _TRIM$(STR$(_WINDOWHANDLE)) + " style child", ReturnString$, LEN(ReturnString$), 0)
  36.  
  37. IF a% THEN
  38.     x% = mciGetErrorStringA%(a%, ErrorString$, LEN(ErrorString$))
  39.     PRINT ErrorString$
  40.     END
  41.     a2% = mciSendStringA%("window " + filename$ + " handle " + STR$(hwnd&), ReturnString$, LEN(ReturnString$), 0)
  42.     b% = mciSendStringA%("play " + filename$, "", 0, 0)
  43.     '=== Play video...
  44.     DO: _LIMIT 30: LOOP UNTIL INKEY$ <> ""
  45.  
  46.     x% = mciSendStringA%("stop " + filename$, "", 0, 0)
  47.     x% = mciSendStringA%("close " + filename$, "", 0, 0)
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 05, 2020, 02:17:00 am
Updated 02:11 AM on 10/05/2020

Added OpenProcess, TerminateProcess, Process32First, Process32Next, and CreateToolhelp32Snapshot functions from Kernel32 WinAPI. This set of functions allow for you to kill running processes by name or PID (process ID). These functions kill the program outright, similar to using Task Manager so the programs DO NOT close gracefully. It's useful for killing a rogue SHELL _DONTWAIT. However, if you want something to be closed gracefully then you should use the SendSignal executable which I have included in my folder with a SUB that I use to call it. It sends a quit signal to a running process and allows for it to close correctly without worry of corrupting files. I've included 3 functions in my source code that you can use for your own code. KillProcessByName, which accepts a STRING of the processname, KillProcessByPID, which accepts an _UNSIGNED INTEGER of the PID, and SoftKill, which accepts a STRING of the processname.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 05, 2020, 02:41:32 am
Updated 02:40 AM on 10/05/2020

Added MessageBeep function from User32 which plays WAV audio for each of the standard Windows message sounds.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 07, 2020, 01:48:06 am
Updated 01:45 AM on 10/07/2020

Added OpenClipboard and GetClipboard functions from User32. Program is basically a rewrite of what is going on behind the scenes with var$ = _CLIPBOARD$. Uses PeekPoke library from the Wiki found here: https://www.qb64.org/wiki/PEEK_and_POKE_Library (https://www.qb64.org/wiki/PEEK_and_POKE_Library)
Also, added more functions to DoEnvironmentSubstA API for speed comparison between each of the different functions that achieve the same end result (if used the same way).

Added InternetOpenA, InternetConnect, FtpGetFile from Wininet. Will add code for HttpOpenRequest and HttpSendRequest in the future. Code will revamp all my online APIs to be more advanced.
Title: Re: Spriggsy's API Collection
Post by: Dav on October 08, 2020, 10:58:55 am
Nice collection you have going here!

- Dav
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 08, 2020, 11:07:42 am
Appreciate it, @Dav !
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 09, 2020, 01:10:39 am
Updated 01:09 AM on 10/09 AM

Added GetBinaryType from Kernel32. This inspects a binary executable file and returns what type it is; 32, 64, MS-DOS, etc.

Updated 01:54 AM on 10:09 AM

Added GetTempPath and GetTempFileName from Kernel32 which can be used to get a temp folder and filename for files in your applications.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 09, 2020, 08:48:59 pm
Updated 08:47 PM on 10/09/2020

Added GetDateFormat and GetCurrencyFormat from Kernel32. Here is a screenshot showing a sample output:

 


And the usage:

Code: QB64: [Select]
  1. PRINT Currency("123456789")
  2. PRINT FormatDate("MM*dd*yyyy")
  3. PRINT GetDateType(DATE_LONGDATE)

The above code for Currency spits out a formatted monetary value based on the current user's preferences.The number used in my example should return formatted with the local currency you use.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 10, 2020, 12:25:33 pm
Updated 12:20 PM on 10/10/2020

Fixed a bug with the UuidCreate timestamp functions. The function only looked for months either greater than or less than 10 (October). Now it is fixed for months INCLUDING October.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 14, 2020, 12:58:50 am
Soon to be adding advanced WinAPI usage demonstrating creating trainers in QB64. I hope to also create an actual tutorial for start to finish with making the trainer. It will take a lot of personal time and right now I'm trying to find a job. When I find time throughout the day here and there I will attempt to make progress on that.
Title: Re: Spriggsy's API Collection
Post by: bplus on October 14, 2020, 12:51:17 pm
What's a "trainer"? Some difference from a tutorial? (besides spelling)

BTW I believe what you do productively in your spare time is great sign what kind of job you should be pursuing.

If you can train people who are free to come and go and aren't invested only for a letter grade, then I think that also an awesome sign.

Maybe you can use this on your resume? Best wishes...
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 14, 2020, 12:54:19 pm
What's a "trainer"? Some difference from a tutorial? (besides spelling)
@bplus A trainer is a program that modifies the memory of a game to allow for things like adjusting your health, ammo, etc. I will be making a tutorial to show how to make your own trainers, though.
Title: Re: Spriggsy's API Collection
Post by: bplus on October 14, 2020, 01:01:42 pm
@SpriggsySpriggs

Man you have such a different background of terminology and experience from mine. I am glad you haunt this place, if I could only understand what you say better :)

For me if I wanted to improve my weapons and my vitality in a game I'd just hack the data files my stuff is being stored in.

I think in my day it was called cheating but Trump would say, no, just taking advantage of opportunity presented. :)
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 14, 2020, 02:50:39 pm
@bplus It's positivity like yours that keeps me coming back to the forum with more projects.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 16, 2020, 11:41:43 pm
Updated 10/16/2020 at 11:39 PM

Added OpenProcess, ReadProcessMemory, and WriteProcessMemory from Kernel32 WinAPI under filename "PeepingTom.bas". This library allows you to do modern PEEK-ing and POKE-ing in modern QB64.

Dedicated thread here: https://www.qb64.org/forum/index.php?topic=3134.0 (https://www.qb64.org/forum/index.php?topic=3134.0)

Updated 10/17/2020
Fixed peekstring function so it doesn't just call peekbyte repeatedly and grabs the whole string in one go.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 17, 2020, 10:59:19 pm
Updated 10/17/2020

Replaced some functions in the UUID code for better HTTPS functionality. More lines of code, but no more file creation to read back responses. Faster work on the API calls.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 18, 2020, 01:23:47 am
Updated 01:18 AM on 10/18/2020

Using GetTempPath and GetTempFilename with Gravatar and OMDB APIs as well as using Wininet WinAPI functions to handle internet connectivity for downloading images and responses so as to show more WinAPI usage rather than just using urlmon. I find this makes for a more reliable way than simply just writing the response to a file and reading the contents. This new method stores the response in a string buffer that can be read immediately. For images, I do get a temp file name using GetTempPath and GetTempFileName so the files aren't being written to the directory the executable is launched from. More steps and far more complex but it is definitely worth it in the long run as it is more instructive for WinAPI usage and for showing how an HTTP request is structured.

Updated 02:12 AM on 10/18/2020

Fixed code for getting images in the OMDB and Gravatar API for the string buffer concerning number of bytes to write to the output file. Also, updated the Robohash API to match the same schema of image downloading as OMDB and Gravatar.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 26, 2020, 04:00:33 pm
Updated 03:52 PM on 10/26/2020

Added XInputGetState, XInputSetState, and XInputGetBatteryInformation from XInput1_4 WinAPI DLL. The functions are located in "XInputControllerTest - Merged.bas". The demo is an InForm application. Rather than try to bundle all the files into another folder I've opted to just combine them all into one file. CONST declarations are located at the top of the program.

Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 26, 2020, 04:14:09 pm
Updated 4:13 PM on 10/26/2020

Added pipecom from my pipecom library which pipes console output to QB64. It is a cross-platform library that works on Windows, Macintosh, and Linux.

See here for a post with more detail: https://www.qb64.org/forum/index.php?topic=3168.msg124345#msg124345 (https://www.qb64.org/forum/index.php?topic=3168.msg124345#msg124345)
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on November 01, 2020, 05:50:00 pm
Updated 11/01/2020 at 5:49 PM

Updated pipecom library code with WinAPI calls to simulate popen without a console window appearing.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on November 03, 2020, 04:17:30 pm
Updated 04:17 PM on 11/03/2020

Fixed bug in pipecom which caused duplication of data between calls in Windows due to the buffer not being cleared.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on November 05, 2020, 11:17:12 am
Updated 11:15 AM on 11/05/2020

Updated pipecom library and added CryptBinaryToString and CryptStringToBinary from Crypt32 WinAPI DLL. The code is found in "Base64 Multiplatform.bas". The code also contains usage for the built-in base64 command for Mac and Linux.

See here for a dedicated post on the library: https://www.qb64.org/forum/index.php?topic=3214.0 (https://www.qb64.org/forum/index.php?topic=3214.0)
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on November 17, 2020, 06:20:31 pm
Updated 06:17 PM on 11/17/2020

Added a huge FTP library using WinAPI's Wininet DLL. Took me several days to make it this complete. Probably one of my most complex and certainly my largest library so far. This library has functions for downloading, uploading, directory listing, changing directory, deleting files, deleting directories, and making directories. It's a big one and one that will be updated as time goes on. Since this one uses functions from a previous FTP example in my 7-zip folder I have removed the previous example and replaced it with this. The file is named "FTP WinAPI.bas". Below are some screenshots showing an example FTP listing generated with the library:

 
 
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on November 18, 2020, 02:50:27 am
Updated the "dir" style listing as well as added a new function. Both accept a file extension filter.

Screenshot of the filtered listing:

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on November 28, 2020, 08:24:10 am
08:23 AM 11/28/2020

Updated the XInput library to show pressure on the triggers of the gamepad.

See video for demonstration:

Title: Re: Spriggsy's API Collection
Post by: FellippeHeitor on November 28, 2020, 08:25:34 am
❤️
Title: Re: Spriggsy's API Collection
Post by: SMcNeill on November 28, 2020, 10:16:12 am
Is there some requirement for XINPUT to work properly for us?  I ran the test code in your API bundle last night, and the program would never detect my joystick at all.  I even went in and swapped it to check for all 4 of the available channels (0 to 3), wondering if perhaps mine was on something other than the default 0, but it was all no good.  _DEVICES found and identified the gamepad properly, but the XINPUT application didn't.

Does this require DirectX9?  DirectX11?  Some other version?  As this PC is new, I don't think it has anything except DirectX12 installed on it.  Are older packages required for this to work properly?

Edit:  Reading on the XInput information gives this info:

Quote
XInput Limitations
XInput only supports "next generation" controllers. This limits it basically to controllers for the Xbox 360 that also have Windows drivers. Legacy Windows controllers, joysticks and generalized haptic feedback devices are not supported.

I'm guessing that my poor old gamepad is probably not one of the "next generation" models.  Looks like testing this code will have to wait as well, for me to get a new controller. 

Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on November 28, 2020, 01:13:30 pm
@SMcNeill
Yeah, I wasn't sure what sort of drivers your controller used so I couldn't be sure if it would work or not. It would be neat if your new one did!
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on November 29, 2020, 01:05:57 am
1:01 AM 11/29/2020

Updated UUID Creation library by making it cleaner; e.g., getting rid of unnecessary CONST values, breaking some repetitive actions into new functions and subs, and adding the ability to compare two GUID/UUID values to check if they are greater, less, or equal using UuidCompare. If UUID1 is greater than UUID2 then the return is -1. 0 for equal and 1 for UUID1 less than UUID2.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on November 29, 2020, 02:07:01 am
2:05 AM 11/29/2020

Fixed bug in the FTP library that would cause print statements after FTPUpload and FTPDownload to not appear because of the usage of _DISPLAY in the download loop. _AUTODISPLAY has been added after the loop execution so that printing can resume normally.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on December 07, 2020, 03:19:21 pm
Updated 03:15 PM on 12/07/2020

Added hidapi; a library that is a wrapper for WinAPI HID functions. The source code included is a test program designed to interface with a Nintendo Switch Pro Controller over Bluetooth HID using an InForm-based application that is similar to the XInput tester. The DLL included is for 64 bit only (see original post for clarification) but anyone can retrieve the 32 bit version themselves by following this link (https://github.com/libusb/hidapi/releases (https://github.com/libusb/hidapi/releases)) and downloading the hidapi-win.zip file.

A video demonstrating the test program:
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on December 18, 2020, 10:07:55 am
Fixed bug in my Base 64 code that Steve (@SMcNeill) pointed out. A trailing null character was left behind due to my habit of null-terminated strings in WinAPI functions.

 
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on December 20, 2020, 09:19:33 pm
Updated 12/20/2020 @ 9:17 PM

Added mappedvar, a header file I wrote (Windows, Mac, and Linux), which allows you to create and assign values to named variables on the fly rather than creating the variables beforehand in the source. This allows you to have generic variables (strings only. Can be modified quite easily for other types) and works quite nicely. It's a small file but I believe it will lead to much power in future QB64 programs. Enjoy having generics!

Updated 12/20/2020 @ 9:48 PM

Added some trim functions to the library in order to verify that the name for the variable would not begin, end, or solely contain, whitespace.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on December 21, 2020, 01:22:46 pm
Updated 12/21/2020 @ 1:19 PM

Added two new SUBs to my mappedvar header library: freemappedvar and freemap. freemappedvar erases the referenced mapped variable from the map. freemap erases the map entirely, freeing that portion of memory.

Updated 12/21/2020 @ 4:33 PM

Fixed problem of freemappedvar not actually being freed from memory due to wrong function being used. The code is now fixed and updated in the zip.

Code: QB64: [Select]
  1.  
  2. $IF WIN THEN
  3.     DECLARE LIBRARY ".\mappedvar"
  4.     $ELSE
  5.     DECLARE LIBRARY "./mappedvar"
  6.     $END IF
  7.     FUNCTION mapvar% (name AS STRING, value AS STRING)
  8.     FUNCTION getmappedvalue$ (name AS STRING)
  9.     SUB freemappedvar (name AS STRING)
  10.     SUB freemap ()
  11.     FUNCTION mapsize%& ()
  12.  
  13.  
  14. a = mapvar("test1", "this is a test")
  15. a = mapvar("test2", "this is also a test")
  16. PRINT getmappedvalue("test1"), getmappedvalue("test2")
  17. PRINT "Map is currently"; mapsize; "elements"
  18. freemappedvar "test1"
  19. PRINT "Map is currently"; mapsize; "elements"
  20. a = mapvar("test3", "not sure how big it is now")
  21. PRINT "Map is currently"; mapsize; "elements"
  22. freemap
  23. PRINT "Map is currently"; mapsize; "elements"
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on December 22, 2020, 06:29:28 pm
Upated 12/22/2020 @ 6:24 PM

Added preproc, a header file that gives QB64 access to C++ preprocessor macros for getting things like when the executable had been compiled (__COMPILE_DATE, __COMPILE_TIME), which file was compiled (__SRC_FILE, __BASE_FILE), static counters (__STATIC_COUNT), when the source file had last been edited (__SRC_LAST_EDIT), the C++ names of variables and functions (__VARIABLE_NAME, __FUNCTION_NAME, __FUNCTION_NAME_FULL), etc.

  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on December 28, 2020, 02:01:35 pm
Made a GitHub repository to host this collection so changes and other things can be tracked/managed there with greater ease. The zip folder won't be hosted here anymore. It will only be on GitHub and the code will be downloaded from that repository. However, changes made to the repository will be reflected here as updates to the thread.

https://github.com/SpriggsySpriggs/Spriggsys-API-Collection (https://github.com/SpriggsySpriggs/Spriggsys-API-Collection)
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on February 06, 2021, 11:04:07 pm
Updated 11:01 PM on 02/06/2021

Added SHOpenWithDialog from Shell32. This function invokes the "Open With" dialog many of you are familiar with.
The source also contains usage for WideCharToMultiByte (Unicode/wchar to ANSI) and MultiByteToWideChar (ANSI to Unicode/wchar) but those are small and don't deserve their own file/post. They are needed for this function since it only has a W (wchar/Unicode) variant and not an A (ANSI/cp437).

 
Title: Re: Spriggsy's API Collection (pipecom update!)
Post by: SpriggsySpriggs on February 12, 2021, 08:56:01 am
Updated on 02/12/2021 @ 08:56 AM

As many of you already saw in the dedicated forum post, I've updated pipecom and converted it into a QB64 $INCLUDE. This post is just to serve as the official update to my API collection. Below is the code:

Code: QB64: [Select]
  1.  
  2. Print pipecom("dir /b")
  3.     Sleep
  4.  
  5. Function pipecom$ (cmd As String)
  6.     $If WIN Then
  7.         Type SECURITY_ATTRIBUTES
  8.             nLength As Long
  9.             $If 64BIT Then
  10.                 padding As Long
  11.             $End If
  12.             lpSecurityDescriptor As _Offset
  13.             bInheritHandle As Long
  14.             $If 64BIT Then
  15.                 padding2 As Long
  16.             $End If
  17.         End Type
  18.  
  19.         Type STARTUPINFO
  20.             cb As Long
  21.             $If 64BIT Then
  22.                 padding As Long
  23.             $End If
  24.             lpReserved As _Offset
  25.             lpDesktop As _Offset
  26.             lpTitle As _Offset
  27.             dwX As Long
  28.             dwY As Long
  29.             dwXSize As Long
  30.             dwYSize As Long
  31.             dwXCountChars As Long
  32.             dwYCountChars As Long
  33.             dwFillAttribute As Long
  34.             dwFlags As Long
  35.             wShowWindow As Integer
  36.             cbReserved2 As Integer
  37.             $If 64BIT Then
  38.                 padding2 As Long
  39.             $End If
  40.             lpReserved2 As _Offset
  41.             hStdInput As _Offset
  42.             hStdOutput As _Offset
  43.             hStdError As _Offset
  44.         End Type
  45.  
  46.         Type PROCESS_INFORMATION
  47.             hProcess As _Offset
  48.             hThread As _Offset
  49.             dwProcessId As Long
  50.             $If 64BIT Then
  51.                 padding2 As Long
  52.             $End If
  53.         End Type
  54.  
  55.         Const STARTF_USESTDHANDLES = &H00000100
  56.         Const CREATE_NO_WINDOW = &H8000000
  57.  
  58.         Declare Dynamic Library "Kernel32"
  59.             Function CreatePipe% (ByVal hReadPipe As _Offset, Byval hWritePipe As _Offset, Byval lpPipeAttributes As _Offset, Byval nSize As Long)
  60.             Function CreateProcess% Alias CreateProcessA (ByVal lpApplicationName As _Offset, Byval lpCommandLine As _Offset, Byval lpProcessAttributes As _Offset, Byval lpThreadAttributes As _Offset, Byval bInheritHandles As Integer, Byval dwCreationFlags As Long, Byval lpEnvironment As _Offset, Byval lpCurrentDirectory As _Offset, Byval lpStartupInfor As _Offset, Byval lpProcessInformation As _Offset)
  61.             Function CloseHandle% (ByVal hObject As Long)
  62.             Function ReadFile% (ByVal hFile As Long, Byval lpBuffer As _Offset, Byval nNumberOfBytesToRead As Long, Byval lpNumberOfBytesRead As _Offset, Byval lpOverlapped As _Offset)
  63.         End Declare
  64.  
  65.         Dim As String pipecom_buffer
  66.         Dim As Integer ok: ok = 1
  67.         Dim As Long hStdOutPipeRead
  68.         Dim As Long hStdOutPipeWrite
  69.         Dim As SECURITY_ATTRIBUTES sa: sa.nLength = Len(sa): sa.lpSecurityDescriptor = 0: sa.bInheritHandle = 1
  70.  
  71.         If CreatePipe(_Offset(hStdOutPipeRead), _Offset(hStdOutPipeWrite), _Offset(sa), 0) = 0 Then
  72.             pipecom = ""
  73.             Exit Function
  74.         End If
  75.  
  76.         Dim As STARTUPINFO si
  77.         si.cb = Len(si)
  78.         si.dwFlags = STARTF_USESTDHANDLES
  79.         si.hStdError = 0
  80.         si.hStdOutput = hStdOutPipeWrite
  81.         si.hStdInput = 0
  82.         Dim As PROCESS_INFORMATION pi
  83.         Dim As _Offset lpApplicationName
  84.         Dim As String fullcmd: fullcmd = "cmd /c " + cmd + " 2>&1" + Chr$(0)
  85.         Dim As String lpCommandLine: lpCommandLine = fullcmd
  86.         Dim As Long lpProcessAttributes
  87.         Dim As Long lpThreadAttributes
  88.         Dim As Integer bInheritHandles: bInheritHandles = 1
  89.         Dim As Long dwCreationFlags: dwCreationFlags = CREATE_NO_WINDOW
  90.         Dim As _Offset lpEnvironment
  91.         Dim As _Offset lpCurrentDirectory
  92.         ok = CreateProcess(lpApplicationName,_
  93.                            _Offset(lpCommandLine),_
  94.                            lpProcessAttributes,_
  95.                            lpThreadAttributes,_
  96.                            bInheritHandles,_
  97.                            dwCreationFlags,_
  98.                            lpEnvironment,_
  99.                            lpCurrentDirectory,_
  100.                            _Offset(si),_
  101.                            _Offset(pi))
  102.         If ok = 0 Then
  103.             pipecom = ""
  104.             Exit Function
  105.         End If
  106.  
  107.         ok = CloseHandle(hStdOutPipeWrite)
  108.  
  109.         Dim As String buf: buf = Space$(4096 + 1)
  110.         Dim As Long dwRead
  111.         While ReadFile(hStdOutPipeRead, _Offset(buf), 4096, _Offset(dwRead), 0) <> 0 And dwRead > 0
  112.             buf = Mid$(buf, 1, dwRead)
  113.             buf = String.Remove(buf, Chr$(13))
  114.             pipecom_buffer = pipecom_buffer + buf
  115.             buf = Space$(4096 + 1)
  116.         Wend
  117.         ok = CloseHandle(hStdOutPipeRead)
  118.         pipecom = pipecom_buffer
  119.     $Else
  120.         Function popen%& (cmd As String, readtype As String)
  121.         Function feof& (ByVal stream As _Offset)
  122.         Function fgets$ (str As String, Byval n As Long, Byval stream As _Offset)
  123.         Function pclose& (ByVal stream As _Offset)
  124.         End Declare
  125.  
  126.         Dim As String pipecom_buffer
  127.         Dim As _Offset stream
  128.  
  129.         Dim buffer As String * 4096
  130.         stream = popen(cmd+ " 2>&1", "r")
  131.         If stream Then
  132.         While feof(stream) = 0
  133.         If fgets(buffer, 4096, stream) <> "" And feof(stream) = 0 Then
  134.         pipecom_buffer = pipecom_buffer + Mid$(buffer, 1, InStr(buffer, Chr$(0)) - 1)
  135.         End If
  136.         Wend
  137.         Dim As Long a
  138.         a = pclose(stream)
  139.         End If
  140.         pipecom = pipecom_buffer
  141.     $End If
  142.  
  143. $If WIN Then
  144.     Function String.Remove$ (a As String, b As String)
  145.         Dim c As String
  146.         Dim j
  147.         Dim r$
  148.         c = ""
  149.         j = InStr(a, b)
  150.         If j > 0 Then
  151.             r$ = Left$(a, j - 1) + c + String.Remove(Right$(a, Len(a) - j + 1 - Len(b)), b)
  152.         Else
  153.             r$ = a
  154.         End If
  155.         String.Remove = r$
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on February 12, 2021, 08:26:53 pm
Removed header version of pipecom from library. The new bas version is far superior to the old header and it will be too difficult for me to maintain both versions. The QB64 version is far more interesting and easier to maintain/adapt at this point.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on February 17, 2021, 11:56:36 pm
Updated 02/17/21 @ 11:55 PM

Complete rewrite of PeepingTom library with dedicated post.
Post link:Rewrite of PeepingTom library (Peek/Poke replacement) (https://www.qb64.org/forum/index.php?topic=3669.0)
Title: Re: Spriggsy's API Collection
Post by: zaadstra on October 15, 2021, 05:39:30 pm
Hi @SpriggsySpriggs,

I am trying to have Windows do a time calculation for me.  And I was looking here for the API Collection to see if something will help me.

I want to use the call SystemTimeToTzSpecificLocalTime, to convert an UTC timesmap to local timezone stamp.   I just found out that your API collection is gone from Github (link throws a 404 error), did you know that?

Half a year ago I grabbed a zip from it,  I'll start digging from there.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on October 16, 2021, 12:22:56 am
@zaadstra It's public now. I had it private for a while.
Title: Re: Spriggsy's API Collection
Post by: zaadstra on October 16, 2021, 03:45:52 am
Thanks!