Author Topic: Recent PB toys for API coding.  (Read 3308 times)

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4935
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Recent PB toys for API coding.
« on: December 13, 2014, 01:25:21 PM »
Window Template generator.

I have been writing and using toys like this for many years as I hate hacking out boilerplate code. This one quickly creates a base Windows API template that has the following support.

Code: [Select]
Self Centering window
Basic menu
Messageloop, WndProc and DlgProc
Simple hot key processing
Drag and drop enabled
---------
RESOURCES
---------
Icon
Manifest
Version control block
Resource dialog about box

It builds at just under 14k. It is minimalist code aimed at getting the most out of operating system capacity for its size. The idea is to save having to keep writing the hack startup code so you can work on the stuff that matters and you can add all the fancy stuff later as you need it.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4935
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Recent PB toys for API coding.
« Reply #1 on: December 13, 2014, 01:30:16 PM »
Subclassing tool for API based code.

I have been using this toy for years as I hate having to hack out repetitive code. Did a few tweaks on it recently and it works fine on late versions of PB.

Create a control with CreateWindowEx() OR or use simple code to get the handle of a resource dialog box control,
Code: [Select]
hButton1 = GetDlgItem(hDlg,125)
Then subclass it if you need the extra control or need to extract extra functionality with the control.

There are two (2) files in the zip file, the subclass.exe and the result viewer tview.exe which is one of my MASM toys. It saves having to write an edit control section of the subclass executable and I also use the viewer for other similar tools.

Usage is simple enough, once you have the Windows handle, just type in the names you require, hit the GO button and the viewer will turn up a subclass skeleton that you can routinely modify to do what you need.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4935
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Recent PB toys for API coding.
« Reply #2 on: December 13, 2014, 01:34:19 PM »
Random Pad Generator.

This is a tool for creating reasonably high quality unique random pads that have a number of uses, encryption being one of them. The design of the app is to produce pads that are extremely difficult to reproduce.

It is a console app (PBCC 6) that liberally uses API code to perform the high level aspects of the app. It has an attached file called "randompad.bas" that is full of the dirtiest hacks you can imagine and so Michael and James do not suffer from incontinence problems, its functionality is accessed through a normal basic function to obtain the random pad and you don't even have to look at it.

The ZIP file also has a public domain random analysis program called ENT written by John Walker that is used to analyse the results. The important test is the CHI SQUARED test and you need to get the pad results in the 25% to 75% range for the pad to be any good.

The app is not particularly fast as it is very busy in its guts and it among other things relies on timing delays to get random seeds and this was necessary to get the results in ENT.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4935
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Recent PB toys for API coding.
« Reply #3 on: December 13, 2014, 01:38:48 PM »
Constructing an API based library in PB.

If anything held PowerBASIC back for a long time, it was the lack of linkable static libraries but with the last versions of PBWIN and PBCC this last irritation has disappeared. No longer a candidate for the "Mickey Mouse Club" of kiddie level BASIC, PowerBASIC now has the capacity of a professional language.

Now effectively this means that you can have a near infinite number of new intrinsics as long as you know how to write them and make sure they are reliable re-usable code and as you can do almost anything within the boundaries of Win32, you can bundle BASIC functions, encapsulate complex and messy code so its easier to use, write a heap of dirty hacks and if speed matter you can write some truly filthy ones.

Instead of the last couple of years of whining because Bob passed away, what most missed is that Bob did make the language fully extendable, redundant code removal for personal code and personal collections of code and a professional capacity in constructing libraries that can be shared, sold or just used to store re-usable code.

Something you DO need to do when constructing libraries is produce documentation for the functions included in the library so that you don't have to go ratting through your source code to find out or remember how to use it.

The attached ZIP file has a number of API based functions that I have on and off posted before, the API based fileio functions and I have used them in this library demo as I had them handy to show how a professional library is created in PowerBASIC.

The library is built with a batch file and I have included a PB utility PLIB which may not be the latest version but it works fine. You will need to edit the batch file "makelib.bat" to set the path to your own installation of PB in the BIN directory. I have included a simple text based HELP file so you know the basics of how to construct and use the library.

Here is the very simple test piece that comes in the ZIP file.
Code: [Select]
' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    #include "\basic\include\win32api.inc"

    #link "fileio.lib"

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

FUNCTION PBmain as LONG

    LOCAL hFile as DWORD
    LOCAL lFile as DWORD
    LOCAL rval  as DWORD

    hFile = fopen("\basic\include\win32api.inc")
    lFile = fsize(hFile)
    dat$  = fread(hFile,lFile)
    rval  = fclose(hFile)

    save_file("win32.inc",dat$)

End FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4935
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Recent PB toys for API coding.
« Reply #4 on: December 13, 2014, 01:46:23 PM »
Doing C in PowerBASIC.

