flat assembler
Message board for the users of flat assembler.

Index > Windows > Iczelion's Win32 Assembly Tutorial: 21 - Pipe

Author
Thread Post new topic Reply to topic
Beowulf



Joined: 10 Jul 2003
Posts: 5
Location: Germany
Beowulf
I made a small change to original version: Instead of a menu, i use WM_CHAR!

Code:
format PE GUI 4.0
entry main

;-------------------------------------------------------------------------------------
;Include
;-------------------------------------------------------------------------------------

include '%fasminc%\win32a.inc'

;-------------------------------------------------------------------------------------
;Constants
;-------------------------------------------------------------------------------------

Black        equ 000000h
Yellow       equ 00FFFFh

;-------------------------------------------------------------------------------------
;Structurs
;-------------------------------------------------------------------------------------

struc PROCESS_INFORMATION
{

        .hProcess      dd   ?
        .hThread       dd   ?
        .dwProcessId   dd   ?
        .dwThreadId    dd   ?
}

struc SECURITY_ATTRIBUTES
{
        .nLength               dd   ?
        .lpSecurityDescriptor  dd   ?
        .bInheritHandle        dd   ?
}

;-------------------------------------------------------------------------------------
;Data Section
;-------------------------------------------------------------------------------------

section '.data' data readable writeable

        ClassName            db "PipeWinClass",0
        AppName              db "One-way Pipe Beispiel",0
        EditClass            db "EDIT",0
        CreatePipeError      db "Fehler während der Pipe-Erzeugung",0
        CreateProcessError   db "Fehler während der Prozess-Erzeugung",0
        CommandLine          db "fasm test.asm test.exe",0

        hInstance            dd ?
        hwndEdit             dd ?

        wc                   WNDCLASSEX
        msg                  MSG
        hwnd                 dd ?

        rect                 RECT
        hRead                dd ?
        hWrite               dd ?
        startupinfo          STARTUPINFO
        pinfo                PROCESS_INFORMATION
        buffer               rb 1024
        bytesRead            dd ?
        hdc                  dd ?
        sat                  SECURITY_ATTRIBUTES

;-------------------------------------------------------------------------------------
;Code Section
;-------------------------------------------------------------------------------------

