flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > system() function

Author
Thread Post new topic Reply to topic
strcpy()



Joined: 23 Aug 2006
Posts: 5
Location: Mar del Plata / Argentina
strcpy()
Hi all!

i want to use the C´s system() function but in FASM
is there some way, using the WINAPI or something ?

thanks!
Post 28 Sep 2006, 18:22
View user's profile Send private message MSN Messenger Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
i guess it's accessible through the msvcrt.dll
Post 28 Sep 2006, 19:21
View user's profile Send private message Visit poster's website Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
Code:
include '%fasminc%\win32a.inc'
format PE GUI 4.0

main:
        invoke _system,progname
        invoke ExitProcess,0

;data
progname db 'notepad.exe',0

data import
library crt,'msvcrt.dll',\
kernel32,'kernel32.dll'


import crt, _system,'system'
import kernel32,ExitProcess,'ExitProcess'
end data
    

This should work.
Post 28 Sep 2006, 19:33
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Or use CreateProcess instead of depending on msvcrt.dll. Or ShellExecute, if your needs are simple.
Post 28 Sep 2006, 21:57
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
And even more simple WinExec (not recomended by Microsoft but this worked for me on WinXP 64-bit Very Happy):
Code:
include 'win32axp.inc'

.code

start:
  invoke  WinExec,\
          "notepad.exe test.asm",\   ; address of command line
          SW_SHOWNORMAL    ; window style for new application
  invoke  ExitProcess, 0

.end start    


My source is named "test.asm" so when I press F9 on FASMW I get a notepad with the source code of the program that opened it Razz
Post 28 Sep 2006, 23:43
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav
also ShellExecute
Post 29 Sep 2006, 04:36
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
If ShellExecute runs synchronously then is the prefered, otherwise I think it's better CreateProcess with a wait-for-terminate code. WinExec returns control at the first GetMessage call of the program passed to WinExec (but the program still alive and doesn't finished its work).

The wait-for-terminate code is something around CreateProcess, OpenProcess and WaitForSingleObject.
Post 29 Sep 2006, 13:43
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
Indeed, locodelassembly. And don't forget CloseHandle*2 Smile
Post 29 Sep 2006, 13:55
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
oooh, good advice Smile
Post 29 Sep 2006, 13:58
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.