Win32 Source code snippets by the derelict


  • These are all small, typically command-line utilities that I've found to be useful.
  • All are compiled using the MinGW compiler package. This is an excellent, *FREE* compiler package which is based on the GNU compiler, but links to Windows libraries.  MinGW is available from: http://www.mingw.org/
  • All are FREEWARE for any and all uses!!

    THE SOFTWARE
    ulocate - This was initially written for use under Linux, as a replacement for the obtuse find command.  It also works in Windows consoles.   ulocate searches all subdirectories below the specified starting point for any filename containing the provided string.  Optionally, it can also search the PATH for the same criteria.
    Last Update: October 01, 2012
    ULOCATE.EXE, Version 1.11
    Usage: ulocate [options] name_component start_path
    This program displays all filenames containing a specified
    name component, starting at directory [start_path].
    Default start_path is current location.
    
    output-format options:
     -d  show file date
     -t  show file time
     -s  show file size (short format)
     -S  show file size (byte format)
         -xl  l = width of size field for -S (default = 6)
     -n  show file name (default)
    
    other options:
     -v  Verbose mode - show search paths
     -b  Debug mode - show other process information
     -l  follow symbolic links
     -w  match exact string (whole-word search)
    
     -p  Search for name_component in the directories in the PATH variable
         NOTE: This option replaces the normal ulocate functionality with
         alternate functionality.  In this mode, subdirectories are NOT searched!!
          
    Download ulocate.cpp here
    printf2 - source code for printf/sprintf, with floating-point support, and no header-file dependencies
    Last Update: October 08, 2013
    Embedded firmware environments provide a variety of challenges to the software developer.  One of these challenges is that, typically, there is no "standard output" device to display messages on, so the archetypal printf function is not an option.  However, the sprintf function is often still very useful for generating formatted strings. Unfortunately, in most embedded environments, linking stdio libraries is not an option, so a non-stdio version of sprintf is very handy - but find such a function is very challenging, especially if floating-point support is required!!

    In 2002, Georges Menie distributed a version of printf which had no stdio/stdlib dependencies, and seems to support all of the various obtuse printf syntaxes.  His code is clean, short, efficient, and builds on modern gcc with almost no warnings!  Furthermore, it is distributed under LGPL, which means it can be used freely by anyone, for any purpose!  The only option missing from his function was floating-point support, which I need in my ARM9 implementation, so I added that capability to it.  This version has no dependencies on any standard headers or libraries.

    Updates:
  • 12/02/09 - fixed floating-point bug related to padding decimal portion with zeroes.
  • 03/19/10 - pad fractional portion of floating-point number with 0s
  • 03/30/10 - document the \%char bug
    If '\%' is included in a format string, followed by a non-format character (typically because the user desires to place the % char in the output string), this function will mis-handle the data entirely!! Essentially, it will just discard the character following the percent sign. This bug is not easy to fix in the existing code; for now, I'll just try to remember to use %% instead of \% for normal output.
  • 07/20/10 - Fix a round-off bug in floating-point conversions
    ( 0.99 with %.1f did not round to 1.0 )
  • 10/25/11 - Add support for %+ format (always show + on positive numbers)
  • 01/19/12 - fix handling of %f with no decimal; it was defaulting to 0 decimal places, rather than printf's 6.
  • 05/10/13 - Add stringfn() function, which takes a maximum-output-buffer length as an argument. Similar to snprintf()
  • 09/28/13 - Fix bug in printchar(), which was using a fixed length test that was not appropriate for general use
  • 10/08/13 - Add support for signed/unsigned long long (u64/i64)

    Download printf2.c here
  • serial_enum - Uses standard Windows/Win32 methods to enumerate serial devices
    Last Update: February 02, 2015
    This is the Microsoft-approved method to enumerate all serial ports on a machine, including USB-serial devices.  In addition to listing all the ports, it will report which ports can be opened (i.e., are available for use). Also added an option to display the Device Name, which can be passed to CreateFile().

    Download serial_enum.cpp here
    beer_cals - Estimates calories of ale
    Last Update: September 22, 2015
    Estimates calories of ale, from both alcohol and carbohydrates, based upon volume and alcohol content. Volume may be input in milliliters or ounces.

    Download beer_cals.cpp here
    apptest - This inappropriately-named file demonstrates two common WinAPI tasks
    Last Update: December 03, 2013
    This console application demonstrates two common WinAPI tasks:
  • Use printf() to output UNICODE messages to the console
  • Display various Windows system/user directories

    Download apptest.cpp here
  • dms2dd - Convert between degrees/minutes/seconds and decimal degrees
    Last Update: September 30, 2010
    Usage: dms2dd input_value
    Enter dms as degrees.minutes.seconds
    Enter dd as integer_degrees.fractional_degrees

    If dms2dd sees two decimal points in the input,
    the value will be treated as dms, and dd will be calculated and output.

    If dms2dd sees one decimal points in the input,
    the value will be treated as dd, and dms will be calculated and output.


    Download dms2dd.cpp here
    mortgage - Performs mortgage calculations
    Last Update: December 23, 2011
    Usage: MORTGAGE principle interest number_months overpay In normal operation, this program computes the monthly payment, and payment summary table, for a loan with the input parameters.

    Alternate mode: If number_months is 0, overpay is treated as the payment amount, and this program will // calculate and display the number of months required to pay off principle.

    Also, if overpay is greater than payment, then overpay is treated as total payment amount, and overpay is calculated from that.

    Download mortgage.cpp here
    prime32 - calculates factors of a number, or reports if input is prime
    Last Update: February 22, 2012
    PRIME32.EXE - Written by: Daniel D. Miller
    ****************************************************
    This program determines whether a number is a prime,
    then displays either the number or its factors.

    Download prime32.cpp here
    C/C++ makefile-dependency generator
    Last Update: February 02, 2007
    This is the version of makedepend which is distributed with Xfree86.  It is Copyright (c) 1993, 1994, 1998 The Open Group and has a free-distribution message in each source file.  I made a couple of trivial changes to the source to make it compile with modern gcc, but otherwise it still works superbly and needs no changes.
    To use this utility, make the following changes to your makefile:

    1. Add this line to the end of the makefile:
    # DO NOT DELETE
    2. Add a rule for running makedepend:
    SRCS=file1.cpp file2.cpp file3.cpp
    depend:
      makedepend -I. $(SRCS)
    
    3. run
    make depend
    to update the dependencies.   That's it!! Your makefile now has the appropriate dependency list.

    Download the source code package here