News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

msvcrt include and library.

Started by hutch--, January 20, 2005, 09:44:49 AM

Previous topic - Next topic

GregL

Vortex,

Didn't you already do this once? What is the difference between your include and library and this one of Hutch's?

Vortex

Hi Greg,

My tool creates the include file form msvcrt.dll, plus Pelle's library manager creates an import library for this DLL

Vortex


MazeGen

 :eek

Great job, Vortex!
I wonder who is the author, because if is he Slovak (.sk), I can speak with him in my native language.

Now I'm happy I didn't convert it manually before :toothy

Mark Jones

Cool. My msvcrt.dll is different than these, so attached is an XP SP1 .lib and .inc zip, maybe it is useful. I can't imagine there being new procedures in each version of msvcrt? Neat tool Vortex. Is there any Win32.hlp for msvcrt? We really need something like that. And http://uemake.szm.sk/ appears to be down.


msvcrt.dll v7.0.2600.1106: WinXP SP1, 315 KB (323,072 bytes)
msvcrt.lib, 142 KB (145,662 bytes)

Pelle's POLIB reported:
  POLIB: warning: '_exit' already defined in 'msvcrt.dll'; ignoring definition in 'msvcrt.dll'.
  POLIB: warning: '__imp__exit' already defined in 'msvcrt.dll'; ignoring definition in 'msvcrt.dll'.
  POLIB: warning: '_strerror' already defined in 'msvcrt.dll'; ignoring definition in 'msvcrt.dll'.
  POLIB: warning: '__imp__strerror' already defined in 'msvcrt.dll'; ignoring definition in 'msvcrt.dll'.
  POLIB: warning: '_tolower' already defined in 'msvcrt.dll'; ignoring definition in 'msvcrt.dll'.
  POLIB: warning: '__imp__tolower' already defined in 'msvcrt.dll'; ignoring definition in 'msvcrt.dll'.
  POLIB: warning: '_toupper' already defined in 'msvcrt.dll'; ignoring definition in 'msvcrt.dll'.
  POLIB: warning: '__imp__toupper' already defined in 'msvcrt.dll'; ignoring definition in 'msvcrt.dll'.

Removed from msvcrt.inc due to [apparent] naming conflicts:
  abs PROTO C :VARARG
  atol PROTO C :VARARG
  div PROTO C :VARARG
  exit PROTO C :VARARG
  fabs PROTO C :VARARG
  isalpha PROTO C :VARARG
  islower PROTO C :VARARG
  isupper PROTO C :VARARG
  strcat PROTO C :VARARG

[attachment deleted by admin]
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

James Ladd

I think it is great we are helping each other, but the concern I have is that the proto's are not
correct. Does someone go back and fix these up ?

Vortex

Hi Mark,

Here is uemake's zip file.

I posted the links for the msvcrt reference, you can check page 1 of this topic.

[attachment deleted by admin]

Xor Stance

Quote from: MazeGen on January 21, 2005, 11:47:29 AM
Hi Wortex,

Quote from: Vortex on January 21, 2005, 11:38:05 AM
To get the real prototypes, you can convert the .h files manually

Huh, it could be a lot of work - more than 700 functions...

Quote from: VortexProbably, it would be interesting to code a tool automating the conversion process.

There's no sort of h2inc for such files already?

I Installed the Vc pp5 for Visual Studio, and in the masm reference mention about it. And I can't upload it because it's only license to vb owners,
:lol unless you show me a screenshot that yo own the v studio. 

I have one doubt, what if I replace the ml 6.15 in the masm32; will it work fine? or it modifies something. And the ml it's included witha file called ml.err
Looks like it's a listing errors.

Mark Jones

#23
Don't delete the ml.err file, or ML error messages will be blank! (Some file-cleaning programs delete .err files...) I set mine to Read-Only.

Striker, yes but it looks like Uemaker's msvcrt.inc has all the prototypes correctly defined. :)

Aah Vortex, yes the MSDN page does have info, thanks.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

MichaelW

Quote from: Mark Jones on March 06, 2005, 09:35:41 PM
Striker, yes but it looks like Uemaker's msvcrt.inc has all the prototypes correctly defined.

The ones that are there do seem to be correctly defined, but some are missing (_errno, _matherr, __setusermatherr, and possibly others). IMO, in the absence of easily accessible help, the prototypes should include the Microsoft-documented names for the parameters.
eschew obfuscation

GregL

#25
Here is a program I wrote to test using MSVCRT from MASM32, I used the include and lib Hutch posted. I was getting conflicts with MASM32.LIB so I used only MSVCRT and Win32 functions and cut and pasted the macros. I thought someone might find it interesting.

