News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Using VC++2005 with msvcrt.dll

Started by Manos, January 31, 2013, 08:11:50 AM

Previous topic - Next topic

Manos

Hi.

VC++2005 and later have newr compilers and linkers than the VStudio6.0.
Also it has a better intelligence and the ability to make your own wizards.
But if you build a Win32 application, using their libraries statically (/MT), you will find that the .exe is
bigger in size than the old one written with VS6 because the newr libraries are bigger.
If you choice to link dynamically (/MD), you will find that the linker will link your
project with msvcr80.dll that has size about 612 KBs.
The same happen when use VC++2008 e.t.c. These will link with msvcr90.dll and so on.
Therefore, you must distribute the above DLLs because these does not belongs on the System.
But what you can do if you wish to use VC++2005 and the simple msvcrt.dll that
is part of the system from Win2000 and later ? This DLL is a system DLL and run always.
I made this question to myself and after one day I found the solution.
I copied the Include and Libraries files from my VStudio 6.0 and I included these in a new directory named MySDK.
After I puted MySDK in the same directory that belongs the PlatformSDK.
Then I opened VC++2005 and from menu Tools--->Options I selected Project and Solutions-->
-->VC++ Directories and I made two new directories: One for include files named $(VCInstallDir)MySDK\include
and one for libraries files named $(VCInstallDir)MySDK\lib.
After I moved my new directories on the top of listbox using the Up-Down arrows.
This is the trick.
When you build a project, the linker begins the search in order from Top to Bottom to find
the appropriate include and libraries files.
The linker find the first my own include and libraries and stop there, linking my project with msvcrt.dll.
That's ALL. My project use only msvcrt.dll.

The only restriction is that you must have the Include and Libraries files of VStudio 6.0.

Manos.

dedndave

seems to me that you could use the include and import library from the masm32 package
may have a little issue with names, but i am sure there is a simple solution to that

Vortex

Hi Manos,

Thanks for posting your method. :t

bomz

msvcrt.dll - only one usefull C dll? the different version of it is compatible?

Manos

I ran a simple project that use this DLL, in Win7 64 bits and it works fine.

Manos.

bomz

http://implib.sourceforge.net/index.html
crazy method with fasm - but full automatic dll -> lib. lib makes about 2-3 minutes
Quote@echo off
color 9F
dll2def /COMPACT c:\windows\system32\msvcrt.dll
SetLocal EnableDelayedExpansion
for /f "tokens=1,2,3 delims= " %%i in (msvcrt.def) do (

set string=%%k
set string=!string:~0,1!
if not "!string!"=="?" (

if not %%i==include (
if not %%i==endlib (
echo %%i %%j %%k, _imp_%%k>>temp.tmp
) else (
echo %%i>>temp.tmp
)
) else (
echo %%i 'implib.inc'>>temp.tmp
)

)
)
del msvcrt.def
ren temp.tmp msvcrt.def
fasm msvcrt.def msvcrt.lib
pause

But I see that some handly making lib includes decorated names inside like
Quote??0__non_rtti_object@@QAE@ABV0@@Z
??0__non_rtti_object@@QAE@PBD@Z
??0bad_cast@@AAE@PBQBD@Z
??0bad_cast@@QAE@ABQBD@Z
??0bad_cast@@QAE@ABV0@@Z
??0bad_cast@@QAE@PBD@Z
I undecorated them but don't know what do with them - I miss them now

ps. don't forget about \src\implib.inc


just drag and drop msvcrt.dll on this batch file
@echo off
color 0a
if "%~1"=="" exit /b
cd %~dp1
\masm32\bin\dumpbin.exe /EXPORTS %~nx1 /out:%~n1.txt
for /f "skip=15 tokens=4 delims= " %%i in (%~n1.txt) do echo %%i>>%~n1.def
SetLocal EnableDelayedExpansion
echo LIBRARY %~n1>>temp.tmp
for /f "delims=" %%i in (%~n1.def) do (
set string=%%i
set string=!string:~0,1!
if not "!string!"=="?" (
echo EXPORTS %%i>>temp.tmp
)
)
del %~n1.def
ren temp.tmp %~n1.def
\masm32\bin\link.exe -lib /machine:ix86 /def:%~n1.def
pause

bomz

#6
Quote@echo off
color 0a
if "%~1"=="" exit /b
cd %~dp1
\masm32\bin\dumpbin.exe /EXPORTS %~nx1 /out:%~n1.txt
for /f "skip=15 tokens=4 delims= " %%i in (%~n1.txt) do echo %%i>>%~n1.def
SetLocal EnableDelayedExpansion
echo LIBRARY %~n1>>temp.tmp
for /f "delims=" %%i in (%~n1.def) do (
set string=%%i
set string=!string:~0,1!
if not "!string!"=="?" (
echo EXPORTS %%i>>temp.tmp
) else (
echo %%i>>%~n1.inf
)
)
del %~n1.def
ren temp.tmp %~n1.def
\masm32\bin\link.exe -lib /machine:ix86 /def:%~n1.def
echo  ; ------------------------------------------>%~n1.inc
echo  ; prototypes for EXPORT %~n1 functions>>%~n1.inc
echo  ; ------------------------------------------>>%~n1.inc
echo.>>%~n1.inc
echo    c_%~n1 typedef PROTO C :VARARG>>%~n1.inc
for /f "skip=1 tokens=2 delims= " %%i in (%~n1.def) do (
echo    externdef _imp__%%i:PTR c_%~n1>>%~n1.inc
echo    crt_%%i equ ^<_imp__%%i^>>>%~n1.inc
echo.>>%~n1.inc
)
del %~n1.exp
pause
http://s004.radikal.ru/i205/1302/17/fb4daaae7d97.gif
Quote@ECHO OFF
COLOR 9F
SetLocal EnableDelayedExpansion
for /f "delims=" %%i in (msvcrt.inf) do (
for /f "skip=4 tokens=1 delims=" %%a in ('undname.exe %%i') do (
set string=%%a
set string=!string:~7,-1!
echo !string!>>msvcrt.ini
)
)
pause
If open KMDKit wdmsec.lib make Four-F in notepad, you may see this undecorated names in it. may be C linker/compiller need to make all corectly

