Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop button doesn't work when API referenced from Addin #4

Open
Greedquest opened this issue Sep 28, 2020 · 2 comments
Open

Stop button doesn't work when API referenced from Addin #4

Greedquest opened this issue Sep 28, 2020 · 2 comments

Comments

@Greedquest
Copy link
Owner

Greedquest commented Sep 28, 2020

It seems Excel loads addins as quite separate files, and interestingly the Stop button does not affect VBA loaded in the addin. This could certainly have some positives, in ensuring certain objects persist beyond timer destruction, allowing for safe cleanup.

Couple of solutions

  • Move out of addin and into self extractor for sharing code, this way everything is as normal
  • Get user code to supply the Userform ref that hosts the timer
  • Create a VBA function that persists after stop button press and does something clever. This could also stop the End statement crashes perhaps
@Greedquest
Copy link
Owner Author

A cool opportunity here is to remove the ties to a Userform; the original reason for using a Userform was not to provide a hwnd for the timer messages - the thread message queue (hwndless) would suffice - but to invalidate the timers upon state loss. This is because when hitting the stop button you kill VBA callback functions but not the WinAPI calling them, so WinAPI would crash the host when it tried to call a TIMERPROC that no longer existed. Userforms are killed by VBA, removing the hwnd and invalidating WM_TIMER messages so the now destroyed TIMERPROCs are never called (I guess there is no race condition here because VBA cleanup is in the same thread as the message queue so the hwnd is always invalidated in the same (atomic?) step as the TIMERPROCs).

Anyway if VBA code in an addin survives termination of the main project, then the TIMERPROCS could persist after state loss and do something a bit more flexible than just disappearing. Plus there would be no need to tie the timer messages to a userform which has always felt weird. This still leaves the issue of detecting state loss in the main project (we don't want the addin timers going off indefinitely) but worth thinking about...

@Greedquest
Copy link
Owner Author

Another avenue; create timers and invoke from tB out of proc or inproc dll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant