News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

need to run a program with arguments and a txt file.

Started by gavin, July 06, 2005, 03:04:11 AM

Previous topic - Next topic

gavin

Hi their.

I need some advice and some help please.

I'm making a windows console application.
What i want to do is use the popup list demo code from C:\masm32\examples\EXAMPLE2\POPLIST
the item popup will recieve it's lists from a text file containing i.p. addresses.
and when i click on an item it will add the server string onto the end of the C:\Program Files\Steam\Steam.exe -applaunch 20 +connect
and run it.

example.

click item 1
runs command + ip address from the list
Thanks lads for any help.


    .486                       ; create 32 bit code
    .model flat, stdcall       ; 32 bit memory model
    option casemap :none       ; case sensitive

    include \masm32\include\windows.inc
    include \masm32\include\kernel32.inc
    include \masm32\include\user32.inc
    include \masm32\include\shell32.inc

    includelib \masm32\lib\kernel32.lib
    includelib \masm32\lib\user32.lib

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««;

    .data
   
_cmd         db "C:\Program Files\Steam\Steam.exe -applaunch 20 +connect ",0

_server      db " ",0



    .code

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««;

start:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««;




; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««;

end start


Tedd

There's no reason for this to be a console app.
Do the listbox, as in the example -- fill it out with the ip addresses, etc.
Receive notification of the click.
Append the ip address to the end of the string.
Use CreateProcess to start the program with your command line.
Voila.

Of course, these are pretty brief instructions, so you'll have a bit of research to do for the details :wink
No snowflake in an avalanche feels responsible.

gavin


include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
FileName db "C:\Valve\Steam\Steam.exe",0

startupinfo         STARTUPINFO         { SIZEOF STARTUPINFO }
processinfo         PROCESS_INFORMATION { SIZEOF PROCESS_INFORMATION }


.code
;------------------------------------------------------------------------------
run     proc, s:dword

        invoke CreateProcess, ADDR FileName, NULL, NULL, NULL, NULL,
     NULL, NULL, ADDR Startup, ADDR processinfo

run     endp
;------------------------------------------------------------------------------
haha    proc s:dword

        invoke    winexec, addr buf
haha endp       
;------------------------------------------------------------------------------

start:  invoke haha, FileName
        xor       eax, eax
        invoke    ExitProcess, eax
        ret
;------------------------------------------------------------------------------

end start   



Anyone tell me why the code is wrong thanks.

Mark Jones

By "ADDR buf", do you mean "ADDR FileName"?

EDIT a few seconds later: Also the S:DWORDs are not being used for anything. If they are not needed, remove them and change their PROTOs to


run PROTO
haha PROTO
.code
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

ToutEnMasm

Hello,
with a speed look s:DWORD is not use and the structures are not initialised.
                                           ToutEnMasm

gavin

Hi lads thanks for help so far.

All i want to do is run a program but man it's hard.

If i knew how to interpret the win32 help file it would be easier :(.

I'll fix my code the best i can i suppose.
Thanks again.

Edit :)


.386                       ; create 32 bit code
.model flat, stdcall       ; 32 bit memory model
option casemap :none      ; case sensitive

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
FileName db "C:\Valve\Steam\Steam.exe",0

startupinfo         STARTUPINFO         { SIZEOF STARTUPINFO }
processinfo         PROCESS_INFORMATION { SIZEOF PROCESS_INFORMATION }


.code
;------------------------------------------------------------------------------
start:


invoke GetStartupInfo,ADDR startupinfo
invoke CreateProcess,ADDR FileName,NULL,NULL,NULL,NULL,\
NORMAL_PRIORITY_CLASS,\
NULL,NULL,ADDR startupinfo,ADDR processinfo
invoke CloseHandle,processinfo.hThread

xor  eax, eax
invoke ExitProcess, eax
;------------------------------------------------------------------------------


end start


:U :8) :bg :lol :clap:

It works man i'm a bit slow :)

One more question lads.

Receive notification of the click.
Append the ip address to the end of the string.

Ok for the mouse clicks i read the Client Area Mouse Messages in win32 help file.
Can anyone help me please i've never done thi before.

Thanks again.

Tedd

(Without looking) I'm pretty sure that the listbox will send its parent window a WM_NOTIFY message, with details of the clicking. Doesn't the example you've got react in some way to mouse clicks? (If not, find one that does :wink)
As for appending the string - it's as easy as copying the first string to a memory buffer, followed by the next string (lstrcopy, lstrcat - amongst the numerous other ways to achieve the same thing.)
No snowflake in an avalanche feels responsible.

