News:

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

Complete msvcrt library and include file.

Started by hutch--, May 15, 2005, 05:44:07 AM

Previous topic - Next topic

Vortex

Hi Hutch,

Thanks for your kind words. If it's possible, can you test the demo application on Win 2000? I builded the import library and the demo on a XP SP2 machine.

Vortex

Unfortunately, the method of associating ordinals with function names is not portable. Xp and Win 2000 are providing different sets of ordinal numbers for a same named DLL.

Another problem is that MS link ( and polink ) doesn't seem to support aliases for function names :

LIBRARY msvcrt
EXPORTS
crt_$I10_OUTPUT=$I10_OUTPUT
crt__CIacos=_CIacos
crt__CIasin=_CIasin
crt__CIatan=_CIatan


dlltool, the librarian from the MinGW package accepts aliases and it creates the import library.
Building the import library :

\MinGW\bin\dlltool -d msvcrt.def -l msvcrt.lib

Building the example code :

\masm32\bin\ml /c /coff Demo.asm
\MinGW\bin\ld -e _start --subsystem console -o Demo.exe Demo.obj msvcrt.lib \masm32\lib\kernel32.lib -s


Tools used :

dlltool from binutils-2.15.91-20040904-1.tar
ld.exe from binutils-2.16.91-20060119-1.tar

[attachment deleted by admin]

Tedd


LIBRARY <dll_name>
EXPORTS
<exported_func1> [=<internal_func_name1>] [@<ordinal1>]
<exported_func2> [=<internal_func_name2>] [@<ordinal2>]
  .
  .

note the spaces as separators :wink
(square brackets indicate optional parameters)
No snowflake in an avalanche feels responsible.

Vortex

Tedd, inserting a space as separator doesn't solve the problem :

LIBRARY msvcrt
EXPORTS
crt_$I10_OUTPUT =$I10_OUTPUT
crt__CIacos =_CIacos
crt__CIasin =_CIasin
crt__CIatan =_CIatan
.
.


\masm32\bin\lib /OUT:msvcrt.lib /DEF:msvcrt.def

As a result, the import library will not contain symbols without the crt_ prefix, this is the problem. For example, you should be able to see two entries in the library, both of crt__CIasin and _CIasin Unfortunately, the librarian simply omits the function names after the symbol =

Tedd

Aah, sorry, it's not for 'aliases' like that, it's for exporting functions under different names, not for exporting the same function under two names.
No snowflake in an avalanche feels responsible.

Vortex

Quote from: Tedd on October 15, 2006, 08:00:54 PM
Aah, sorry, it's not for 'aliases' like that, it's for exporting functions under different names, not for exporting the same function under two names.

Unfortunately, link.exe lacks the feature of exporting the same function under two names, that's funny. You can do it easily with ld.exe

Vortex

The development tools of Digital Mars are accepting aliased names :

LIBRARY msvcrt
EXPORTS
_crt_$I10_OUTPUT = $I10_OUTPUT
_crt__CIacos = _CIacos
_crt__CIasin = _CIasin
_crt__CIatan = _CIatan
.
.

\dm\bin\implib msvcrt.lib msvcrt.def
\masm32\bin\ml /c /Cp Demo.asm
\dm\bin\link -NOD -ENTRY:_start -SU:CONSOLE -FIXE Demo.obj,Demo.exe,,msvcrt.lib

[attachment deleted by admin]

jdoe

Hi,

I have a question about msvcrt.inc (the one of masm32). It looks like there is functions in msvcrt.dll that are not using varargs as parameter.

_seh_longjmp_unwind@4
_seh_longjmp_unwind@4
__CxxLongjmpUnwind@4
_CxxThrowException@8

Does using "c_msvcrt typedef PROTO C :VARARG" can be applied anyway ? I'm not sure.

externdef _imp___seh_longjmp_unwind:PTR c_msvcrt
externdef _imp___seh_longjmp_unwind:PTR c_msvcrt
externdef _imp____CxxLongjmpUnwind:PTR c_msvcrt
externdef _imp___CxxThrowException:PTR c_msvcrt

::)

MichaelW

AFAIK vararg will work for any of them, as long as you pass workable parameters. At one time I attempted to create an include file that specified the parameters for all of the functions that do not take a variable number of parameters, along with some short comments indicating what the parameters are, but there are so many that I never finished.
eschew obfuscation

jdoe


Thanks Michael,

I'm working on a lib and inc creation batch for crt libraries and I wasn't sure what to do with those specific cases.   :red


Vortex

Hi Jdoe,

Here is msvcrt.def and msvcrt.inc coming with the GeneSys development package. They contain those functions you mentioned above.

[attachment deleted by admin]

Vortex

#26
I coded a simple tool rebuilding the .idata section storing the internal function names of import libraries. The procedure is easy, first build a long import library with MS link :

LIBRARY msvcrt
EXPORTS
.
.
crt__AdjustLocation
crt__AdjustStack
crt__CIacos
crt__CIasin
.
.


link -lib /OUT:msvcrt.lib /DEF:msvcrt.def /MACHINE:IX86
rebuildlib msvcrt.lib -l4


rebuildlib.exe will remove the leading crt_ tag from the internal function names found in the import library.
-l4 : 4 is the length of the the leading tag to remove.

A quick example :

.386
.model flat, stdcall
option casemap : none
     
ExitProcess PROTO :DWORD
crt_printf PROTO C :VARARG
crt_scanf PROTO C :VARARG
crt__strupr PROTO C :VARARG

includelib \masm32\lib\kernel32.lib
includelib msvcrt.lib

.data
text1 db 'Please type your name : ',0
text2 db 'Hello %s , nice to meet you :) ',0
format1 db '%s',0

.data?
buffer db 100 dup(?)

.code

start:

    invoke crt_printf,ADDR format1,ADDR text1
    invoke crt_scanf,ADDR format1,ADDR buffer
    invoke crt__strupr,ADDR buffer
    invoke crt_printf,ADDR text2,eax
    invoke ExitProcess,0

END start


The final executable will import the stripped forms of the C functions with the leading crt_ tag.

[attachment deleted by admin]

Vortex

Here is a new version of Dll2inc :

- Simplified cinvoke macro :

prC TYPEDEF PROTO C :VARARG

cinvoke MACRO func:REQ,args:VARARG

invoke prC PTR _&func,args

ENDM


- New example ( Demo2 ) with the syscall calling convention.

http://vortex.masmcode.com/files/Dll2inc13.zip

Vortex

Version 1.4
=======

- Added new switch -n emitting function names without double quotes in the def file.

http://vortex.masmcode.com/files/Dll2inc14.zip

Vortex

This is the latest version of the rebuilt msvcrt.lib  The previous release of the library didn't contain the functions conflicting with the MASM keywords, this version is fixing this issue.

[attachment deleted by admin]