The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: IAO on March 21, 2006, 08:11:22 PM

Title: More of the same thing.(WINEXE or ShellExecute)
Post by: IAO on March 21, 2006, 08:11:22 PM
Hi to all:    My English is poor. But I try.

I made a program that must execute a File.com.

In Visual C, it works well.
case WM_CREATE:
WinExec("det.exe", SW_SHOWMINNOACTIVE);
return 0;

In assembler, it gives an error. When I execute the program.
I execute it again and works well.
;#########################################################################
.386
.model flat,stdcall
option casemap:none

include VariosGra.inc

.code
start:
   invoke GetModuleHandle, NULL
   mov hInstance,eax
   ;LLama al Dialog Box almacenado en el .DLG o .RC
   invoke DialogBoxParam, hInstance,MyDialog,NULL,addr DlgProc,NULL   
   invoke ExitProcess,eax

DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

    LOCAL pMem  :DWORD
    LOCAL flen  :DWORD
    LOCAL rpos  :DWORD
    LOCAL wpos  :DWORD
    LOCAL buffer[128]:BYTE

   .IF uMsg==WM_INITDIALOG
   
       invoke WinExec, ADDR filename, SW_SHOWMINNOACTIVE     <----Here

      ;Esto es para el Icono.   
      invoke LoadIcon,hInstance,200
        mov hIcon, eax
        invoke SendMessage,hWnd,WM_SETICON,1,hIcon
    
       ;-Para que aparezca el VALOR en el  "EditText box".
      mov hEdit1, FUNC(GetDlgItem,hWnd,3000)
      
        mov pMem, InputFile("Addr.ini")     ; load the INI file into memory
        mov rpos, 0                         ; zero the read position pointer

        mov rpos, linein$(pMem,ADDR buffer,rpos)
        invoke SendMessage,hEdit1,WM_SETTEXT,0,ADDR buffer
        free pMem                           ; free the memory
;==============================================================

   .ELSEIF uMsg==WM_CLOSE
      invoke   EndDialog,hWnd,0

   ;Aqui el delete file.
    .if rv(exist,"Addr.ini") != 0           ; if file already exists
      test fdelete("Addr.ini"), eax                    ; delete it
    .endif      

   ;Procesan los Menu y Botones
   .ELSEIF uMsg==WM_COMMAND
      mov eax,wParam
      .IF eax==1003 ;

      mov esi,39h ;65 Numero que se muestra en EDITDOX 39h=9Decimal
      mov number,esi   
      invoke SetDlgItemText,hWnd,IDC_EDIT,ADDR number
      
      .ELSE
         mov edx,wParam
         shr edx,16
         .if dx==BN_CLICKED
            .IF ax==IDC_EXIT
               invoke   SendMessage,hWnd,WM_CLOSE,0,0
            .ENDIF
         .ENDIF
      .ENDIF
   .ELSE
      mov eax,FALSE
      ret
   .ENDIF
   mov eax,TRUE
   ret
DlgProc endp

;#########################################################################
end start

I have seen several tutorials. I know that I am making something bad.
You can see what lacks?

If comment this line, works well.
;invoke WinExec, ADDR filename, SW_SHOWMINNOACTIVE
Filename creates a Addr.ini file. I think that I must make a delay.
To make a delay, while it creates the file (Addr.ini).


Thanks for your patience.

Bye ('_').


[attachment deleted by admin]
Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: PBrennick on March 21, 2006, 09:10:49 PM
IAO,
You are not initializing filename, you should have a line that says ...

filename db 'MyFile.txt',0

or something similar.  You could put it in the .data section so as to make it globsl in scope or you can make it a local variable (it would be delared diffirently).

Paul
Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: ChrisLeslie on March 21, 2006, 09:50:55 PM
IAO

Assuming that your filename equates to 'file.exe', I think that Addr.ini is not created in time for its use.
Using a time delay after WinExec would by clumsy.
Why don't you use CreateProcess API, or better still, use 'shell' in the m32lib.
'shell' has a loop at the end of it to not continue until the shell's process thread is completed.
Doing that will assure that Addr.ini will be created by the time that your application needs to use it.

Chris
Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: IAO on March 21, 2006, 09:51:15 PM
Hi to all:    My English is poor. But I try.

My lord PBrennick:
The file "Probe.zip" it has: *.ini, *.rc, *.dlg, *.asm.
I think that the problem is not there.
The program executes well, in the second attempt.
Please, look inside of "Probe.zip".

Thanks for your patience.

Bye ('_').
Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: IAO on March 21, 2006, 10:02:17 PM
Hi to all:    My English is poor. But I try.

My lord ChrisLeslie:
I think that you go by good way.
I will try to make your suggestion.

Tonight I will try to conquer the world.  :lol
Thanks for your patience.

Bye ('_').
Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: IAO on March 22, 2006, 01:20:25 PM
Hi to all:    My English is poor. But I try.

C O N G R A T U L A T I O N S!!!!!!
My lord ChrisLeslie:
You are right.
You are Jimmy Neutron: Boy Genius. You are The Lord of the Ring(Assembler).
Thanks, Thanks, Thanks and Thanks again.


DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    LOCAL pMem  :DWORD
    LOCAL rpos  :DWORD
    LOCAL buffer[128]:BYTE

.IF uMsg==WM_INITDIALOG

|----------- V e r y  G o o d!!!! ------------| 
fn shell_ex,"Convstri.com",HIGH_PRIORITY_CLASS

;Esto es para el Icono.
invoke LoadIcon,hInstance,200
        mov hIcon, eax
        invoke SendMessage,hWnd,WM_SETICON,1,hIcon
    