gavin

Hi Tedd.

It uses this .


WndProc proc hWin   :DWORD,
             uMsg   :DWORD,
             wParam :DWORD,
             lParam :DWORD

    .if uMsg == WM_CLOSE

    .elseif uMsg == WM_LBUTTONDBLCLK


         szText msgText,"msg goes here"
         invoke MessageBox,hWin,ADDR msgText,ADDR szDisplayName,MB_OK

    .elseif uMsg == WM_DESTROY
        invoke PostQuitMessage,NULL
        return 0
    .endif

    invoke CallWindowProc,lpfnWndProc,hWin,uMsg,wParam,lParam

    ret

WndProc endp




Tedd

If that works, use that :toothy

However, note that it does that by subclassing, so during window creation, it will use GetWindowLong with GWL_WNDPROC to get the address of the listbox's wndproc, then SetWindowLong to replace that with its own. The CallWindowProc then calls the original wndproc after you've finished playing with whatever you want to do :wink

However, a quick look brings up the LBN_DBLCLICK message.
Soo... without all the messing around with subclassing, upon clicking a string, the parent will receive a WM_COMMAND message, with hiword(wParam) set to LBN_DBLCLICK, loword(wParam) set to the id of the listbox, and lParam as the handle of the listbox.
But note that you have to create the listbox with LBS_NOTIFY in the style.
No snowflake in an avalanche feels responsible.

gavin

Hi lads i need help with my code please.
What i did was use a file called list.asm which has the text items for the dialogue listbox.
Then whatever is selected it will correspond with the array i made below called IP and put the contents into server db "255.255.255.255:65535",0



This is my first asm prog so any help would be great.

Thanks.




      .386
      .model flat, stdcall
      option casemap :none   ; case sensitive

; #########################################################################

      include \masm32\include\windows.inc
      include \masm32\include\gdi32.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc

      includelib \masm32\lib\gdi32.lib
      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib

; #########################################################################

      ;=============
      ; Local macros
      ;=============

      szText MACRO Name, Text:VARARG
        LOCAL lbl
          jmp lbl
            Name db Text,0
          lbl:
        ENDM

      m2m MACRO M1, M2
        push M2
        pop  M1
      ENDM


      return MACRO arg

        mov eax, arg
        ret
      ENDM

        ;=================
        ; Local prototypes
        ;=================
        WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
        WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
        TopXY PROTO   :DWORD,:DWORD

    .data
        szDisplayName db "sngn servers",0
        CommandLine   dd 0
        hWnd          dd 0
        hInstance     dd 0
        lpfnWndProc   dd 0

       
        FileName db "C:\Valve\Steam\Steam.exe - applaunch 10 - console + connect "
        server db "255.255.255.255:65535",0
        ip0 db "213.40.198.1:27020",0
        ip1 db "213.40.198.1:27040",0
        ip2 db "213.40.198.1:27045",0
        ip3 db "213.40.198.1:27035",0
        ip4 db "213.40.198.1:27030",0
        ip5 db "213.40.198.1:27025",0
        ip6 db "213.40.198.1:27015",0
       
        IP dd ip0, ip1, ip2, ip3, ip4, ip5, ip6       
       

        ItemBuffer    db 128 dup (?)

        startupinfo         STARTUPINFO         { SIZEOF STARTUPINFO }
        processinfo         PROCESS_INFORMATION { SIZEOF PROCESS_INFORMATION }



      ; ---------------------------------------------------
      ; The following include file is a list converted to
      ; a specific format by the QBASIC program in this
      ; directory. The format is that each item in the list
      ; is delimited by one zero byte and the list is
      ; terminated by two zero bytes. There is an algorithm
      ; in the WinMain procedure that reads this format and
      ; loads the list items individually into the list box.
      ; ---------------------------------------------------

      include list.asm

    .code

start:
        invoke GetModuleHandle, NULL
        mov hInstance, eax

        invoke GetCommandLine
        mov CommandLine, eax

        invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT
        invoke ExitProcess,eax

; #########################################################################

