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
At the request of some members here is a collection of my API programs' source codes so far. I'll update this post each time I make a new API and will add it to the zip folder.

This package contains API usage for REST, HTTP, HTTPS, WinAPI (Shell32, User32, Kernel32, etc.), and Cross-platform C++ Libraries. Each one is unique in some way.

Attached is a 7-zip folder containing the source codes for each.

Inside the folder 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 using Kernel32, User32, Advapi32, Wininet, etc. (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 (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) Added 10/16/2020 (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. Too many functions to write here. Largest library yet. Added 11/17/2020

Cross-Platform Libraries (Windows, Macintosh, and Linux)
pipecom (pipecom) Header file that pipes console output to QB64. Win (using WinAPI), Mac, and Linux (using C libraries). Added 10/26/2020
encodeBase64, decodeBase64 (Crypt32, base64 (Linux and Mac)) Added 11/05/2020

 
* Spriggsy's API Collection.7z

https://mega.nz/file/Tn42gbRK#70zC0etdyZZc6u0QRNrvGGbVowwZn-Bo-oLWJv6AU-c (https://mega.nz/file/Tn42gbRK#70zC0etdyZZc6u0QRNrvGGbVowwZn-Bo-oLWJv6AU-c) Link 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 for a post about installing WSL2 on Windows 10 to use Linux on your machine: https://www.qb64.org/forum/index.php?topic=3152.msg124219#msg124219 (https://www.qb64.org/forum/index.php?topic=3152.msg124219#msg124219)

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: Waltersmind on August 18, 2020, 08:45:09 PM
@spriiggsySpriggs, when did you get ominous emails? If it was in the last several weeks, I can tell you for a fact that it was not CoderHunter. Also, I have spoken with him about this accusation, and he guarantees me it was not him.

As I have mentioned to other people in this community, CodeHunter is not the only one from this community who is angry with the community, and that I have been working with CodeHunter ever since this mess started to get to realize it is unhealthy for him to continue this anger to this community for what was done to  him, and I have given him a new home where he can finally be part of a community who appreciates him.

All I ask is that you people stop accusing him of things without being 100% positive, because like I said, CodeHunter is not the only one who is unhappy with this community. He has calmed down quite a bit and no longer cares about any of this anymore and has moved on, which is why he will be leaving the IRC.

On a final note, he is now part of a bigger and better project, and has no need for this one anymore. He is now involved with ModernBASIC 128, which myself and a couple of other powerful developers are working on, so he has no time wallering in anger.

We have a category for ModernBASIC 128 on my Discord server with multiple channels where we are planning out the project, and everything is for the public to see.

I don't get a lot of time at the moment to constantly add stuff because I am gone between 4:00pm and 4:30am everyday, as I work from 5:00pm to 3:30am Monday through Friday and sometimes Saturday.
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 Code Hunter, 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: Waltersmind on August 18, 2020, 09:54:50 PM
Bplus, thank you. I'm actually around quite a bit here and on QB64's Discord server, but I dont socialize very much anymore. I'm mostly on my Discord server now helping people and writing content for ModernBASIC 128. We currently have 110 members there and growing.

I'm in the process of expanding my communities, building my new websites, and working with some other developers on creating ModernBASIC 128, which will be a multi-language transpiler, similar to the way GCC is. Right now there will be three languages wrapped into one: QBasic, QB64, and of course ModernBASIC 128.

All of this is either mentioned on my Discord server, or will be soon enough. I have nothing to hide and everything to share. This is a community project so my word is not final.

My schedule doesn't give me very much time for personal life due to all the constant overtime I have to do at my new job. I am working almost 50 hours a week.
Title: Re: Spriggsy's API Collection
Post by: SpriggsySpriggs on August 18, 2020, 10:17:29 PM
@Waltersmind , 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:
 
* recording.wav
 
* recording2.wav

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.