Last night, Brain and me (Pinky). We conquer Assembler's World.
We Conquer the World of the Lenguage of the Assembly.

Now, I should make it with WINIO.
Step to step, I make my road.

Thanks for your patience.

Bye ('_').


[attachment deleted by admin]
Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: Emperor on March 22, 2006, 02:31:41 PM
Quote from: ChrisLeslie on March 21, 2006, 09:50:55 PM
IAO

Assuming that your filename equates to 'file.exe', I think that Addr.ini is not created in time for its use.
Using a time delay after WinExec would by clumsy.
Why don't you use CreateProcess API, or better still, use 'shell' in the m32lib.
'shell' has a loop at the end of it to not continue until the shell's process thread is completed.
Doing that will assure that Addr.ini will be created by the time that your application needs to use it.

Chris

You could use CreateProcess and WaitForSingleObject to wait until the program exits before continuing.


.data

SInfo STARTUPINFO <>
PInfo PROCESS_INFORMATION <>
PName db "C:\WINDOWS\notepad.exe", 0

.code

invoke GetStartupInfo, ADDR SInfo
invoke CreateProcess, ADDR PName, NULL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, \
NULL, NULL, ADDR SInfo, ADDR PInfo
invoke WaitForSingleObject, PInfo.hProcess, INFINITE
Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: Mark Jones on March 22, 2006, 06:13:02 PM
Quote from: IAO on March 22, 2006, 01:20:25 PM
You are The Lord of the Ring(Assembler).

Heheh, maybe this should be "Lord of the Ring Zero." :toothy
Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: asmfan on March 22, 2006, 06:22:27 PM
Mark,
:) LOL...
Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: IAO on March 22, 2006, 06:51:25 PM
Hi to all: My English is poor. But I try.

My lord Emperor:
I like much your suggestion. Tonight I will prove with your aid.

I never could make a program Windows with VisualC++. (I have 16 Books of: C, C++, VisualC++.)
With Masm32, Radasm, much documentation, Tutorial and this forum of course, now I can do it.
I have 4 books of Assembler.
This is very strange. But I understand more Assembler, than VisualC++ and MFM.
Excuse the speech, I am very happy.

Thanks for your patience.

Bye ('_').
Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: IAO on March 22, 2006, 07:03:24 PM
Hi to all:

My dear Mark Jones:
QuotePosted by: Mark Jones
Heheh, maybe this should be "Lord of the Ring Zero."
Your words gave much laughter me. You are a boy very earthquake.
I am not offending to you. You killed me of the laugh. :lol

Thanks for your patience.[/size]
Bye ('_').
Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: IAO on March 23, 2006, 07:09:32 PM
Hi to all:

My Lord  Emperor:
You are another genius. This forum is full with Geniuses.
You are the core of the cheese. You are 3 Brain. Me alone I have one.

You made an error, or you threw me a banana shell.
An extra NULL.

invoke CreateProcess, ADDR PName, NULL, NULL,( NULL,) FALSE, NORMAL_PRIORITY_CLASS, \
NULL, NULL, ADDR SInfo, ADDR PInfo

Thank you for your help. I am not sure, but I can see to the program execute quicker.


My Lord  Mark Jones:
Please Mark Jones. Don't make me that another time.
In the morning, I remembered of your words. I died from laugh.

Thanks, Thanks.  ChrisLeslie, Emperor.
  :clap: :cheekygreen:
Bye ('_').
Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: Emperor on March 24, 2006, 03:07:14 AM
Quote from: IAO on March 23, 2006, 07:09:32 PM
You made an error, or you threw me a banana shell.
An extra NULL.
invoke CreateProcess, ADDR PName, NULL, NULL,( NULL,) FALSE, NORMAL_PRIORITY_CLASS, \
NULL, NULL, ADDR SInfo, ADDR PInfo


But I thought CreateProcess took 10 params  :eek

; From kernel32.inc
CreateProcessA PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: ic2 on March 24, 2006, 01:00:45 PM
Don't forget to check in with or get Win32 Programmer's Reference.  It's a must for Asm programmer... It make API calls so much easier to understand and work with.

BOOL CreateProcess(

    LPCTSTR  lpApplicationName,   // pointer to name of executable module
    LPTSTR  lpCommandLine,   // pointer to command line string
    LPSECURITY_ATTRIBUTES  lpProcessAttributes,// pointer to process security attributes
    LPSECURITY_ATTRIBUTES  lpThreadAttributes,   // pointer to thread security attributes
    BOOL  bInheritHandles,   // handle inheritance flag
    DWORD  dwCreationFlags,   // creation flags
    LPVOID  lpEnvironment,   // pointer to new environment block
    LPCTSTR  lpCurrentDirectory,   // pointer to current directory name
    LPSTARTUPINFO  lpStartupInfo,   // pointer to STARTUPINFO
    LPPROCESS_INFORMATION  lpProcessInformation    // pointer to PROCESS_INFORMATION 
   );

Title: Re: More of the same thing.(WINEXE or ShellExecute)
Post by: IAO on March 24, 2006, 07:21:26 PM
Hi to all:

My Lord  Emperor:
You are right.

I made the error. I copied bad in a paper. I am a donkey. :dance:
Please accept my apologies. Whole-heartedly.
Pardon me.  I am ashamed.  :'( :(

Mr. ic2:  
I will be more careful.
But when I read my notebook and I compare. I said, I am a donkey.

I do not have Internet in my House. For me, everything is a little more difficult.
But I try, But I try.

Thanks, Thanks. 

Thanks for your patience and help. Whole-heartedly. (Heart of Donkey).

Bye ('_').