CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 25 of 25

Thread: Auto updater WinApi

  1. #16
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,477

    Re: Auto updater WinApi

    After calling which function are you calling GetLastError()? Note that GetLastError() only returns a valid error code under the conditions documented by the proceeding function call. Just calling GetLastError() after any function call and without checking first whether the function succeeded or failed will not give a reliable value.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.9.5)

  2. #17
    Join Date
    May 2017
    Posts
    13

    Re: Auto updater WinApi

    Quote Originally Posted by 2kaud View Post
    After calling which function are you calling GetLastError()? Note that GetLastError() only returns a valid error code under the conditions documented by the proceeding function call. Just calling GetLastError() after any function call and without checking first whether the function succeeded or failed will not give a reliable value.
    I call GetLastError after the WaitForSingleObject. If the mask par. in shellexecuteinfo is MASK_NOCLOSEAPP don't remember the correct name, then the error is 0 but is it's SYNCHRONIZE then the GetLastError is 6.
    Ok. Got it. By exploring more, I noticed that if the ShellExecuteEx is called on creating a console app then the WaitForSingleObject works ok, but when I call it on a GUI application then the WaitForSingleObject is being ignored.
    In shellexecuteEx I'm setting the hwnd parameter it is not a NULL value.

  3. #18
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,477

    Re: Auto updater WinApi

    Following a call to WaitForSingleObject(), GetLastError() is only valid when WaitForSingleObject() returns a value of WAIT_FAILED. For any other return value, calling GetLastError() is not supported and hence its return value shouldn't be used.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.9.5)

  4. #19
    Join Date
    May 2017
    Posts
    13

    Re: Auto updater WinApi

    And what to do that the WaitForSingleObject works with console app and not with the GUI ones?

  5. #20
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,477

    Re: Auto updater WinApi

    What program are you calling from ShellExecuteEx()? Does this program create other processes? WaitForSingleObject() works OK on my Windows 10 when waiting for the gui programs I've tried.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.9.5)

  6. #21
    Join Date
    May 2017
    Posts
    13

    Re: Auto updater WinApi

    Quote Originally Posted by 2kaud View Post
    What program are you calling from ShellExecuteEx()? Does this program create other processes? WaitForSingleObject() works OK on my Windows 10 when waiting for the gui programs I've tried.
    well the process creation is like this:
    process A calls a console process the console calls a gui process(needs UAC), when process A calls a console then WaitForSingleObjects waits, but when the console part calls the GUI then it does not wait.

  7. #22
    Join Date
    May 2017
    Posts
    13

    Re: Auto updater WinApi

    Quote Originally Posted by 2kaud View Post
    What program are you calling from ShellExecuteEx()? Does this program create other processes? WaitForSingleObject() works OK on my Windows 10 when waiting for the gui programs I've tried.
    I'm running a NSIS uninstaller over the ShellExecuteEx and the console app does not wait for it to finish. But when I try to run a notepad by specifing the full path the the WaitForSingleObject function works ok.

  8. #23
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,477

    Re: Auto updater WinApi

    So the issue is with the NSIS uninstaller. I wonder if NSIS spawns new process(s)? That would fit with what is happening. NSIS does some work, spawns a new process and then exits. The new process continues to run but as the original process has terminated, WaitForSingleObject() returns because the process it is waiting on has terminated.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.9.5)

  9. #24
    Join Date
    May 2017
    Posts
    13

    Re: Auto updater WinApi

    Quote Originally Posted by 2kaud View Post
    So the issue is with the NSIS uninstaller. I wonder if NSIS spawns new process(s)? That would fit with what is happening. NSIS does some work, spawns a new process and then exits. The new process continues to run but as the original process has terminated, WaitForSingleObject() returns because the process it is waiting on has terminated.
    So when I spawn NSIS process, it then spawns another one?
    How I can bypass this?

  10. #25
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,477

    Re: Auto updater WinApi

    Quote Originally Posted by mandruk1331 View Post
    So when I spawn NSIS process, it then spawns another one?
    How I can bypass this?
    That could be one explanation. If it is, then you can't bypass it - as you can't change NSIS behaviour. If you could find out if there is another process involved then it should be possible to open a handle to this other process and then wait on that handle.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++20 Compiler: Microsoft VS2019 (16.9.5)

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)