Testing the msvcrt functions of the windows.sdk

Started by ToutEnMasm, February 19, 2008, 04:36:52 PM

Previous topic - Next topic

ToutEnMasm

Hello,
I am testing them following a reference with many simple samples:
http://www.warpspeed.com.au/cgi-bin/inf2html.cmd?..\html\book\IBMVACPP\CPPLIB.INF
It seems that it just work.

Sample of use (console):
Quote
                include C:\masm32\sdk\translate.inc
   include C:\masm32\sdk\stdio.sdk
   include C:\masm32\sdk\stdlib.sdk   
   includelib C:\PROGRA~1\MICROS~1.0\VC\lib\libcmt.lib   
   includelib C:\PROGRA~1\MICROS~1.0\VC\lib\OLDNAMES.lib
.data
formatDecimal db "The result of _itoa(-255) with radix of 10 is %s",13,10,0
formatBinaire db "le résultat de _itoa(-255) en binaire est %s",13,10,0
formatHexadecimal db "The result of _itoa(-255) with radix of 16 is %s",13,10,0
.code
main PROC C un:DWORD,deux:DWORD
   local buffer[35]:BYTE
   local p:DWORD
   ;-------------------------------------------
    invoke _itoa,-255, addr buffer, 10
   mov p,eax 
   invoke printf,addr formatDecimal, p
   ;------------------------------------------
   invoke _itoa,-255,addr buffer, 2
   mov p,eax
   invoke printf,addr formatBinaire, p
   ;-------------------------------------------------   
   invoke _itoa,-255, addr buffer, 16
   mov p,eax
   invoke printf,addr  formatHexadecimal, p
   comment µ
/****************************************************************************
The output should be:

The result of _itoa(-255) with radix of 10 is -255
The result of _itoa(-255) with radix of 2
is 11111111111111111111111100000001
The result of _itoa(-255) with radix of 16 is ffffff01
****************************************************************************/
      µ      
   mov eax,0   
ret
main endp
end

Some names of functions are reserved words for masm as
Quote
idiv
_beep
fabs
unlink
dup
To solve the problem,link dynamically to them
Quote
   Pcrt_fabs TYPEDEF PROTO C :QWORD
   Fcrt_fabs TYPEDEF PTR Pcrt_fabs
   crt_fabs TEXTEQU <Fcrt_fabs ptr Acrt_fabs>
.data
Acrt_fabs dd 0
; fabs extract the absolute value of a real
Those functions are in the ntdll.dll
the GetProcAddress funtion give the adress to place in Acrt_fabs

For other functions,just replace the chain crt_fabs by another in all the strings.