Friday, February 21, 2020 | Toby Opferman

WIN32 Programming for TASM Part 3

Toby Opferman

                        Win32 Assembly Advanced Tutorial
                                    (TASM v5.0)
                      "Callbacks, Compiles and Resources!"

        You know how to create structures, you know how to define functions and data types.
You know how to create a WinMain and how to define a Callback function.  Now, you are ready
to Finish the callback, define your resources and Compile this piece of shit!

I have basically told you the jist of this, it goes the same for Dialog Call back procs.
If you want a good example, go to the Code Section
and download the WINPONG.ASM source code.  There is not really anything more to tell you,
you just have to know windows API now and how to program in Windows.  You should get a good
windows book that teaches windows.  It doesn't matter if it's in C, from what you know,
you should be able to convert.  Also, look over the WINPONG.ASM as an example as well
as WAP32.ASM that comes with tasm.

  Resources are tricky with TASM, but once you figure it out you're fine.  TASM comes with
BRC.EXE, which will compile resources into .RES BUT, it requires the C header files!  To learn
HOW to do a resource file, go get a C book that teaches how to make a resource or use a resource
editor.  But, it must be a certain format .RES for it to work.  I compiled my .RC with Watcom
C/C++ and it did not link in with TASM.  You must use MS's RC.EXE or Borland's BRC.EXE in order
for you to get the right format.  BRC.EXE lets me use the Watcom .h's but I had to comment out
2 lines where it did a #DEFINE PURE in one of the headers.  Whatever compiler you have, you 
may be able to compile your resource file like this.  How ever you make the resource file,
just make sure you get a .RES form of it, that is what you need to link it to tasm.

Now, in order for your resource to work, you can't use Text Titles!  I know in Watcom and VC++,
(For those who write their own resource files) do a MyIcon ICON x.ico  You can't do this when
you link to assembly.  They must be numbers.

#define MyIcon 101

MyIcon ICON x.ico

That is how you do it to link it to assembly.  Then, in your assembly programs

 MyIcon equ <101>

And just do

 PUSH L MyIcon
 PUSH [hInstance]
 CALL LoadIcon
It's that simple.  You must reference ICON's, Bitmap's and other included resources like this.

But Menu's and Dialog boxs can be referenced the same old way.


 Mymenu MENU
 Menu  db 'Mymenu', 0
 MOV [WC.clsLpszMenuName], OFFSET Menu

Now you have your source code, your .RES and you're all set to compile.

 Simple.  Tasm comes with a MAKEFILE for WAP32, all you need to do is modify it!
 Copy this into the directory with your code.
 Now, all you have to do is:
 Where is says

change that to
NAME = Whateveryourprogramis

Next, look underneath it.

OBJS = $(NAME).obj
DEF  = $(NAME).def

Now, if you have a resource, add this line with the rest of them:

(Make sure your resource is the same name as your program.  prog.res, prog.rc, prog.asm, etc.)

last thing you do if you have a .RES, is add to the end of the tlink32 line:

  tlink32 /Tpe /aa /c $(LINKDEBUG) $(OBJS),$(NAME),, $(IMPORT), $(DEF), $(RES)

Now, you must get WAP32.DEF and rename it yourprogname.DEF

Open up the file and change what is appropriate.

The Name part and the Description part you probably want to change.

That's it.  Look in the file, you can do:


for no debug info and compile it.


for debug info, just like the comments say.

And that's it, you can compile and run.
You may get 2 error messages about heapsize error, I just ignore those.

Of course, you can try to fix it but the linker usually fixes that itself.
They have to do with the .DEF file's defines of the heapsize.

Congratulations, you have now finished the 3 part course on how to make windows assembly
programs.  This was a basic tutor that took you step by step using TASM v5.0 on how to
create assembly programs in Win32 from the ground up.  Now, the rest is up to you.  There
are other resources on the net if you need them.  Mostly, if you have grasped all the
information provided within these series, the only questions you have should only like
within Win32 itself.  All you need is the structure defines, the Win32 API function 
descriptions and how to do things in Win32.   All your questions should not be in Assembly,
they should be general Win32 questions.  Although some may be deeper into the Win32 API
than a C programmer would know (i.e. structure definitions) since
they do not have to make WINDOWS.H like you did WIN32.INC.

Well, I hope you learned something!

About Toby Opferman

Professional software engineer with over 15 years...

Learn more »
Codeproject Articles

Programming related articles...

Articles »

Resume »

Email: codeproject(at)opferman(dot)com