News:

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

Main Menu

In what library is printf found in VS 2022?

Started by markallyn, October 27, 2021, 05:45:58 AM

Previous topic - Next topic

markallyn

Hello everyone,

I've searched lots of places, wanting to avoid cluttering up the forum with stupid questions, but with no luck.  So here's my stupid question:  having just downloaded VS 2022 and trying to run a simple program calling printf  it seems that msvcrt.lib no longer contains the function.  So, could someone kindly tell me where printf now resides in VS 2022?

Mark Allyn


markallyn

Good afternoon, Jochen,

The source code I'm using does an "includelib ucrt.lib", but it doesn't seem to "know" a naked printf.  I've looked at ucrt.lib and the references to printf in that file are prefixed by some new __imp .... code.  Is there something I should be adding to the front end of my printf in order for the proto and call statements to work?

But, anyway, thanks for the help.  I'll have to experiment a bit, it appears.

Mark

hutch--

Mark,

You go to the DLL file and see what is in it. If its there, you should know how to call it. These are the joys of starting to use newer code sources, you have to find every thing yourself.

markallyn

Good evening, Hutch,

I was telling myself precisely that, your bit about the joys of starting to use new code sources, as I dumped and peeled thru ucrt.lib and ucrtbase.dll.  Says I : Son, this is a really great way to see what's inside these fellers.  Always wanted to know.  I'm still peeling ....  And garnering great joy.

Regards,
Mark

mineiro

Functions inside library files have a prefix (__imp_) before function name as you noted, , __imp_ExitProcess, __imp_MessageBoxExA, ... .
You can use this as a skeleton to your tests, it's necessary to create a library (.def,externdef) file to print.
test64.asm

OPTION DOTNAME
option casemap:none

includelib kernel32.lib
EXTERNDEF ExitProcess: PROC     ;proc or proto, I suppose proc is better
                                ;__imp_ExitProcess inside kernel32.lib
includelib user32.lib
EXTERNDEF MessageBoxExA: PROTO  ;__imp_MessageBoxExA inside user32.lib

;ALIAS <MessageBoxExA>=<MessageBox>
MessageBox TEXTEQU <MessageBoxExA>

public start
;public MainCRTStartup

.data
    caption db 'testing!!!', 0
    message db 'If works!', 0

.code
start:
    sub    rsp,28h      ; shadow space, align stack
    mov    rcx, 0       ; hWnd = HWND_DESKTOP
    lea    rdx, message ; LPCSTR lpText
    lea    r8,  caption ; LPCSTR lpCaption
    mov    r9d, 0       ; uType = MB_OK
    call   MessageBox   ; call MessageBox API function
    mov    ecx, eax     ; uExitCode = MessageBox(...)
    call   ExitProcess

ALIAS <mainCRTStartup>=<start>         ;;console
;ALIAS <WinMainCRTStartup>=<start>      ;;windows
end


user32.def

LIBRARY user32.dll
EXPORTS
MessageBoxExA


kernel32.def

LIBRARY kernel32.dll
EXPORTS
ExitProcess


doit.bat

lib /MACHINE:AMD64 /DEF:kernel32.def
lib /MACHINE:AMD64 /DEF:user32.def
ml64 /c test64.asm
link /SUBSYSTEM:CONSOLE /machine:AMD64 test64.obj
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

jj2007

Quote from: markallyn on October 27, 2021, 10:14:46 AMas I dumped and peeled thru ucrt.lib and ucrtbase.dll

On my Win7-64, there is no printf in C:\Windows\System32\ucrtbase.dll, unfortunately.

hutch--


TimoVJL

in ucrt printf is just an inline function and since msvc 2015 it was removed from msvcrt.lib_Check_return_opt_
_CRT_STDIO_INLINE int __CRTDECL printf(
    _In_z_ _Printf_format_string_ char const* const _Format,
    ...)
#if defined _NO_CRT_STDIO_INLINE
;
#else
{
    int _Result;
    va_list _ArgList;
    __crt_va_start(_ArgList, _Format);
    _Result = _vfprintf_l(stdout, _Format, NULL, _ArgList);
    __crt_va_end(_ArgList);
    return _Result;
}
#endif
May the source be with you

jcfuller

Does this help?
https://gist.github.com/njsmith/08b1e52b65ea90427bfd

James

mineiro

You can try "Dependency Walker" program to check.
https://www.dependencywalker.com/

I stopped in windows XP, but I remember that most dll functions are based in ntdll.dll or use some variations of functions inside this dll.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

markallyn

Good morning, Hutch, mineiro, JJ, JCFuller,TIMOVJL,

Hutch's masm32/lib64/msvcrt.lib does indeed contain __imp_printf.  None of the other msvcrt's I have examined in windows kits or VS 2022 have this function.  This is consistent with JJ's observation in his most recent response.  TIMOVJL:  I don't "get" what you mean when you refer to "inlining"--not your fault, I'm just too much a beginner.  Perhaps you could enlarge for my benefit? 

In the meantime, I notice that four more responses to my query have come in.  I'll check them out.

Thanks to all of you for taking the trouble to look this issue over.

Regards,
Mark

TimoVJL

Quote from: markallyn on October 28, 2021, 12:06:40 AM
  TIMOVJL:  I don't "get" what you mean when you refer to "inlining"--not your fault, I'm just too much a beginner.  Perhaps you could enlarge for my benefit? 
It is similar like masm32 macros, that inserts some longer code.
May the source be with you

jj2007

Actually, I wouldn't touch that UCRT crap with a bargepole. It's so full of bugs and errors that they had to set up an Urgent Community Response Team :cool:

nidud

#14
deleted