Recent

Author Topic: Windows API test programs / Examples  (Read 12173 times)

440bx

  • Hero Member
  • *****
  • Posts: 3946
Windows API test programs / Examples
« on: January 08, 2021, 09:53:57 pm »
Hello,

During years of programming, I've accumulated a fairly large number of programs whose purpose is to test the operation of specific Windows APIs.  All of the programs are pure Windows API, that is, no objects/classes and independent of Delphi/Lazarus.  IOW, programs along the lines of what is presented in Petzold's Programming the Windows API but, in Pascal.

The great majority of the programs, likely around 95% are very simple, even trivial, programs meant to show how to correctly build the API call and to occasionally be used as the foundation for further tests (such as performance.)   About 5% of the programs are more sophisticated and, are not API specific but goal/technique specific instead.  Such as, how to avoid/eliminate flicker using various methods, implementing the functionality of undocumented APIs using documented APIs and many other unrelated purposes that are often useful in one way or another.

Through the years, I have accumulated about 700+ such (Pascal) programs.  _Important note_ : these programs are _not_ programming examples, they are API _test_/example programs.  This means that almost all of them use global variables and other ways of getting things done that are fine in throw away code but, would be questionable and, sometimes even unacceptable, in production quality code.

I am offering these test programs mostly as a way to learn the Windows API.  A few, very few (maybe 5%), can be used as programming Windows examples (IOW, the programming is halfway decent.)

The point of this post is two fold:

First, find out if the community is interested in these API test programs.

If there is interest then, I'd post _about_ 5 of them on a daily basis.  One short post per API test program and, proceed from simplest (usually downright trivial) to more complex as the number of post increases with a few exceptions along the way to keep things interesting.

Second if there is interest then I'd like the moderators to confirm that my creating about 5 individual posts every day is acceptable (possibly fewer on some days but never larger.)

If there is interest and approval from the moderators, I'd start about a week from today, this to give me a little time to organize the programs.

All feedback welcome,

Thank you.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Windows API test programs / Examples
« Reply #1 on: January 08, 2021, 10:45:15 pm »
Your Windows API test programs sound really useful, but it may be better to put them up on your favourite repository (Sourceforge, Github, GitLab etc) and add a link in the forum and the Wiki.

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: Windows API test programs / Examples
« Reply #2 on: January 08, 2021, 11:09:25 pm »
Thank you Trev.

I am usually not fond of sharing my code, for that reason, sourceforge, github, etc, are not appealing avenues to me. 

That said, I thought that if FPC forum members were interested then I would share it here and, since this is s forum, answer any questions that may arise.  Given that all programs are pure API, I didn't expect much interest but, I figured just in case, I'd offer.

However, I appreciate your suggestion, which admittedly is probably the "natural" solution. 
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Windows API test programs / Examples
« Reply #3 on: January 08, 2021, 11:44:03 pm »
May I make a suggestion, maybe towards a middle ground.

Since you want to post an article with the sources, yes that can be done on the forum.
I would suggest the "Programming / os / win" board. Or 3rd party announce.

However, it probably be best to collect several posts into one thread. If you had a 100 samples (no idea how many you have) grouping an average of 5 per day would still be 20 topics. But IMHO ok (well to much for the announcment board). If you have 1000 then maybe grouping several days....

The announcement board should be shared fairly. Max 2 or 3 threads per user per month. But as many posts as you like, inside those threads.

In the programming/os/win, I think it is ok. I would suggest that if several daily topics do not attract lots of answers, then they could be merged by an admin to become one thread.

About a repro to share source, I am not sure if by "not appealing" you mean
- you do not want the sources to end up there.
- you do not want to go into the trouble to put them there.

If the latter, then maybe someone  can volunteer to upload them in groups of 5 a day?

Also, it may be easier than you think. Github allows you to upload via web interface.
- Get an account
- Create a repro
- Go to upload files
- drag and drop each folder that you want to upload (that way the folder is created in the repro)
- add a commit message
- commit


Having the sources avail on a repro would also, if interest is big, make it easier to collect info on the wiki. (again could be done by a volunteer, if alright with you, and someone wants to do that)

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: Windows API test programs / Examples
« Reply #4 on: January 09, 2021, 12:01:23 am »
Thank you Martin.

The programming / os / win does sound like it would be the best suited forum.  I estimate that I have somewhere between 700 and 800 examples/test programs.

The reason I thought about doing one post per API was to make it easy to find.  I would title each post along the lines of "Win API example - api name" which I believe would make it easy to find using the forum's search engine.  Combining multiple APIs into one post could make finding the example for a specific API more difficult for the interested party.

I don't find the repositories attractive because they are very static.  The great advantage of the forum is that they are interactive, every one can participate either with questions, suggestions and/or improvements. 

