Using libc.lib from Visual C++ Toolkit 2003 with Masm

Started by Vortex, November 19, 2005, 08:19:03 PM

Previous topic - Next topic

Vortex

Here is a simple example demonstrating the usage of libc.lib with Masm. This library comes with the free Visual C++ Toolkit 2003
.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\user32.inc
include     \masm32\include\masm32.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\masm32.lib
includelib  libc.lib ; CRT static library

strcat PROTO C :DWORD,:DWORD
strstr PROTO C :DWORD,:DWORD
strchr PROTO C :DWORD,:DWORD

.data
dest    db 'strcat example : ',0
        db 20 dup(0)
source  db 'Hello my friend',13,10,0
string2 db 'friend',0
crlf    db 13,10,0

.data?
buffer  db 20 dup(?)

.code

start:
invoke strcat,ADDR dest,ADDR source
invoke StdOut,ADDR dest
invoke strstr,ADDR dest,ADDR string2
call   print
invoke strchr,ADDR dest,114 ; look for 'r'
call   print
invoke ExitProcess,0

print   PROC
invoke dw2hex,eax,ADDR buffer
invoke StdOut,ADDR buffer
invoke StdOut,ADDR crlf
ret
print   ENDP

END start

[attachment deleted by admin]