; Time64CRT.asm
    .486
    .model flat, stdcall
    option casemap :none
   
    include c:\masm32\include\windows.inc
    include c:\masm32\include\kernel32.inc
    includelib c:\masm32\lib\kernel32.lib
   
    include    c:\masm32\msvcrt\msvcrt.inc
    includelib c:\masm32\msvcrt\msvcrt.lib
           
    main PROTO
    _difftime64 PROTO pTime1:PTR QWORD, pTime2:PTR QWORD, pDiff:PTR REAL8
    WaitKeyCrt PROTO
                             
    ; ---------------------
    ; literal string MACRO
    ; ---------------------
    literal MACRO quoted_text:VARARG
        LOCAL local_text
        .data
            local_text db quoted_text,0
        align 4
        .code
            EXITM <local_text>
    ENDM
    ; --------------------------------
    ; string address in INVOKE format
    ; --------------------------------
    SADD MACRO quoted_text:VARARG
        EXITM <ADDR literal(quoted_text)>
    ENDM
       
    __timeb64 STRUCT 8
        time     QWORD   0
        millitm  WORD    0
        timezone SWORD   0
        dstflag  SWORD   0
    __timeb64 ENDS
   
    tm STRUCT 4
        tm_sec   SDWORD   0     ; seconds after the minute - [0,59]
        tm_min   SDWORD   0     ; minutes after the hour - [0,59]
        tm_hour  SDWORD   0     ; hours since midnight - [0,23]
        tm_mday  SDWORD   0     ; day of the month - [1,31]
        tm_mon   SDWORD   0     ; months since January - [0,11]
        tm_year  SDWORD   0     ; years since 1900
        tm_wday  SDWORD   0     ; days since Sunday - [0,6]
        tm_yday  SDWORD   0     ; days since January 1 - [0,365]
        tm_isdst SDWORD   0     ; daylight savings time flag
    tm ENDS
           
.data

    align 8
    time1     QWORD     0
    time2     QWORD     0
    diff      REAL8     0.0
    day       REAL8     86400.0  ; 60*60*24
    days      REAL8     0.0
    tstruct   __timeb64 <0>
    align 4
    hmodule   DWORD     0
    pxmas     DWORD     0
    ptzname   DWORD     0
    tmpbuf    BYTE      128 dup(0)
    ampm      BYTE      "AM", 0
    newline   BYTE      13, 10, 0
           
.code

start:

    invoke main
    invoke WaitKeyCrt
    invoke _exit, 0