The above is just to show where I'm coming from.  I appreciate your suggestions.

So far, the level of interest does not seem to be high enough to even merit concern on how to go about it.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Windows API test programs / Examples ()
« Reply #5 on: January 09, 2021, 12:16:25 am »
The programming / os / win does sound like it would be the best suited forum.  I estimate that I have somewhere between 700 and 800 examples/test programs.
700 topics would mean anyone just browsing the board would see nothing else.
Even 140 (700 div 5) is way too much (unless they really all attract big exchange of messages).

The reason I thought about doing one post per API was to make it easy to find.  I would title each post along the lines of "Win API example - api name" which I believe would make it easy to find using the forum's search engine.  Combining multiple APIs into one post could make finding the example for a specific API more difficult for the interested party.
An idea would be to have on overview topic, in which to post the name and link (to the post inside a thread) for each example. That would help finding them. You can keep that topic locked, so only you can write to it (you may need to unlock it to edit it, not sure).
(It may need updating, if topics need to be split/merged)

Each post in a topic can have a modified subject.

If a specific example takes on an extraordinary amount of discussion, then you can pm me, and I can split the topic.

I don't find the repositories attractive because they are very static.  The great advantage of the forum is that they are interactive, every one can participate either with questions, suggestions and/or improvements. 

Well you can disable all feedback on github, and include a readme that points to the forum as place for discussion.

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: Windows API test programs / Examples ()
« Reply #6 on: January 09, 2021, 01:34:41 am »
700 topics would mean anyone just browsing the board would see nothing else.
Even 140 (700 div 5) is way too much (unless they really all attract big exchange of messages).
that's definitely a valid concern, which is why I thought about limiting the number of posts to a maximum of 5 per day, to avoid "drowning" other posts in the target forum.

An idea would be to have on overview topic, in which to post the name and link (to the post inside a thread) for each example. That would help finding them. You can keep that topic locked, so only you can write to it (you may need to unlock it to edit it, not sure).
(It may need updating, if topics need to be split/merged)
I figured we could try 5 posts a day in a particular forum (the one you suggested sounds very appropriate) and if that creates a problem then address whatever problem arises (if any) with a solution tailored for it.

Well you can disable all feedback on github, and include a readme that points to the forum as place for discussion.
That is a possibility but, since the examples would be on github (or some other repo) it would result in a lack of context (the API in one place - the repo - and, its discussion in another - the forums here.) 

I believe the greatest value is obtained by open discussions on the topic in one place.

Anyway, at least so far, it doesn't seem like there is much interest in the examples.  IOW, so far, it's a non-problem. <chuckle>
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • Former Delphi 1-7, 10.2 user
Re: Windows API test programs / Examples
« Reply #7 on: January 09, 2021, 02:00:37 am »
> Anyway, at least so far, it doesn't seem like there is much interest in the examples.

Build it and they will come :) Seriously, your examples sound like valuable content that should be preserved for posterity and shared with the Pascal populace.

In my past experience, relying on a Forum for longevity of preservation does not work. While I don't expect this Forum to disappear which has happened to me in the past with JAL, I've seen Forum software changes in the past which have "lost" the previous content, but perhaps the biggest disadvantage is that the content becomes scattered and hard to find once it's been buried in several hundred/thousand posts.

The Wiki is a good place to collect the examples and document them. Discussion can then be either linked back to the Forum (as is already done in some cases) or held on the Discussion page assuming there's an Overview page which lists them all with links to each one on its own page. Yes, it sounds like work :) I could help.

Anyway, what you do is, of course, up to you.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Windows API test programs / Examples
« Reply #8 on: January 09, 2021, 02:24:34 am »
I was thinking about this (and yes, I'm also very interested: I'm almost completely out of touch with the Windows API :-[) and it really sounds as a subject for a whole (if small) new site.

The problem, as Martin said already, is that here it would be easy to "drown" other posts under yours (unless it's just one or a few topics listing related examples), more so in any of the "specialties" boards which see relatively little traffic.

Of course, builiding a whole new site has its own problems too (mainly that "someone" has to maintain it ;)) but it might be worth at least thinking about it: "Pascal and the WAPI!"

But however you do it (if you do it) I'll surely collect both the examples and any discussion about them. Would be a nice addition to my Pascal "'ciclopedic notes"*


* ... so called; really just a bunch of badly organized text files, saved web pages, zipped examples,etc. :-X
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: Windows API test programs / Examples
« Reply #9 on: January 09, 2021, 08:39:29 am »
Build it and they will come :)
I think you're quite right about that.  I'm going to prepare a few "teaser" examples in the next few days.  That might raise interest.  "Seeing is coveting"  ;)

