flat assembler
Message board for the users of flat assembler.

Index > Windows > printf instead of API console func

Author
Thread Post new topic Reply to topic
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle 26 Sep 2003, 08:09
How to build macro "printf" with syntax like in C
I need do it and use instead of API_console_functions

What is the best way to learn writing any macros I'll need in the future.

Do not make any solvation, I want to do it myself but I need somebody who can show me the way.

W2K

I am glad I' here with the best of the best Fellows who love FASM truly Wink

if it (above) is tough to do I'll do dll in C with this function and I'll import it

_________________
Microsoft: brings power of yesterday to computers of today.
Post 26 Sep 2003, 08:09
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 26 Sep 2003, 10:39
Do you need that macro to be some interface for the "printf" function from CRT, or do you mean the whole procedure written in assembly, that will perform the task of "printf" function?
Post 26 Sep 2003, 10:39
View user's profile Send private message Visit poster's website Reply with quote
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle 26 Sep 2003, 11:15
the basic printf syntax which can simpy print a string %s or a digit %d and can be ended by \n makes me satisfied.

if I'll have to use another printf's option the simplest way will be to load it as module written i C. Am I wrong?


but today I'll learn such exampe as "for" to understand how can I do anything ,because I know nothing about macros.

_________________
Microsoft: brings power of yesterday to computers of today.
Post 26 Sep 2003, 11:15
View user's profile Send private message Reply with quote
Eoin



Joined: 16 Jun 2003
Posts: 68
Location: Ireland
Eoin 26 Sep 2003, 17:27
To be honest I've only ever used sprintf, never the console version but I imagine the functionality is the same.

The printf functions are available in the crtdll.dll which comes with the versions of windows I'm aware of. So the simple solution is to write a macro which will call those functions.

Basically all you need is a ccall or cinvoke macro. There are plenty of examples around but you say you wish to do this yourself. I'd recommend studying the stdcall and invoke macros you'll find in the Fasm examples and then try and convert them to cdecl.

For extra info on calling conventions see http://www.codeproject.com/cpp/calling_conventions_demystified.asp

Including strings among the parameters is possible thanks to the eqtype operator, again there are plenty of examples knocking around.
Post 26 Sep 2003, 17:27
View user's profile Send private message Reply with quote
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle 29 Sep 2003, 13:45
THX all of You ,I had no idea that crtdll.dll includes all I need.

API&DLL are powerful tools ,just I know the truth that without those tools I can't do any step forward.

_________________
Microsoft: brings power of yesterday to computers of today.
Post 29 Sep 2003, 13:45
View user's profile Send private message Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 25 Oct 2003, 08:59
An example:

Code:
format PE CONSOLE
entry start

include '%include%\win32a.inc'

section '.data' data readable writeable
msg db 'This is a printf example',0
format1 db '%s',0

section '.code' code readable executable
  start:
cinvoke printf,format1,msg
invoke ExitProcess,0

section '.idata' import data readable writeable

  library kernel32,'kernel32.dll',\
          crtdll,'crtdll.dll'

  import kernel32,\
         ExitProcess,'ExitProcess'

  import crtdll,\
         printf,'printf'
    

_________________
Code it... That's all...
Post 25 Oct 2003, 08:59
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 27 Oct 2003, 05:58
What about using simple wsprintf from user32 (maybe kernel32)?
At has basic functionality
Post 27 Oct 2003, 05:58
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Eoin



Joined: 16 Jun 2003
Posts: 68
Location: Ireland
Eoin 27 Oct 2003, 15:02
The advantage with sprintf is that it handles floating points unlike wsprintf.
Post 27 Oct 2003, 15:02
View user's profile Send private message Reply with quote
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle 27 Oct 2003, 15:27
but this is better and faster for W_9x only.

W_NT use UNICODE so there is w font in sprintf,it means wild-16bit characters intead of ASCII codes.

W_NT always translate ASCII to UNICODE !

_________________
Microsoft: brings power of yesterday to computers of today.
Post 27 Oct 2003, 15:27
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.