flat assembler
Message board for the users of flat assembler.

Index > Windows > TextOut not working...

Author
Thread Post new topic Reply to topic
JapanLover



Joined: 17 Oct 2006
Posts: 8
JapanLover
hey folks...

i've got an issue with some simple code that won't work...

the textout does not draw the text unless i remove the exitprocess and allow it to crash when run...

Code:
format PE GUI 4.0
entry start

include 'C:\fasm\INCLUDE\win32a.inc'

section '.data' data readable writeable

     Text     db   'hello',0

section '.code' code readable executable
  start:

   invoke GetDC,0
   mov ebp,eax
   invoke SetBkColor,ebp,00e6ffffh
   invoke SetTextColor,ebp,007f0000h
   invoke TextOut,ebp,10,40,Text,5
   invoke ExitProcess,0

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          gdi,'GDI32.DLL',\
          user,'USER32.DLL'

  import  kernel,\
          ExitProcess,'ExitProcess'

  import  user,\
          GetDC,'GetDC',\
          ReleaseDC,'ReleaseDC'

  import  gdi,\
          TextOut,'TextOutA',\
          SetBkColor,'SetBkColor',\
          SetTextColor,'SetTextColor'
    


any help making this work is much appreciated =)

thanks in advance =)

edit:

i went ahead and tried some line drawing, with even less success...

Code:
format PE GUI 4.0
entry start

include 'C:\Documents and Settings\nnop\Desktop\crackin-and-such\fasm\INCLUDE\win32a.inc'

section '.data' data readable writeable

     Text     db   'hello',0

section '.code' code readable executable
  start:

   invoke GetDC,0
   mov ebp,eax
   invoke SetBkColor,ebp,00e6ffffh
   invoke SetTextColor,ebp,007f0000h
   invoke TextOut,ebp,10,40,Text,5
   invoke CreatePen,PS_SOLID,1,00ff0000h
   mov ebx,eax
   invoke SelectObject,ebx,ebp
   invoke MoveToEx,ebx,200,200,0
   invoke LineTo,ebx,500,500
;   invoke Sleep,10000
   invoke ReleaseDC,0,ebx
   invoke ExitProcess,0

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
          gdi,'GDI32.DLL',\
          user,'USER32.DLL'

  import  kernel,\
          ExitProcess,'ExitProcess',\
          Sleep,'Sleep'

  import  user,\
          GetDC,'GetDC',\
          ReleaseDC,'ReleaseDC'

  import  gdi,\
          TextOut,'TextOutA',\
          SelectObject,'SelectObject',\
          SetBkColor,'SetBkColor',\
          MoveToEx,'MoveToEx',\
          LineTo,'LineTo',\
          CreatePen,'CreatePen',\
          SetTextColor,'SetTextColor'     


the writting of hello works now...

so i guess that that was some kind of delay/timing issue...

i can't figure what wrong with the lines...

any help is much appreciated =)
Post 01 Jun 2007, 17:23
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
you must use another dc created with CreateCompatibleDC, so this is a pseudo-algo:

Code:
hdc=GetDC(0);
hcdc=CreateCompatibleDC(hdc);
SetBkColor(hcdc,0);
SetTextColor(hcdc,0ffffff);
TextOut(hcdc,...);
BitBlt(hdc,...,hcdc,0,0,SRCCOPY);
    
Post 01 Jun 2007, 18:56
View user's profile Send private message Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 245
Location: US
Yardman
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 02:22; edited 1 time in total
Post 01 Jun 2007, 19:11
View user's profile Send private message Reply with quote
Frank



Joined: 17 Jun 2003
Posts: 100
Frank
JapanLover,

you need to invoke GdiFlush after TextOut, but before ExitProcess (read the Win32 help on GdiFlush for explanation). Your original code works after two minor changes:

Code:
   ; Change 1:
   invoke TextOut,ebp,10,40,Text,5
   invoke GdiFlush
   invoke ExitProcess,0

   ; Change 2:
  import  gdi,\
          TextOut,'TextOutA',\
          SetBkColor,'SetBkColor',\
          SetTextColor,'SetTextColor',\
          GdiFlush,'GdiFlush'
    
Post 01 Jun 2007, 21:16
View user's profile Send private message Reply with quote
JapanLover



Joined: 17 Oct 2006
Posts: 8
JapanLover
well, i think i've got it all working and figured out for now...

thanks for quick replies and great help guys =)
Post 02 Jun 2007, 03:08
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-2020, Tomasz Grysztar.

Powered by rwasa.