The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: elmo on October 21, 2010, 07:12:16 AM

Title: open external file with own program.
Post by: elmo on October 21, 2010, 07:12:16 AM
I follow code example in richedit:
I want to do this:
I want to open FileName.asm
I do right-click on FileName.asm. I click openWith. I click my own program.
It must show whatever I type in FileName.asm in my own program.
But I fail to show it. It always show eax<>1 ("Sorry, cannot find that file.")
What problem with the code below?


      ; ------------------------------
      ; get any command line filename
      ; ------------------------------
      invoke PathGetArgs,CmdLine
      mov fo, eax

      mov esi, eax
      lodsb
      cmp al, 0
      je noArgs       ; jump if no arg
      cmp al, 34
      jne @F          ; jump if no quote

      invoke PathUnquoteSpaces,fo
      mov fo, eax
      @@:



      invoke exist,addr fo
      .if eax == 1
         invoke CreateFile,
                  ADDR fo,
                  GENERIC_READ,
                  FILE_SHARE_READ,
                  NULL,
                  OPEN_EXISTING,
                  FILE_ATTRIBUTE_NORMAL,
                  NULL
         mov hFile, eax
         invoke MessageBox,hWnd,str$(hFile),SADD("hFile"),MB_OK

         invoke GetFileSize,hFile,NULL
         mov ln, eax
         invoke MessageBox,hWnd,str$(ln),SADD("FILE SIZE [BYTES]"),MB_OK

         .if ln > 5000000
            invoke CloseHandle,hFile
            szText CONFIRM_FileSizeTooBig1,"Sorry, file is too large for the editor"
            invoke MessageBox,hWnd,ADDR CONFIRM_FileSizeTooBig1,ADDR CONFIRM_DEBUG,MB_OK
            xor eax, eax
            ret
         .endif

         invoke SysAllocStringByteLen,0,ln
         mov hMem$, eax

         invoke ReadFile,hFile,hMem$,ln,ADDR br,NULL
         invoke SetWindowText,hEdit40,hMem$

         invoke SysFreeString,hMem$
         invoke CloseHandle,hFile

         invoke dwtoa,ln,ADDR STRAccno
         invoke SendMessage,hStatus,SB_SETTEXT,2,ADDR STRAccno
         invoke SendMessage,hEdit40,EM_SETMODIFY,0,0
         invoke SetWindowText,hChild4,ADDR fo
      .else
         szText cantfind,"Sorry, cannot find that file."
         invoke MessageBox,hWnd,addr strConnect,ADDR cantfind,MB_OK
      .endif



      noArgs:




Thank you
Title: Re: open external file with own program.
Post by: hutch-- on October 22, 2010, 06:53:21 AM
Fritz,

It looks like from your range of questions that you need to start learning how to write both assembler code and Windows API code because until you have some idea of both you will not get anywhere. Posting bits of other peoples code and asking how it works is a waste of time. This is not a beginners forum, we help who we can but we do not take on the responsibility of teaching learners from scratch, perhaps you should be working in a less complicated environment until you learn more about both assembler and API programming.