Author Topic: Passing a structure  (Read 5068 times)

Vortex

  • Member
  • *****
  • Posts: 2328
Re: Passing a structure
« Reply #30 on: April 03, 2019, 05:24:46 AM »
Reading that Twitter message, one can write a simplified version of printf. No need of other dependencies.

AW

  • Member
  • *****
  • Posts: 2583
  • Let's Make ASM Great Again!
Re: Passing a structure
« Reply #31 on: April 03, 2019, 02:30:49 PM »
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

  • Member
  • ****
  • Posts: 551
Re: Passing a structure
« Reply #32 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.
May the source be with you

jj2007

  • Member
  • *****
  • Posts: 10539
  • Assembler is fun ;-)
    • MasmBasic
Re: Passing a structure
« Reply #33 on: April 03, 2019, 05:59:37 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:

AW

  • Member
  • *****
  • Posts: 2583
  • Let's Make ASM Great Again!
Re: Passing a structure
« Reply #34 on: April 03, 2019, 06:09:45 PM »
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

  • Member
  • *****
  • Posts: 10539
  • Assembler is fun ;-)
    • MasmBasic
Re: Passing a structure
« Reply #35 on: April 03, 2019, 07:38:50 PM »
includelib "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.

AW

  • Member
  • *****
  • Posts: 2583
  • Let's Make ASM Great Again!
Re: Passing a structure
« Reply #36 on: April 03, 2019, 07:48:32 PM »
includelib "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

  • Member
  • *****
  • Posts: 10539
  • Assembler is fun ;-)
    • MasmBasic
Re: Passing a structure
« Reply #37 on: April 03, 2019, 08:39:09 PM »
Me too.

TimoVJL

  • Member
  • ****
  • Posts: 551
Re: Passing a structure
« Reply #38 on: April 03, 2019, 09:32:23 PM »
As jj2007 mentioned, the dynamic way:
Code: [Select]
.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

AW

  • Member
  • *****
  • Posts: 2583
  • Let's Make ASM Great Again!
Re: Passing a structure
« Reply #39 on: April 03, 2019, 11:30:07 PM »
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

  • Member
  • *****
  • Posts: 10539
  • Assembler is fun ;-)
    • MasmBasic
Re: Passing a structure
« Reply #40 on: April 04, 2019, 12:01:30 AM »
I hope you had a good lunch, José - I won't feed you :P

Vortex

  • Member
  • *****
  • Posts: 2328
Re: Passing a structure
« Reply #41 on: April 04, 2019, 04:55:35 AM »
Code assembled with nidud's asmc :

Code: [Select]
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

AW

  • Member
  • *****
  • Posts: 2583
  • Let's Make ASM Great Again!
Re: Passing a structure
« Reply #42 on: April 04, 2019, 05:08:55 AM »
Code assembled with nidud's asmc :

Code: [Select]
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

  • Member
  • ****
  • Posts: 807
    • Uasm
Re: Passing a structure
« Reply #43 on: April 08, 2019, 05:25:01 AM »
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--

  • Administrator
  • Member
  • ******
  • Posts: 7531
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Passing a structure
« Reply #44 on: April 08, 2019, 11:57:56 AM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: