News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Passing a structure

Started by Biterider, March 22, 2019, 05:36:44 AM

Previous topic - Next topic

Vortex

Reading that Twitter message, one can write a simplified version of printf. No need of other dependencies.

aw27

msvcrt.dll continues to be available in everyone's system32 folder, only for backwards compatibility.
We expect this to happen for a few more years.  :biggrin:
There are a few simplified alternatives to printf, but they are not as comprehensive by definition, which is desirable some times.


TimoVJL

msvcrt.dll is a Windows NT CRT DLL.
So system programs and dlls use it too.
Like about 1400 in Windows 7 and 1800  in Windows 10 in system32 folder.
May the source be with you

jj2007

Quote from: TimoVJL on April 03, 2019, 05:42:34 PM
msvcrt.dll is a Windows NT CRT DLL.
So system programs and dlls use it too.
Like about 1400 in Windows 7 and 1800  in Windows 10 in system32 folder.

But of course, M$ wants us to use the latest and most exotic flavour of the CRT. To make sure our programs don't run on obsolete Windows versions :icon_mrgreen:

aw27

We can replace "includelib \masm32\lib\msvcrt.lib" with:

includelib "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\ucrt\x86\ucrt.lib"
includelib "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.20.27508\lib\x86\legacy_stdio_definitions.lib"
includelib "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.20.27508\lib\x86\legacy_stdio_wide_specifiers.lib"

it works but we receive a warning in the end (instead of a warming congratulation for our great success):
warning LNK4210: .CRT section exists; there may be unhandled static initializers or terminators

jj2007

Quote from: AW on April 03, 2019, 06:09:45 PMincludelib "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.20.27508\lib\x86\legacy_stdio_wide_specifiers.lib"

Yes, that's what they want. But you can get practically the same service from a LoadLibrary("msvcrt"). Works on all Windows versions, from XP to 10.

aw27

Quote from: jj2007 on April 03, 2019, 07:38:50 PM
Quote from: AW on April 03, 2019, 06:09:45 PMincludelib "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.20.27508\lib\x86\legacy_stdio_wide_specifiers.lib"
Yes, that's what they want. But you can get practically the same service from a LoadLibrary("msvcrt"). Works on all Windows versions, from XP to 10.
I was talking about True MasmTM not High Level Languages or macro boosted variations.

jj2007


TimoVJL

As jj2007 mentioned, the dynamic way:
.386
.model flat, stdcall
includelib kernel32.lib

.data
sDll db 'msvcrt',0
sFunc db 'printf',0
sMsg db 'Hello ASM',13,10,0

.code
_mainCRTStartup:
push ebp
mov ebp, esp
sub esp, 4h ; function pointer
push offset sDll
call LoadLibraryA@4
push offset sFunc
push eax
call GetProcAddress@8
mov dword ptr [ebp-4h], eax
push offset sMsg
call dword ptr [ebp-4h]
add esp, 4h
mov eax, 0h
mov esp, ebp
pop ebp
ret
end _mainCRTStartup
May the source be with you

aw27

LoadLibrary("msvcrt") is not MASM or any assembly language in this World. Can be considered pseudo-code, so that people can figure out the idea. incidentally can even be an instruction of MASM BASIC, which is not MASM just because it contains the word MASM.  JJ may even change the name to UASM BASIC it will not make any difference at all. It will not be UASM as well  just because it uses the UASM assembler :(

jj2007

I hope you had a good lunch, José - I won't feed you :P

Vortex

Code assembled with nidud's asmc :

include windows.inc

.data?

hModule     dd ?

.data

string      db 'This is a test.',0

.code

main PROC

    LoadLibrary("msvcrt")
    mov     hModule,eax
   
    GetProcAddress(eax,"printf")

    push    OFFSET string
    call    eax
    add     esp,4

    FreeLibrary(hModule)
    ExitProcess(0)

main ENDP

END main

aw27

Quote from: Vortex on April 04, 2019, 04:55:35 AM
Code assembled with nidud's asmc :

include windows.inc

    LoadLibrary("msvcrt")
    GetProcAddress(eax,"printf")
    FreeLibrary(hModule)
    ExitProcess(0)

main ENDP

END main

Yeap, ASMC has lots of internal macros, or whatever I can call that, replicating Windows API and CRT functions. It is a great work indeed for people that want to maintain a comfortable distance from machine code.   :t

johnsa

LoadLibrary is a std. win32 function, not related to asmc or uasm, masm etc. So that should be 100% generic and safe to use on any Windows always.

hutch--

LoadLibrary() and GetProcAddress() are standard API functions which should be used with the normal testing on both the library handle and the procedure address. Without this it can go BANG if either are incorrect.

call LoadLibrary
If return value != 0
call GetProcAddress
If return value != 0
....
call function address.