main  PROC uses edi

    invoke _tzset
    invoke printf, SADD("%s"), OFFSET newline
    invoke printf, SADD("64-bit Time and Date Functions - C Run-time Library")
    invoke printf, SADD("%s"), OFFSET newline       
    invoke _strtime, OFFSET tmpbuf
    invoke printf, SADD(" OS time:                            %s"), OFFSET tmpbuf
    invoke printf, SADD("%s"), OFFSET newline
    invoke _strdate, OFFSET tmpbuf
    invoke printf, SADD(" OS date:                            %s"), OFFSET tmpbuf
    invoke printf, SADD("%s"), OFFSET newline
    invoke _time64, OFFSET time1
    invoke printf, SADD(" Time in seconds since UTC 1/1/1970: %I64d"), OFFSET time1
    invoke printf, SADD("%s"), OFFSET newline
    invoke _ctime64, OFFSET time1
    invoke printf, SADD(" Time and date string:               %s"), eax
    invoke _gmtime64, OFFSET time1
    invoke asctime, eax
    invoke printf, SADD(" Coordinated universal time:         %s"), eax
    invoke _localtime64, OFFSET time1
    mov edx, (tm PTR [eax]).tm_hour
    .if edx >= 12
        push eax
        push edx
    invoke strcpy, OFFSET ampm, SADD("PM")
    pop edx
    pop eax
    sub edx, 12
    mov (tm PTR [eax]).tm_hour, edx
    .endif
    mov edx, (tm PTR [eax]).tm_hour
    .if edx == 0
        mov (tm PTR [eax]).tm_hour, 12
    .endif
    invoke asctime, eax
    add eax, 11
    invoke printf, SADD( " 12-hour time:                       %.8s %s"), eax, OFFSET ampm
    invoke printf, SADD("%s"), OFFSET newline
    invoke _ftime64, OFFSET tstruct
    movsx eax, tstruct.millitm 
    invoke printf, SADD(" Plus milliseconds:                  %u"), eax
    invoke printf, SADD("%s"), OFFSET newline
    xor edx, edx
    movsx eax, tstruct.timezone
    mov ecx, 60
    div ecx
    invoke printf, SADD(" Zone difference in hours from UTC:  %u"), eax
    invoke printf, SADD("%s"), OFFSET newline
    invoke GetModuleHandle, SADD("MSVCRT")
    mov hmodule, eax
    invoke GetProcAddress, hmodule, SADD("_tzname")
    .if tstruct.dstflag == 0
        mov edx, [eax+0] 
        mov ptzname, edx
    .else
        mov edx, [eax+4] 
        mov ptzname, edx
    .endif
    invoke printf, SADD(" Time zone name:                     %s"), ptzname
    invoke printf, SADD("%s"), OFFSET newline
    invoke printf, SADD( " Daylight savings:                   ")
    movsx eax, tstruct.dstflag
    .if eax == 0
        invoke printf, SADD("False")
    .else
        invoke printf, SADD("True")
    .endif
    invoke printf, SADD("%s"), OFFSET newline               
    invoke _localtime64, OFFSET time1
    invoke strftime, OFFSET tmpbuf, SIZEOF tmpbuf, SADD("%A, %B %d, %Y"), eax
    invoke printf, SADD(" Today is:                           %s"), OFFSET tmpbuf
    invoke printf, SADD("%s"), OFFSET newline
    invoke _localtime64, OFFSET time1
    mov edx, 11                     ; December
    mov (tm PTR [eax]).tm_mon, edx
    mov edx, 25                     ; 25th
    mov (tm PTR [eax]).tm_mday, edx
    mov edx, 12                     ; 12:00 noon   
    mov (tm PTR [eax]).tm_hour, edx
    mov edx, 0
    mov (tm PTR [eax]).tm_min, edx
    mov edx, 0
    mov (tm PTR [eax]).tm_sec, edx
    mov edx, 0
    mov (tm PTR [eax]).tm_wday, edx
    mov edx, 0
    mov (tm PTR [eax]).tm_yday, edx
    mov edx, 0
    mov (tm PTR [eax]).tm_isdst, edx
    mov pxmas, eax
    invoke _mktime64, eax
    mov SDWORD PTR [time2+0], eax
    mov SDWORD PTR [time2+4], edx
    .if eax != -1 && edx != -1
        invoke strftime, OFFSET tmpbuf, SIZEOF tmpbuf, SADD("%A, %B %d, %Y"), pxmas
        invoke printf, SADD(" Christmas this year:                %s"), OFFSET tmpbuf
        invoke printf, SADD("%s"), OFFSET newline
    .endif
    invoke _difftime64, OFFSET time1, OFFSET time2, OFFSET diff
    finit
    fld diff
    fld day
    fdiv
    fstp days
    invoke printf, SADD(" Days until Christmas:               %.0lf"), days
    invoke printf, SADD("%s"), OFFSET newline
    ret
main  ENDP

_difftime64 PROC pTime1:PTR QWORD, pTime2:PTR QWORD, pDiff:PTR REAL8
    ; MS Visual C Run-time Library does not have a _difftime64 function so...
    mov     eax, pTime1
    mov     edx, pTime2
    finit                   ; initialize FPU
    ; compare Time1 with Time2
    fild    QWORD PTR [edx] ; st(0) = Time2
    fild    QWORD PTR [eax] ; st(0) = Time1, st(1) = Time2
    fcompp                  ; compare st(0) with st(1) and pop both registers
    fstsw   ax              ; retrieve comparison result in the AX register
    fwait                   ; insure the previous instruction is completed
    sahf                    ; transfer the condition codes to the CPU's flag register
    jb      st0_less        ; only the C0 bit (CF flag) would be set if no error
st0_greater:                ; Time1 > Time2
    ;Subtract Time2 from Time1 to calculate the number of seconds difference
    mov     eax, pTime1
    mov     edx, pTime2
    fild    QWORD PTR [eax]
    fild    QWORD PTR [edx]
    fsub
    mov     eax, pDiff
    fstp    REAL8 PTR [eax]
    fwait
    jmp     @F
st0_less:                  ; Time2 > Time1
    ;Subtract Time1 from Time2 to calculate the number of seconds difference
    mov     eax, pTime2
    mov     edx, pTime1
    fild    QWORD PTR [eax]
    fild    QWORD PTR [edx]
    fsub
    mov     eax, pDiff
    fstp    REAL8 PTR [eax]
    fwait
@@:
ret
_difftime64 ENDP

WaitKeyCrt PROC
    invoke printf, SADD("%s"), OFFSET newline
    invoke printf, SADD("Press any key to continue...")
    invoke _getch
    ret
WaitKeyCrt ENDP

END start