Friday, November 23, 2018

Putting items in the New context menu above the separator line

One user wanted to put a custom New submenu entry above the separator line (right under Folder and Shortcut) instead of among the normal entries. At first I assumed this was impossible and that the above-separator entries were hardcoded, but then I did some disassembling.

shell32.dll has a CNewMenu::_BeforeSeparator function that determines whether a given entry will be placed above the separator. It first checks the file type against a hardcoded list, but if that check fails, it also checks a flag in the NEWOBJECTINFO structure. It looks like those structures are set up by the _GetNewObjectInfoForKey structure, which calls _GetConfigFlags on the Config subkey of ShellNew to populate the field containing that flag. _GetConfigFlags checks for the existence of a bunch of entries, setting flags as it goes along. The Registry entry for the flag of interest is named BeforeSeparator.

So, placing a value named BeforeSeparator in the Config subkey under ShellNew for a New menu item will move that menu entry above the separator:


Thursday, November 22, 2018

SprintDLL - v1.2

Previously I had been planning to release a new version of SprintDLL after making it easier to call COM methods. But then I realized I'd been sitting on a pile of really useful progress that hadn't even be pushed to GitHub yet. So today I put all my changes in the GitHub repository, compiled a Release build, and published v1.2.

Wednesday, November 21, 2018

Sometimes it's easier to blow away the entire profile

Today I investigated an issue that only appeared for one user on one specific computer in a domain. In this organization, local user profiles don't contain any important information - all work is done on a centralized database. It would have been possible to hunt the problem down, but finding the specific Registry entry would have taken quite a while. So I simply deleted the affected user's local profile using the User Profiles section of the Advanced tab on the System Properties window. When the user next logged on, they received a fresh profile unaffected by the glitch.

(I did later find what caused the problem, but was not able to narrow it down to the Registry entry that got the problematic application stuck.)

Monday, November 19, 2018

Crashes in innocuous destructors can indicate memory corruption elsewhere

Earlier today I was debugging a double-free crash in a C++ application. A backtrace from gdb showed that the crash occurred in the destructor of a vector of ints, which should be foolproof - all the memory is managed by the vector. Debugging with Valgrind found some bad memory accesses in a completely different method. Fixing that issue solved the crash problem. If memory corruption is in play, bizarre things can happen.

Sunday, November 18, 2018

Windows Forms DPI scaling goes better on Windows 10 than Windows 7

I noticed that, despite all Windows Forms settings I tried for a .NET application, some forms would scale improperly on Windows 7. Specifically, some controls would be scaled, but the form wouldn't be, cutting off some controls. I couldn't even find a way to disable scaling entirely for the program. Happily, this issue doesn't seem to occur on Windows 10.

Monday, November 12, 2018

TestNG results in Android Studio can be stale if there are build failures

One student asked about a puzzling failure in a TestNG test in Android Studio. Their code seemed correct and in fact worked on my machine. Apparently there was a compilation failure somewhere in the project that of course prevented a new executable from being generated, causing the test suite to test an outdated version. Build | Rebuild Project (to do a recompile and show the Build tab) helped identify the problem.

Sunday, November 11, 2018

Mysterious checkstyle failures are sometimes fixed by reinstalling the plugin

Occasionally students have run into an "Unable to create listeners: formatters" error from checkstyle run in a Gradle task in Android Studio. I haven't yet figured out what actually causes it, but I have noticed that uninstalling and reinstalling the CheckStyle-IDEA plugin has fixed the problem for some people. It's also possible for Gradle to use checkstyle without having the IDE plugin installed - the task can still use checkstyle results, but the warnings won't be displayed in the code editor window.

Invalidate Caches / Restart can also help "no tests found in the package"

A couple students received "no tests found in the package" errors from TestNG in Android Studio even though the tests could compile successfully. Everything seemed to be in order, and an abridged version of the test results even appeared in the [build] tab. I asked the students to try a Gradle sync and a File | Invalidate Caches / Restart and that appeared to fix it. In general, mysterious problems tend to go away with a resync or cache clear.

Thursday, November 8, 2018

When test results vanish from IntelliJ

Several times, students have reported seeing some test results not show up in the Test results pane in IntelliJ or Android Studio. Only successful tests disappeared; all the ones that still appear are failed. This happens because of accidental pressing of the green check toggle button in the upper left of the results pane. When that button is not pushed in, passing tests are hidden.

I can see why multiple people have been confused - it's really easy to accidentally toggle that button when trying to expand the tests list view (the dropdown and button are really close) and not realize what happened.

Monday, November 5, 2018

Daylight Savings Time and hardcoded date formats

This morning I woke up to discover that my app was broken. It was unable to parse date-times from the API it uses because of a format mismatch. When I originally wrote that bit of code, I saw that there was a timezone fragment (containing the offset from UTC) that was always the same, since the app is for a transportation system within one time zone. But when Daylight Savings Time ended, the offset shifted by an hour, making the strings not match the literal timezone fragment. I suppose the moral of the story is to be very careful with timezones because DST transitions will wreak havoc.

Sunday, November 4, 2018

Android Studio sometimes destroys run configurations

I've observed Android Studio deleting all the run configurations when the project is imported or (sometimes) opened, for unclear reasons. One solution I've seen used is to keep the run configurations in a separate folder and copy them over to .idea/runConfigurations in a Gradle task set as a finalizedBy on every other task. Crude but effective.

Saturday, November 3, 2018

Writing PSThar scripts that compile C# code

PowerShell run scripts inside the PSThar extension for Abiathar automatically have access to Abiathar/FleexCore2 features. But if that PowerShell code tries to use Add-Type to compile and run C# code, it may encounter errors about not being able to find a type or namespace. The solution is to provide the three Abiathar assemblies to Add-Type:
Add-Type $code -ReferencedAssemblies ([Abiathar.Interop.IAbiatharState].Assembly, [FMod.GalaxyLevels].Assembly, $Abiathar.GetType().Assembly)

For most operations, only the first assembly (the Abiathar extension API) should be necessary. The second is FleexCore2, which is needed if using that directly instead of through Abiathar's API. The Abiathar assembly itself shouldn't usually need to be referenced; relying on internal details will lead to fragile scripts.

Friday, November 2, 2018

TestNG's assertEquals will iterate an iterable

Today I saw a confusing test failure message from TestNG. I was using assertEquals to see if two objects were the same and expected the check to use reference equality, since the objects' class didn't override equals. Instead there was a message about some other objects not being equal and an iterator differing at a certain position. Since I hadn't overriden equals to examine objects referred to, I was confused for a moment until I remembered that the class was iterable. Apparently TestNG checks for that and will do an item-by-item comparison if possible. To just check for reference equality, I switched to assertSame.