Page 4 of 4

Re: CopyFileEx API call

Posted: Thu Nov 21, 2019 8:54 am
by infratec
You implemented my include totally wrong.

Here is the correct way:

Code: Select all

Enumeration
  #Form0
  #EditorCommand
  #StringCommand
  #Button
EndEnumeration



IncludeFile "ExternalProgram.pbi"


Define Event.i, Exit.i, i.i, j.i
Define ThreadParameter.ExternalProgramParameterStructure
Define Source$, Destination$, ProgramFilePath$

ProgramFilePath$ = GetPathPart(ProgramFilename())

Source$ = PathRequester("Source", ProgramFilePath$)
If Source$
  Destination$ = PathRequester("Destination", ProgramFilePath$)
  If Destination$
    
    LoadFont(0, "Consolas", 10)
    
    OpenWindow(#Form0, 379, 176, 608, 542, "Backup User Profile", #PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_TitleBar)
    EditorGadget(#EditorCommand, 5, 15, 593, 447, #PB_Editor_ReadOnly)
    SetGadgetFont(#EditorCommand, FontID(0))
    StringGadget(#StringCommand, 6, 469, 594, 23, "/S /E /TEE /log:backup.log "+ Source$ + " " + Destination$)
    ButtonGadget(#Button, 211, 503, 201, 33, "Begin Backup!")
    
    ThreadParameter\Program$ = "robocopy.exe"
    ThreadParameter\ProgramReadWriteMode = #PB_Program_Ascii
    ThreadParameter\ProgramExit$ = "Break"
    ThreadParameter\Semaphore = CreateSemaphore()
    ThreadParameter\Mutex = CreateMutex()
    
    Repeat
      
      Event = WaitWindowEvent()
      
      Select Event
        Case #ExternalProgram_Event_StdOut
          ThreadParameter\StdOut$ = RemoveString(ThreadParameter\StdOut$, #CR$)
          ThreadParameter\StdOut$ = RTrim(ThreadParameter\StdOut$, #LF$)
          i = CountString(ThreadParameter\StdOut$, #LF$)
          For j = 0 To i
            AddGadgetItem(#EditorCommand, -1, StringField(ThreadParameter\StdOut$, j + 1, #LF$))
          Next j
          SignalSemaphore(ThreadParameter\Semaphore)
          
        Case #ExternalProgram_Event_Error
          Debug ThreadParameter\StdErr$
          SignalSemaphore(ThreadParameter\Semaphore)
          
        Case #ExternalProgram_Event_Exit
          DisableGadget(#Button, #False)
          
        Case #PB_Event_Gadget
          Select EventGadget()
            Case #Button
              ThreadParameter\ProgramParameter$ = GetGadgetText(#StringCommand)
              ThreadParameter\Thread = CreateThread(@ExternalProgramThread(), @ThreadParameter)
              DisableGadget(#Button, #True)
          EndSelect
          
        Case #PB_Event_CloseWindow
          If IsThread(ThreadParameter\Thread)
            ThreadParameter\Exit = #True
            WaitThread(ThreadParameter\Thread)
          EndIf
          FreeMutex(ThreadParameter\Mutex)
          FreeSemaphore(ThreadParameter\Semaphore)
          Exit = #True
      EndSelect
      
    Until Exit
  EndIf
EndIf
And you have to copy my include stuff again, because I modified it a bit.
The character modes were not correct handled.

Re: CopyFileEx API call

Posted: Thu Nov 21, 2019 1:47 pm
by gonpublic2k
Understood. Thanks for the correction, I'll play with the modified version. Although now I'm taking a look into the
skeleton that Marcus provided. Did you take a look a it? It's more or less what I was trying to accomplish, it's a
great base to work on and develop it to be a great application. I appreciate your help and Marcus's and everyone
else who has showed interest. :D

Re: CopyFileEx API call

Posted: Thu Nov 21, 2019 2:46 pm
by gonpublic2k
And you have to copy my include stuff again, because I modified it a bit.
The character modes were not correct handled.
Show me the part I need to correct in ExternalProgram.pbi - I can't find the updated
version that you said you changed. I tested your code and it gave me an error.

[ERROR] ReadProgramError(): invalid value specified for parameter "Flags".

Please :D

Re: CopyFileEx API call

Posted: Thu Nov 21, 2019 3:52 pm
by Marc56us
gonpublic2k wrote: [ERROR] ReadProgramError(): invalid value specified for parameter "Flags".
Have you compared with the possible values given in the help on ReadProgramError() ?

:wink:

Re: CopyFileEx API call

Posted: Thu Nov 21, 2019 4:07 pm
by gonpublic2k
Marc56us wrote:
gonpublic2k wrote: [ERROR] ReadProgramError(): invalid value specified for parameter "Flags".
Have you compared with the possible values given in the help on ReadProgramError() ?

:wink:
yes, it only takes two parameters as especified in the code written by infratec.

Code: Select all

ReadProgramError(Program[,Format]) - Read a line from the standard error output of the program
Therefore I'm not sure as to why the error. Infratec mentioned he made some changes to the code (ExternalProgram.pbi) so maybe
that has something to do with taking care of this. Just waiting for him to publish the updated code.

:)

Re: CopyFileEx API call

Posted: Thu Nov 21, 2019 4:21 pm
by gonpublic2k
gonpublic2k wrote:
Marc56us wrote:
gonpublic2k wrote: [ERROR] ReadProgramError(): invalid value specified for parameter "Flags".
Have you compared with the possible values given in the help on ReadProgramError() ?

:wink:
yes, it only takes two parameters as especified in the code written by infratec.

Code: Select all

ReadProgramError(Program[,Format]) - Read a line from the standard error output of the program
Therefore I'm not sure as to why the error. Infratec mentioned he made some changes to the code (ExternalProgram.pbi) so maybe
that has something to do with taking care of this. Just waiting for him to publish the updated code.

:)
Never mind, Just as I was writing this, I went back to the original thread and saw Infratec's correction there. It's working as expected now.

Thanks!

Re: CopyFileEx API call

Posted: Thu Nov 21, 2019 6:11 pm
by Marc56us
[ERROR] ReadProgramError(): invalid value specified for parameter "Flags".
...Have you compared with the possible values given in the help on ReadProgramError() ?
... ...yes, it only takes two parameters as especified in the code written by infratec.
I'm glad it's working now, but in general, you should read the message carefully.
It is not written that the number of parameters is wrong, but that the Flag value is not the expected one
Expected values are 24 or 2 or 25

To see the values of the constants, use Debug

Code: Select all

Debug #PB_Ascii
Debug #PB_UTF8
Debug #PB_Unicode
:wink:

Re: CopyFileEx API call

Posted: Thu Nov 21, 2019 7:26 pm
by gonpublic2k
Marc56us wrote:
[ERROR] ReadProgramError(): invalid value specified for parameter "Flags".
...Have you compared with the possible values given in the help on ReadProgramError() ?
... ...yes, it only takes two parameters as especified in the code written by infratec.
I'm glad it's working now, but in general, you should read the message carefully.
It is not written that the number of parameters is wrong, but that the Flag value is not the expected one
Expected values are 24 or 2 or 25

To see the values of the constants, use Debug

Code: Select all

Debug #PB_Ascii
Debug #PB_UTF8
Debug #PB_Unicode
:wink:
Okie. Noted. Thank you!

Re: CopyFileEx API call

Posted: Tue Nov 26, 2019 1:31 pm
by gonpublic2k
Hello all,

Hi @Marc56us, any other updates to this that we need to know of? :)