News:

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

More of the same thing.(WINEXE or ShellExecute)

Started by IAO, March 21, 2006, 08:11:22 PM

Previous topic - Next topic

IAO

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]
"There is no way to peace. Peace is the way."    Mahatma Gandhi

PBrennick

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
The GeneSys Project is available from:
The Repository or My crappy website

ChrisLeslie

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

IAO

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 ('_').
"There is no way to peace. Peace is the way."    Mahatma Gandhi

IAO

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 ('_').
"There is no way to peace. Peace is the way."    Mahatma Gandhi

IAO

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]
"There is no way to peace. Peace is the way."    Mahatma Gandhi

Emperor

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

Mark Jones

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
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

asmfan

Russia is a weird place

IAO

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 ('_').
"There is no way to peace. Peace is the way."    Mahatma Gandhi

IAO

#10
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 ('_').
"There is no way to peace. Peace is the way."    Mahatma Gandhi

IAO

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 ('_').
"There is no way to peace. Peace is the way."    Mahatma Gandhi

Emperor

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

ic2

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 
   );


IAO

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 ('_').
"There is no way to peace. Peace is the way."    Mahatma Gandhi