Author Topic: Spriggsy's API Collection  (Read 8843 times)

0 Members and 1 Guest are viewing this topic.

Offline SpriggsySpriggs

  • QB64 Developer
  • Forum Resident
  • Posts: 1114
  • If you're API and you know it clap your hands
    • My GitHub
Re: Spriggsy's API Collection
« Reply #75 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.

 
Screenshot 2020-12-22 182204.png
If you're API and you know it clap your hands
My GitHub

Offline SpriggsySpriggs

  • QB64 Developer
  • Forum Resident
  • Posts: 1114
  • If you're API and you know it clap your hands
    • My GitHub
Re: Spriggsy's API Collection
« Reply #76 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
« Last Edit: December 28, 2020, 02:04:09 PM by SpriggsySpriggs »
If you're API and you know it clap your hands
My GitHub

Offline SpriggsySpriggs

  • QB64 Developer
  • Forum Resident
  • Posts: 1114
  • If you're API and you know it clap your hands
    • My GitHub
Re: Spriggsy's API Collection
« Reply #77 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).

 
Screenshot 2021-02-06 230356.png
« Last Edit: February 06, 2021, 11:06:42 PM by SpriggsySpriggs »
If you're API and you know it clap your hands
My GitHub

Offline SpriggsySpriggs

  • QB64 Developer
  • Forum Resident
  • Posts: 1114
  • If you're API and you know it clap your hands
    • My GitHub
Re: Spriggsy's API Collection (pipecom update!)
« Reply #78 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
  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$
If you're API and you know it clap your hands
My GitHub

Offline SpriggsySpriggs

  • QB64 Developer
  • Forum Resident
  • Posts: 1114
  • If you're API and you know it clap your hands
    • My GitHub
Re: Spriggsy's API Collection
« Reply #79 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.
If you're API and you know it clap your hands
My GitHub

Marked as best answer by SpriggsySpriggs on February 18, 2021, 01:56:47 AM

Offline SpriggsySpriggs

  • QB64 Developer
  • Forum Resident
  • Posts: 1114
  • If you're API and you know it clap your hands
    • My GitHub
Re: Spriggsy's API Collection
« Reply #80 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)
If you're API and you know it clap your hands
My GitHub

Offline zaadstra

  • Newbie
  • Posts: 77
Re: Spriggsy's API Collection
« Reply #81 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.

Offline SpriggsySpriggs

  • QB64 Developer
  • Forum Resident
  • Posts: 1114
  • If you're API and you know it clap your hands
    • My GitHub
Re: Spriggsy's API Collection
« Reply #82 on: October 16, 2021, 12:22:56 AM »
@zaadstra It's public now. I had it private for a while.
If you're API and you know it clap your hands
My GitHub

Offline zaadstra

  • Newbie
  • Posts: 77
Re: Spriggsy's API Collection
« Reply #83 on: October 16, 2021, 03:45:52 AM »
Thanks!