flat assembler
Message board for the users of flat assembler.

Index > Windows > Using MessageBox with a console application

Author
Thread Post new topic Reply to topic
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc
I'm attempting to display a MessageBox from a Windows console application. The application always fails when the MessageBox is invoked. Is this even possible? If possible I'd prefer not to have to include all of the Windows includes with the source. Any help would be appreciated.

Here's the code:
Code:
include '%fasminc%/win32a.inc'

format pe console
  start:
 invoke GetModuleHandle, 0
   mov [hinstance], eax

    invoke GetStdHandle, STD_INPUT_HANDLE
       mov [StdIn], eax
    invoke SetConsoleMode, eax, 5

   invoke GetStdHandle, STD_OUTPUT_HANDLE
      mov [StdOut], eax

; HWND_DESKTOP = 0
; MB_OK = 0
  invoke  MessageBox,0,"Testing...","The Title",0

     invoke  ExitProcess,0
;---------------------------------------------------------------------
hinstance rd 1
StdIn rd 1
StdOut rd 1
;---------------------------------------------------------------------
section '.idata' import data readable writeable
  library kernel,'KERNEL32.DLL'
  library user,'USER32.DLL'
  import kernel,\
    GetModuleHandle,'GetModuleHandleA',\
     ExitProcess,'ExitProcess',\
      GetStdHandle, 'GetStdHandle',\
   WriteFile, 'WriteFile',\
         ReadFile, 'ReadFile',\
   ReadConsole, 'ReadConsoleA',\
    WriteConsole, 'WriteConsoleA',\
  SetConsoleMode, 'SetConsoleMode',\
       SetConsoleTitle, 'SetConsoleTitleA'
  import user,\
   MessageBox, 'MessageBoxA'
    
Post 24 Mar 2004, 12:30
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
I think the problem is you need to have only one 'library' statement, like this:
Code:
library  kernel,'KERNEL32.DLL',\
  user,'USER32.DLL'
    


Also, unless you're using a new and funky invoke Smile, you'll need to create some variables for the "Testing..." and "The Title" strings.
Post 24 Mar 2004, 16:17
View user's profile Send private message Visit poster's website Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc
Thanks, that did the trick!
Post 24 Mar 2004, 17:37
View user's profile Send private message Visit poster's website 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. Also on YouTube, Twitter.

Website powered by rwasa.