In my past experience, relying on a Forum for longevity of preservation does not work.  <snip>  perhaps the biggest disadvantage is that the content becomes scattered and hard to find once it's been buried in several hundred/thousand posts.
I'm not concerned about the longevity.  I presume that if members find the examples useful they will be remain, if not they'll be dropped or archived away as they eventually should be.

The Wiki is a good place to collect the examples and document them. Discussion can then be either linked back to the Forum (as is already done in some cases) or held on the Discussion page assuming there's an Overview page which lists them all with links to each one on its own page. Yes, it sounds like work :) I could help.
I definitely appreciate the offer to help, particularly considering that I'm not particularly good at structuring and formatting text.  I'm much better at casual explanations (like those found in forum posts. ;) )

Anyway, what you do is, of course, up to you.
Thank you, my "greatest" concern is to ensure I don't disrupt the smooth operation of the forum by, for instance, "drowning" other posts.



I was thinking about this (and yes, I'm also very interested:
Adding one (1) to the "interested count". :)

Of course, builiding a whole new site has its own problems too (mainly that "someone" has to maintain it ;))
I just don't have the talent nor ability to format a bunch of text.  My artistic abilities are at the low end of the Kelvin scale.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

FlierMate

  • Guest
Re: Windows API test programs / Examples
« Reply #10 on: January 13, 2021, 05:37:43 pm »
This will be a great resources, 440bx!

I need to refer to it for my "basic compiler". I have come up with ReadConsole and WriteConsole (both prefixed with GetStdHandle) but I need more, such as MsgBox and wsprintf??

Will your example include which library(kernel32.dll, user32.dll) in use?


FlierMate

  • Guest
Re: Windows API test programs / Examples
« Reply #11 on: January 13, 2021, 05:46:08 pm »
Adding one (1) to the "interested count". :)

Count me in.

I just don't have the talent nor ability to format a bunch of text.  My artistic abilities are at the low end of the Kelvin scale.

I will try and see if I can help..... With some basic HTML5 +CSS3 skill. Hopefully most part of the text formatting can be automated using Pascal program itself?  8-)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Windows API test programs / Examples
« Reply #12 on: January 13, 2021, 05:49:41 pm »
As maintainer of the windows api headers, count me in too.

Seenkao

  • Hero Member
  • *****
  • Posts: 546
    • New ZenGL.
Re: Windows API test programs / Examples
« Reply #13 on: January 13, 2021, 08:07:58 pm »
Добрый вечер!
То, чем вы хотите поделиться, я думаю, будет полезно многим. Но на форуме, если данная тема/ветка потеряются. А это будет не очень хорошо...
Так же будет и везде: Git, SourceForge и др...

Тему надо периодически обновлять, чтобы она не забывалась людьми. Потому что полезно это может быть и через несколько десятков лет будет.

Eng:
Good evening!
What you want to share, I think, will be useful to many. But on the forum, if this topic / thread is lost. And it won't be very good ...
It will be the same everywhere: Git, SourceForge, etc.

The topic should be periodically updated so that it is not forgotten by people. Because it can be useful and it will be in a few decades.  :)
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: Windows API test programs / Examples
« Reply #14 on: January 13, 2021, 09:51:38 pm »
Honestly, since the level of interest seemed to be modest at best so far, I thought about letting this offer "die" silently.  Given that today an additional number of forum members have expressed interest, I've decided to go ahead and post the examples.

Sometime between today and tomorrow, I'll post a few "teaser" examples. "teaser" because, I'll include the source code only for _one_ of the examples and the remaining examples will hopefully wet the appetite of additional forum members.



Will your example include which library(kernel32.dll, user32.dll) in use?
Examples include mostly, ntdll.dll, kernel32.dll, user32.dll and gdi.dll.  There are examples for other dlls but those mentioned make up the great majority of them.



As maintainer of the windows api headers, count me in too.
good :)

About API headers, I have several hundred definitions of APIs and constants but, they are currently scattered in multiple files (used by examples and programs), I will try to consolidate them to make them useful to you.  However, there is a caveat, I organize all definitions by the dll that depends on it.  For instance, the Windows message definitions are in user32.dll instead of in a "messages" unit.  IOW, for them to be useful to you, you'll have to reorganize them as required by FPC.



What you want to share, I think, will be useful to many. But on the forum, if this topic / thread is lost. And it won't be very good ...

The topic should be periodically updated so that it is not forgotten by people. Because it can be useful and it will be in a few decades.  :)
My "plan" is to name each post "Win API - api name", this way if someone uses the forum search engine, they will always be able to find it even if no one has updated it in a long time (there is only so much that can be said about any one API function.)



Time for me to prepare those "teaser" examples. :)

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018