As we are allowed to handle API wrappers, here is a collection of functions from a standard Windows DLL, MSVCRT.DLL which gives you a wide range of direct C runtime functions.

Being much more interested in the Power aspect of PB than the Flower, Flour or Sour aspects, its no big deal to write close to C using the C runtime and while the functions are nothing exciting, you DO get them for close to nothing and with just a little help from an already posted MACRO, you can do all sorts of useful things with the C runtime functions.

Much of the attraction of PowerBASIC is that it can do many styles of code from line numbered BASIC to truly wicked assembler and any damned thing you can call from a DLL including the full API function set.

Instead of trying to cripple a powerful language down to the "Mickey Mouse Club" BASIC of the distant past, it can be used to do close to anything in Win32.

Old BASIC
New Basic
Almost MASM
Pure API
C Runtime
Better MACRO engine than most C compilers
etc etc etc .....

PowerBASIC needs to be treated like crippleware like it needs an extra hole in the head.

Here is PB doing a passable imitation of C.
Code: [Select]
' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    #include "\basic\include\win32api.inc"
    #include "vcrt.inc"
    #include "funcs.bas"

  ' ------------------------------
  ' return address of BASIC string
  ' ------------------------------
    MACRO FUNCTION sadd(quoted)
      MACROTEMP bas
      LOCAL bas as STRING
      bas = quoted
    END MACRO = StrPtr(bas)
  ' ------------------------------

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

FUNCTION PBmain as LONG

    LOCAL urv   as DWORD
    LOCAL srv   as LONG
    LOCAL pbuf  as DWORD
    LOCAL pmem  as DWORD
    LOCAL lf    as DWORD

    pbuf = cmalloc(1024)                            ' allocate some working memory
    pmem = cmalloc(1024)                            ' and a spare buffer

    lf = sadd(chr$(13,10))

  ' ---------------------------
  ' number - string conversions
  ' ---------------------------
 '     urv = catoi(sadd("123456"))
 '     ccputs(cultoa(urv,pbuf,10))
 '     ccputs lf

    ccputs(cultoa(catoi(sadd("123456")),pbuf,10))   ' unsigned
    ccputs lf

 '     srv = catol(sadd("-987654"))
 '     ccputs(cltoa(srv,pbuf,10))
 '     ccputs lf

    ccputs(cltoa(catol(sadd("-987654")),pbuf,10))   ' signed
    ccputs lf

  ' ---------------------------
  ' tokenise string
  ' ---------------------------
    LOCAL nums  as DWORD
    LOCAL token as DWORD
    nums = sadd("one two three four five six seven eight nine ten")
    token = cstrtok(nums,sadd(" "))                 ' get 1st string
    while token <> 0
      ccputs(token)
      ccputs lf
      token = cstrtok(0,sadd(" "))                  ' loop through the rest
    wEnd

  ' ---------------------------
  ' zero terminated string copy
  ' ---------------------------
    cstrcpy(pmem,sadd("This is a test of C runtime string copy"))
    ccputs(pmem)
    ccputs lf

  ' ---------------------------
  ' string reverse
  ' ---------------------------
    ccputs(sadd("Reverse string = "))
    ccputs(cstrrev(sadd("abcdefghijklmnopqrstuvwxyz")))
    ccputs lf

  ' ---------------------------
  ' zero terminated string length
  ' ---------------------------
    urv = cstrlen(sadd("12345678901234567890"))
    ccputs(sadd("String length = "))
    ccputs(cultoa(urv,pbuf,10))
    ccputs lf

    cfree(pbuf)                                     ' free the memory
    cfree(pmem)

    pause

End FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4935
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Recent PB toys for API coding.
« Reply #5 on: March 05, 2017, 03:41:32 PM »
This download is an uncompressed version of "wmaker.exe" as some of the crapware AV scanners on the combined AV scanner site "Jotti" squarked a false positive on the use of PEcompact. The uncompressed version comes in at 61,440 bytes but by today's standards is no big deal and it does what it is supposed to do, create a simple template of pure Windows API code to use as a base to develop more complex applications.

For the folks who came into Windows programming by using the PowerBASIC DDT interface design tools, you don't need to listen to patronising bullsh*t about how complex Windows API code is and how it is too difficult for BASIC programmers to write. Like anything else you need to understand it but it is not the big deal that some trying to peddle you trash want to make out. Its like anything else, you learn to use the API by gradualism.

The 13k exe (13,824 bytes) it produces has an icon, manifest, menu and version control block, a bare window and a resource dialog for the about box. The code is clean simple Windows API code and the actual API count is not very large. This type of template is only the tip of the iceberg, once you start writing this style of code the sky is the limit. PowerBASIC has plenty of very useful functions, you can routinely use MSVCRT functions once you prototype them and of course you can use your own along with a decent inline assembler that can easily port MASM code.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin: