Samples for MASM32

I put here some samples I coded with MASM32. Maybe they help someone
learning Assembler. The source is included but mostly not commented. (Iczelion's
tutorials are for the first look better. They come with the MASM32.)
The binary is included.
A batch file is included. Note, I do not want to win a beauty contest: Error handling and coding are not optimized. If you find errors let me know, I am still learning;-) (Some of the samples are compiled on NT 4.0, the newest ones on W2K. I have not crosstested them.)
UserinterfaceNetworkDiverseCOM

This control (since version 4.71 of Comctl32.dll) lets you input an
IP address. It does a little bit checking, too. You must insert a couple of
definitions into the windows.inc (I copied them to the beginning of the source code).
Reference: http://bcarroll.siscom.net/HTMLDocs/IE4ResKit/itt/commctls/ipaddress/IPAddress.htm#ch_ipadd_make

This code shows how you implement the label editing in a listview control. It made
me a lot of headache. The solution was RTFM. It also shows how to use the callback function and to sort the items.
Reference: Nancy W. Cluts, Programming the Windows 95 User Interface, Redmond 1995
http://bcarroll.siscom.net/HTMLDocs/IE4ResKit/itt/commctls/listview/ListView.htm#ch_listview

This sample shows an up-down control with the range 9-19 at startup. In the
2-page propertysheet you can change the range and change the the system text color
in blue (I know it is a bit silly, but you can change it back!). The user input is
checked only in so far that upper limit is greater than lower limit.
Reference: Nancy W. Cluts, Programming the Windows 95 User Interface, Redmond 1995

This is a port of a msdn sample program. You may have to insert some definitions
in your windows.inc file if you want to build a new exe-file. The code is not
very tight. The web site below explains the code which was written in C++.
Reference: The Rebar Control: Using a Coolbar in Your Application, in:
http://msdn.microsoft.com/library/techart/msdn_rebar.htm

This one puts an icon in the taskbar notification area (=where the time resides), displays
a tip when the mouse pointer stays on that icon and popups a message box, if you click
on the icon with the left mouse button.
Reference: Nancy W. Cluts, Programming the Windows 95 User Interface, Redmond 1995

Start the anonpipe.exe and from the menu create an anonymous pipe and a process, which is the winclien.exe. When the client window
is displayed you write a message and put it into the pipe. Back in the server window you can read the pipe.
Read in MSDN more about anonymous pipes.

Echo client creates a socket, sends one datagram
to the port 7 on a remote host (echo server) and waits 10 seconds for a reply.
The Programm shows also how you can
en- and disable menuitems. It also uses a statusbar and a timer.
Reference: Arthur Dumas, Programming WinSock, Indianapolis 1995

Finger is a connection oriented protocol. You create a socket and
connect to the port 79 on a remote host. The Programm shows also how you can
en- and disable menuitems.
Reference: Arthur Dumas, Programming WinSock, Indianapolis 1995

This sample has both the client and server part.
It works on the local machine: The client uses in CreateFile \\.\mailslot\sample_mailslot as filename. The mailslot on the server is defined as \\.\mailslot\sample_mailslot.

This one, demonstrating the named pipe, works on the local machine.
(It will also work over the network, if you
login into both machines with the same userID and password. That's
because SECURITY_ATTRIBUTES in CreateNamedPipe is NULL.) The programm shows also how you can
en- and disable menuitems. You step
through the program on a determined path: create a named pipe, write a message, choose
the server, write into the pipe, read the pipe. That's why you must use it on your local machine. The program has both
the client and server part. The named pipe on server is defined as \\.\pipe\sample_pipe.
You must use in the client the server name, not the period.

This one, demonstrating the named pipe, works over the network.
That's
because SECURITY_ATTRIBUTES in CreateNamedPipe is used. The client and the server are
both in the same program. On the server you create the pipe and read the pipe.
On the client you write the message and write it into the pipe.
The named pipe on server side is defined as \\.\pipe\sample_pipe.
On the client side you must change the server name and the account name (I
used xyz and misterx).
In the code there is a lot of error handling.
Reference: http://devcentral.iftech.com/learning/tutorials/mfc-win32/nt/5.asp

The program demonstrates the use of EnumServicesStatus function. You can choose some parameters
to gauge the search. The default type is SERVICE_WIN32 and the default state SERVICE_ACTIVE. The style
of the listbox es is LBS_MULTIPLESEL. Right click on one of 10 first rows shows the types of the service.

Here is a sample which consists of a stream echo server and a correponding client.
The client creates a socket, connects(!) to the listening server port 7 and sends every 5 seconds data to the server waiting for the data to be returned by the server. The client
displays in a listbox some information on the fly. Note: The program is very simple insofar
as only one client can be connected to the server at a time.
The Programm shows also how you can insert the version register into the properties window
for your program.
Reference: Arthur Dumas, Programming WinSock, Indianapolis 1995
Look also in http://www.sockets.com/sample.htm for samples in C/C++

The tiny sample displays a bitmap with the letter A. When the mouse is on the bitmap
it looks like a button and the A is colored. You can use it like a normal button to
end the dialog: just click the left mouse button.

Me too! There are a lot of PE analyzers around. They do many amazing things, except they
don't let me print the listing of the header (I don't live in a paperless world). That's why I coded my own program. I think it runs only on NT.
It shows you also some image directories (import, export and resource). The splitter
window is from Ernest Murphy.
If you right click the characteristics fields you get them analysed.
Look for PEditor if you want a nice PE editor.

Here is the port of the sample how to print a bitmap file. It prints the
winlogo.bmp which should be in the same directory with the program.
The GetOpenFileName dialog lets you choose a filename which is printed at the top
of the page. None the less the winlogo.bmp is printed.
You can edit the source and use the dialog to load a bitmap file.
Reference: Win32.hlp (Printing a Document)

This sample enumerates the running processes in NT 4.0 and displays the process ID, the base
name, the full path and the no. of modules in a list view. It uses the procedures in
PSAPI.DLL.
In Windows 9x and 2000 you will use the ToolHelp32 group of APIs.
Reference: http://support.microsoft.com/support/kb/articles/Q175/0/30.asp

This sample enumerates the running processes in Windows 9x and displays the process ID, the full path and the no. of threads in a list view. It uses the procedures in
the ToolHelp32 group of APIs. It should run also in Windows 2000.
Reference: http://support.microsoft.com/support/kb/articles/Q175/0/30.asp

This is a very simple richtext edit control. You can use it with riched.dll version 1.0
to 3.0. I used windows.inc version 1.13. Later versions may need modifications
in the code. You can choose a font and save a text. The rest is up to you.
Reference: Nancy W. Cluts, Programming the Windows 95 User Interface, Redmond 1995

This is a port of a simple NT service program. All it does is beep every 5 seconds.
You install the service with beep_srv.exe. This inserts the service into the service control manager's (SCM) database and loads the service. You must start the service manually in Services window in 30 seconds after loading. You can pause and continue the service there. If you stop the service, it is removed from the memory. With remove.exe you remove the service from the SCM database.
The web site below explains the code which was written in C++.
Reference: http://www.rdbooks.com/store/products/chapter/ntprch11.htm
Read about NT services also in: http://devcentral.iftech.com/learning/tutorials/mfc-win32/nt/3.asp

This is a port of a NT service sample program published in msj. It consist of a client and a server program.
The server creates a pipe and waits for a client to use the pipe to get the
time from the server. You install the service from the command line: timesrv -install. This inserts the service into the service control manager's (SCM) database and loads the service. You must start the service manually in Services window in 30 seconds after loading. You can pause and continue the service there. If you stop the service, it is removed from the memory. With timeserv -remove you remove the service from the SCM database. I let the error checking in the code.
The web sites below explain the code which was written in C++.
Reference: http://msdn.microsoft.com/msj/1097/WINNT.htm
http://msdn.microsoft.com/msj/0298/service.htm
http://msdn.microsoft.com/msj/0298/servicetextfigs.htm
Read about I/O completion ports in: http://www.sysinternals.com/comport.htm

I am learning COM (Component Object Model) . I suggest everybody should start learning with the client e.g. this one,
which uses the ActiveDesktop
Interface to display the name of your wallpaper file and makes in c: a shortcut to that file. It's the port of Michael Dunn's
excellent tutorial.
Reference: http://www.codeproject.com/com/comintro.asp and "Accessing COM Object from Assembly" in
\masm32\com\docs.

This is another client program which shows the non-folder items on your desktop. It uses a slow
routine to display the icons in the listview. The carcass is by Bill T., but he did not complete it. He is lazy!
See: http://thunder.prohosting.com/~asm1/articles/com_1.txt

Here is a simple server program which derives from IUnknown interface and only adds one method: the client can use
the method to display a Text in the message box. You should read Michael Dunn's excellent tutorial. I reused a lot of Ernie's code.
To be able to use the server you must register the server with r.bat; with u.bat you unregister the server. Msgboxcl.exe is the
client.
Reference: http://www.codeproject.com/com/comintro2.asp

A server program which implements IShellExtInit and IContextMenu interfaces: If you right click on a filename in explorer and
choose the "Testmenu" from the popup menu, a messagebox with the filename is displayed. I minimized Andycar's more complex code to the essential stuff.
You should read Michael Dunn's excellent tutorial. I again reused a lot of Ernie's code.
To be able to use the server you must register the server with r.bat; with u.bat you unregister the server.
Reference: http://www.codeproject.com/com/comintro2.asp
Nancy W. Cluts, Programming the Windows 95 User Interface, Redmond 1995

A server program which implements IShellExtInit and IShellPropSheetExt interfaces: If you right click on a filename in explorer and
choose "Properties" from the popup menu, you see the added property page (My Properties). It is displayed for all files (*) and
the page only shows a radio button control (I reused an old code).
You should read Michael Dunn's excellent tutorial. I again reused a lot of Ernie's code.
To be able to use the server you must register the server with r.bat; with u.bat you unregister the server.
Reference: http://www.codeproject.com/com/comintro2.asp
Nancy W. Cluts, Programming the Windows 95 User Interface, Redmond 1995