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

Removal of TimerHook and update Kernel32/User32/HotKey #3663

Merged
merged 4 commits into from
Jan 3, 2018

Conversation

bclothier
Copy link
Contributor

Closes #3662; add explicit logging for errors arising from Win32 API which will not necessarily throw exceptions.

@@ -31,8 +33,27 @@ public void Attach()
try
{
var timerId = (IntPtr)Kernel32.GlobalAddAtom(Guid.NewGuid().ToString());
Copy link
Contributor Author

@bclothier bclothier Jan 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I'm reading the documentation on the SetTimer and there is no mention of needing a global atom. I'm not sure what purpose the global atom is supposed to serve here, given that we are generating a new GUID every time we invoke the Attach which will never match any existing entries in the global atom table. Can anyone explain why we need this? Otherwise, this strikes me as a cargo-cult programming...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, although you need to supply a timer ID of some sort. The relevant part of the documentation says "If the hWnd parameter is not NULL and the window specified by hWnd already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer". The rest of it (e.g. saying that a new timer ID will be allocated for you) refers to where hWnd is being passed a NULL, so doesn't seem to apply.

Using a global atom is clearly not a requirement though. You just need to be prepared for your specified ID to be already assigned to a timer (e.g. by another addin, or the VBE itself), so make it something as unique as you can to avoid conflicts. It's rubbish actually, because if it just replaces the existing timer hook, then it gives you no chance to try another ID without affecting the old one that we might not have created.

using Rubberduck.Common.WinAPI;
using NLog;

namespace Rubberduck.Common
{
public class TimerHook : IAttachable, IDisposable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this class even in use? It is referenced in the RubberduckIocInstaller but by time RD loads, the class is never instantiated nor its methods called....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... indeed, that does appear to be the case! I love wasting my time ;-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is a remenant of the old timed logger interceptor, which has been removed because there has been the feeling that the inability to proply use reflection on the intercepted inspections (to get their type) was too much of a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, if there's no objection, I will revise the PR to delete the file altogether and remove it from the IoC installer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good. If it's never used, it should be deleted 👍

Remove TimerHook's entry from the IoC.
Clean up of Kernel32 and User32, removing unused declares.
Make calls to Kernel32 in HotKey compliant with documentation and explicitly checking the error status for all Kernel32 calls.
@bclothier bclothier changed the title TimerHook Fixs Removal of TimerHook and update Kernel32/User32/HotKey Jan 2, 2018
Copy link
Member

@Vogel612 Vogel612 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Vogel612 Vogel612 merged commit 9055643 into rubberduck-vba:next Jan 3, 2018
This was referenced Jan 5, 2018
@bclothier bclothier deleted the TimerHookFix branch December 5, 2018 19:57
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

Successfully merging this pull request may close these issues.

None yet

4 participants