In my system, Windows 10, this is not working. I have two Spanish layouts and one English. I don't know if this is the cause. I got Assertion fail in SetDefaultLayout and GetLastError returns 5.
I managed to get it working by sending the hkl value received from API.GetKeyboardLayoutList instead of the one "generated" like this IntPtr hkl = new IntPtr(unchecked((int)((uint)layout << 16 | (uint)layout))); and then it kind of works.
I had made several changes to this to work but then the save config.txt needs more work so I'm not PRing this, I might do it later or branch it