WinMain proc hInst     :DWORD,
             hPrevInst :DWORD,
             CmdLine   :DWORD,
             CmdShow   :DWORD

        ;====================
        ; Put LOCALs on stack
        ;====================

        LOCAL Wwd  :DWORD
        LOCAL Wht  :DWORD
        LOCAL Wtx  :DWORD
        LOCAL Wty  :DWORD
        LOCAL msg  :MSG

        mov Wwd, 200
        mov Wht, 200

        invoke GetSystemMetrics,SM_CXSCREEN
        invoke TopXY,Wwd,eax
        mov Wtx, eax

        invoke GetSystemMetrics,SM_CYSCREEN
        invoke TopXY,Wht,eax
        mov Wty, eax

        szText szClassName,"LISTBOX"

        invoke CreateWindowEx,WS_EX_PALETTEWINDOW or WS_EX_CLIENTEDGE,
                              ADDR szClassName,
                              ADDR szDisplayName,
                              WS_OVERLAPPEDWINDOW or WS_VSCROLL or \
                              LBS_HASSTRINGS or LBS_NOINTEGRALHEIGHT or \
                              LBS_NOTIFY, \
                              Wtx,Wty,Wwd,Wht,
                              NULL,NULL,
                              hInst,NULL
        mov   hWnd,eax

        invoke SetWindowLong,hWnd,GWL_WNDPROC,ADDR WndProc
        mov lpfnWndProc, eax

        invoke GetStockObject,ANSI_FIXED_FONT
        invoke SendMessage,hWnd,WM_SETFONT,eax,0

      ; ---------------------------------------------------
      ; This block of code reads a string that is a list of
      ; seperate items delimited by a single zero byte. The
      ; list is terminated by a double zero byte pair.
      ; ---------------------------------------------------
        mov esi, offset item000000
        mov edi, offset ItemBuffer

      @@:
        lodsb
        cmp al, 0   ; get zero
        je SubLp    ; write to list
        stosb
        jmp @B
      SubLp:
        stosb                       ; write terminator
        invoke SendMessage,hWnd,LB_ADDSTRING,0,ADDR ItemBuffer
        lodsb
        cmp al, 0                   ; check for second zero
        je @F                       ; exit if found
        mov edi, offset ItemBuffer  ; reset to start of buffer
        stosb                       ; write test byte to it
        jmp @B
      @@:

      ; --------------------------------------------------------

        invoke ShowWindow,hWnd,SW_SHOWNORMAL
        invoke UpdateWindow,hWnd

      ;===================================
      ; Loop until PostQuitMessage is sent
      ;===================================

    StartLoop:
      invoke GetMessage,ADDR msg,NULL,0,0
      cmp eax, 0
      je ExitLoop
      invoke TranslateMessage, ADDR msg
      invoke DispatchMessage,  ADDR msg
      jmp StartLoop
    ExitLoop:

      return msg.wParam

WinMain endp

; #########################################################################


WndProc proc hWin   :DWORD,
             uMsg   :DWORD,
             wParam :DWORD,
             lParam :DWORD

    .if uMsg == WM_CLOSE

    .elseif uMsg == WM_LBUTTONDBLCLK
     
       
        xor ecx, ecx ; Clear ECX
looptop:
invoke SendMessage,hWnd,LB_GETSEL, ecx, 0
cmp eax, 0
jne found
cmp ecx, 7
je not_found
inc ecx
jmp looptop

found:
mov eax, [IP+4*ecx] ;eax now holds the address of the selected item right?
;what i need to do is get the string into the server variable to tack onto the end of filename.


not_found: 

   
    .elseif uMsg == WM_DESTROY
        invoke PostQuitMessage,NULL
        return 0
    .endif

    invoke CallWindowProc,lpfnWndProc,hWin,uMsg,wParam,lParam

    ret

WndProc endp

; ########################################################################

TopXY proc wDim:DWORD, sDim:DWORD

    shr sDim, 1      ; divide screen dimension by 2
    shr wDim, 1      ; divide window dimension by 2
    mov eax, wDim    ; copy window dimension into eax
    sub sDim, eax    ; sub half win dimension from half screen dimension

    return sDim

TopXY endp

; ########################################################################

invoke GetStartupInfo,ADDR startupinfo
invoke CreateProcess,ADDR FileName,NULL,NULL,NULL,NULL,\
NORMAL_PRIORITY_CLASS,\
NULL,NULL,ADDR startupinfo,ADDR processinfo
invoke CloseHandle,processinfo.hThread

xor  eax, eax
invoke ExitProcess, eax


end start