Sunday, December 31, 2017

Invoke functions by pointer

Previously, my P/Invoke command-line tool (which is in desperate need of an actual name) was unable to work with COM objects because the tool requires a library and name for functions it calls. COM objects appear from CoCreateInstance and their methods are accessible in their VTable, which is a member of each object/struct. To use them, I implemented the ability to call methods by a function pointer held in a slot. Currently, doing that requires some seriously ugly script, but at least it's now possible at all.

As a not-super-useful but concept-proving demonstration, this creates an IFhConfigMgr and calls AddRef:
newslot native fhPtr
call ole32.dll!CoCreateInstance /return uint (blockptr(guid {ED43BB3C-09E9-498a-9DF6-2177244C6DB4}), nullptr, int 1, blockptr(guid {6A5FEA5B-BF8F-4EE5-B8C3-44D8A0D7331C}), slotptr fhPtr)
newslot native fh
copyslot fh = fhPtr dereferenced
newslot block vtbl = nullptr, nullptr, nullptr, nullptr
copyslot vtbl = fh dereferenced
newslot native addref
copyslot addref = vtbl field 1
call funcat addref /call thiscall /return uint (slotdata fhPtr)

The funcat (that's "function at", not "fun cat", even though cats are pretty great) keyword on the call command is the new addition that does all the heavy lifting.

Saturday, December 30, 2017

FMod - Multiple tour watchdog planes

When I last left off working on the Abiathar tour, I noticed that since the watchdog render plane can only be registered for one level plane, it won't pick up the user's tile placing if it doesn't happen to affect that plane. So today, I made the tour extension register three watchdog planes, one for each level plane. The foreground is special-cased to be the only plane that triggers advancement past the task that asks the user to adjust the foreground only.

.NET bitness matters when using ODBC drivers

.NET assemblies can be compiled in the AnyCPU configuration, in which they can work on either 32-bit or 64-bit machines but have a preference for one or the other. For most applications, this probably doesn't matter too much. However, it definitely can cause issues if native modules are in play, like ODBC drivers. Some ODBC drivers are only registered for one bitness, so trying to start a connection using one might mysteriously fail on a machine with a different architecture. This caused some trouble for me in a recent deployment.

In these cases, it's probably easiest to compile for only the architecture with known-working ODBC drivers in the deployment environment.

Thursday, December 28, 2017

Where PowerShell stores the Ctrl+R history

One user wanted to know where PowerShell stores the console history that's searched by the Ctrl+R feature so that it could be brought across to a new machine. PSReadline stores it here:

%APPDATA%\Microsoft\Windows\PowerShell\PSReadline\ConsoleHost_history.txt

Migrating the console history is as simple as copying that file over (though some directories might have to be created).

Wednesday, December 27, 2017

SQL Server Management Studio might need to be run as administrator

Today I needed to attach a database to an SQL Server instance. When I had it attempt the attachment, the operation failed, claiming that there was an access denied error about the database file. That seemed strange because my user account was the one that had extracted the database file, so I clearly had the rights to modify it. Nevertheless, restarting the management tool elevated made the operation succeed.

Tuesday, December 26, 2017

FMod - Tour fixed

Today I figured out why the presence of the tour panel made keyboard events not go to the main form. As I suspected, the "exit tour" link gets focus when it's visible. The solution was to respond to the GotFocus event of that link (and also of the Proceed button) and set the focus to some inert label instead.

With that sorted out, I continued writing the tour. It now instructs the user to switch to a different level (since actual levels are more interesting than the world map), pick up tiles, place them, and adjust plane states.

Monday, December 25, 2017

Interacting with elevated windows from Chrome Remote Desktop

Under most circumstances, the assistant in a Chrome Remote Desktop connection cannot interact with windows from elevated programs. This is due to Windows's User Interface Privilege Isolation mechanism. This makes system configuration tasks difficult through Chrome Remote Desktop. I suspect disabling UAC would do it, but there is another workaround if the host would prefer not to do that. These steps apply to the host (nothing special needs to be done by the helper to initiate the session):
  1. Make sure Chrome is closed
  2. Launch Chrome Remote Desktop from the Start menu as administrator
  3. Connect as normal
  4. If necessary, Chrome can be reopened now
  5. Launch an elevated command prompt
  6. Accept the UAC dialog on the host machine
  7. Launch any necessary administrative tools from that command prompt
The helper cannot access the secure desktop, so any elevation prompts will render the session inoperable. Since child processes of elevated processes are also elevated, all elevation must be done by using that command prompt.