section '.code' code readable executable

        ;----Entry Point and 'main' Procedure--------------
        proc main
        enter
                mov   [wc.cbSize],48
                mov   [wc.style], CS_HREDRAW or CS_VREDRAW
                mov   [wc.lpfnWndProc],WndProc
                mov   [wc.cbClsExtra],NULL
                mov   [wc.cbWndExtra],NULL

                invoke  GetModuleHandle ,0
                mov   [hInstance],eax
                mov   [wc.hInstance],eax
                mov   [wc.hbrBackground],COLOR_APPWORKSPACE
                mov   [wc.lpszMenuName],NULL
                mov   [wc.lpszClassName],ClassName
                invoke LoadIcon,NULL,IDI_APPLICATION
                mov   [wc.hIcon],eax
                mov   [wc.hIconSm],eax
                invoke LoadCursor,NULL,IDC_ARROW
                mov   [wc.hCursor],eax
                invoke RegisterClassEx, wc
                invoke CreateWindowEx,WS_EX_CLIENTEDGE,\
                                      ClassName,\
                                      AppName,\
                                      WS_OVERLAPPED+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX+WS_MAXIMIZEBOX+WS_VISIBLE,\
                                      CW_USEDEFAULT, CW_USEDEFAULT,350,200,\
                                      NULL,\
                                      NULL,\
                                      hInstance,\
                                      NULL

                mov   [hwnd],eax

                Message_Loop_Start:

                        invoke  GetMessage,msg,NULL,0,0
                        or      eax,eax
                        jz      Message_Loop_End
                        invoke  TranslateMessage,msg
                        invoke  DispatchMessage,msg
                        jmp     Message_Loop_Start

                Message_Loop_End:

                        invoke  ExitProcess,[msg.wParam]
        return


        ;----Window Procedure-----------------
        proc WndProc, hWnd, uMsg, wParam, lParam
        enter
                cmp [uMsg], WM_CREATE
                je wmcreate
                cmp [uMsg], WM_CTLCOLOREDIT
                je wmctlcoloredit
                cmp [uMsg], WM_SIZE
                je wmsize
                cmp [uMsg], WM_CHAR
                je wmchar
                cmp [uMsg], WM_DESTROY
                je wmdestroy

                defwndproc:
                        invoke  DefWindowProc,[hWnd],[uMsg],[wParam],[lParam]
                        return

                wmcreate:
                        invoke CreateWindowEx,NULL,\
                                              EditClass,\
                                              NULL,\
                                              WS_CHILD+ WS_VISIBLE+ ES_MULTILINE+ ES_AUTOHSCROLL+ ES_AUTOVSCROLL,\
                                              0,0,0,0,\
                                              [hWnd],\
                                              NULL,\
                                              hInstance,\
                                              NULL

                        mov [hwndEdit],eax
                        return
                wmctlcoloredit:
                        invoke SetTextColor,[wParam],Yellow
                        invoke SetBkColor,[wParam],Black
                        invoke GetStockObject,BLACK_BRUSH
                        return

                wmsize:
                        mov edx,[lParam]
                        mov ecx,edx
                        shr ecx,16
                        and edx,0ffffh
                        invoke MoveWindow,[hwndEdit],0,0,edx,ecx,TRUE
                        return

                wmchar:
                        mov [sat.nLength],12
                        mov [sat.lpSecurityDescriptor],NULL
                        mov [sat.bInheritHandle],TRUE
                        invoke CreatePipe,hRead,hWrite,sat,NULL
                        cmp eax,0
                        je lCreatePipeError
                        mov [startupinfo.cb],68
                        invoke GetStartupInfo,startupinfo
                        mov eax, [hWrite]
                        mov [startupinfo.hStdOutput],eax
                        mov [startupinfo.hStdError],eax
                        mov [startupinfo.dwFlags], STARTF_USESHOWWINDOW+ STARTF_USESTDHANDLES
                        mov [startupinfo.wShowWindow],SW_HIDE
                        invoke CreateProcess, NULL, CommandLine, NULL, NULL, TRUE, NULL, NULL, NULL, startupinfo, pinfo
                        cmp eax,0
                        je lCreateProcessError
                        invoke CloseHandle,[hWrite]
                        @@:
                                invoke RtlZeroMemory, buffer,1024
                                invoke ReadFile,[hRead],buffer,1023,bytesRead,NULL
                                cmp eax,0
                                je finish
                                invoke SendMessage,[hwndEdit],EM_SETSEL,-1,0
                                invoke SendMessage,[hwndEdit],EM_REPLACESEL,FALSE,buffer
                        jmp @b
                        return

                wmdestroy:
                        invoke PostQuitMessage,NULL
                        return

                lCreatePipeError:
                        invoke MessageBox, [hWnd], CreatePipeError, AppName, MB_ICONERROR+ MB_OK
                        return

                lCreateProcessError:
                        invoke MessageBox,[hWnd],CreateProcessError, AppName,MB_ICONERROR+MB_OK
                        return
                finish:
        return

;-------------------------------------------------------------------------------------
;Imports
;-------------------------------------------------------------------------------------

section '.idata' import data readable writeable

        library kernel32,'KERNEL32.DLL',\
                user32,'USER32.DLL',\
                gdi32,'GDI32.DLL',\
                advapi32,'ADVAPI32.DLL',\
                comctl32,'COMCTL32.DLL',\
                comdlg32,'COMDLG32.DLL',\
                shell32,'SHELL32.DLL',\
                wsock32,'WSOCK32.DLL'

        include '%fasminc%/apia/kernel32.inc'
        include '%fasminc%/apia/user32.inc'
        include '%fasminc%/apia/gdi32.inc'
        include '%fasminc%/apia/advapi32.inc'
        include '%fasminc%/apia/comctl32.inc'
        include '%fasminc%/apia/comdlg32.inc'
        include '%fasminc%/apia/shell32.inc'
        include '%fasminc%/apia/wsock32.inc'   
    
Post 17 Jan 2004, 14:46
View user's profile Send private message ICQ Number 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 GitHub, YouTube, Twitter.

Website powered by rwasa.