bomz

may be somebody may show example how use ordinal in INC file for MASM?
Quote; KERNEL32.AddVectoredExceptionHandler ORD:9
   ; -> NTDLL.RtlAddVectoredExceptionHandler
   implib kernel32.dll, AddVectoredExceptionHandler


japheth

Quote from: bomz on February 01, 2013, 08:34:27 PM
may be somebody may show example how use ordinal in INC file for MASM?
Quote; KERNEL32.AddVectoredExceptionHandler ORD:9
   ; -> NTDLL.RtlAddVectoredExceptionHandler
   implib kernel32.dll, AddVectoredExceptionHandler


Your question is pretty off-topic, IMO - to capture a thread this way is regarded as impolite.

The question "how use ordinal in INC file" is unclear. In Masm, you cannot define an external as a number, you always need a name. You can, however, force the linker to import the externals "by number". For this to happen you'll need to create the import lib in a special way. See this excerpt of a kernel32.def ( used for Win9x ):


LIBRARY KERNEL32

EXPORTS
VxDCall0            @1  NONAME
VxDCall1            @2  NONAME
VxDCall2            @3  NONAME
VxDCall3            @4  NONAME
VxDCall4            @5  NONAME
VxDCall5            @6  NONAME
VxDCall6            @7  NONAME
VxDCall7            @8  NONAME
VxDCall8            @9  NONAME


If you make an import lib from this .DEF, the names will be hidden. If the import lib is later used to fix external references, the linker will have to import "by ordinal".


bomz

I confused yesterday with this http://masm32.com/board/index.php?topic=1401.0
read it / post hear

It is impossible in INC file to change name for ordinal number?

bomz

I made such DEF and compare libs with fc /b there is no any difference

LIBRARY msvcrt
EXPORTS $I10_OUTPUT  @1 NONAME
EXPORTS _CIacos  @2 NONAME
EXPORTS _CIasin  @3 NONAME
EXPORTS _CIatan  @4 NONAME
EXPORTS _CIatan2  @5 NONAME
EXPORTS _CIcos  @6 NONAME
EXPORTS _CIcosh  @7 NONAME
EXPORTS _CIexp  @8 NONAME
EXPORTS _CIfmod  @9 NONAME
EXPORTS _CIlog  @10 NONAME
EXPORTS _CIlog10  @11 NONAME
EXPORTS _CIpow  @12 NONAME
EXPORTS _CIsin  @13 NONAME
EXPORTS _CIsinh  @14 NONAME
EXPORTS _CIsqrt  @15 NONAME
EXPORTS _CItan  @16 NONAME
EXPORTS _CItanh  @17 NONAME
EXPORTS _CxxThrowException  @18 NONAME
EXPORTS _EH_prolog  @19 NONAME
EXPORTS _Getdays  @20 NONAME
EXPORTS _Getmonths  @21 NONAME


sory 1 byte difference in each proc

japheth

Quote from: bomz on February 01, 2013, 09:45:21 PM
It is impossible in INC file to change name for ordinal number?

Well, "impossible" is a rather strong word; many things that the average programmer might regard as impossible are very well possible for the knowledgeable coders, because things that look like a cruel constant to the first one became a friendly variable to the latter one.

Generally, on the assembler level, it is kinda "impossible" ( if "Masm" is a constant for you ) - you are restricted to LoadLibrary + GetProcAddress if you want to ensure that a function is imported by ordinal.

bomz

I want write in code name, but when code convert to bin proc calls with ordinal is it possible
QuoteImporting symbolic names by ordinal values. For example, there's a DLL function you want to call: MYDLL!dummy_function ORD:20. So, it's symbolic name is dummy_function while it's ordinal value is 20. Usually it's not a good idea to import a symbol by ordinal, since the ordinals may change between different versions of the same DLL. However, if you are sure the DLL version won't change or the developer of the DLL guarantees the backward compatibility of the ordinals (i.e. you are the developer of the DLL and you always keep the ordinals unchanged or you just distribute the same DLL version with your project), then you can benefit from using ordinals. Importing by ordinal significantly reduces the load time of the executable and makes the import section size smaller. Buy the way, if you plan to use always the same DLL build, consider binding your executables. Binding reduces the load time even more.
http://implib.sourceforge.net/EN.HTM

bomz

msvcrt.dll back compatible? If I make LIB from 7.0.7601.17744 it's be compatible with all previous version in system?

Vortex

Hi bomz,

Please stop posting questions to this nice thread created by Manos. Your questions are not associated with VC++ 2005 configuration.