Monday, June 11, 2007

Code, manifest yourself!

(Warning: Extreme nerdy article to follow - talks about C++ code and Visual Studio 2005) - You've been warned!

You might want to chalk this one up to "lessons that were learnt the hard way"...

I was investigating a report from some users on our PMDGSounds.DLL failing to load entirely. So I thought: I must have screwed something up with the release builds - possibly linking to the wrong SimConnect.DLL version. Nope -that wasn't it.

I discovered (after having to remote-login to a beta tester's PC and after going through all the pains of changing .ini settings so that logs can be created) that it was really an issue with dependencies, but of the wrong kind: I had done my latest build on Vista and VS2005 - which since I am regularly updating my setup, had been updated to include SP1 and the latest Vista patch. As such, all MFC and CRT libraries were now linking with the newer SxS assemblies, rather than the RTM builds that FSX links against. Ergo, the missing dependencies on only some users' PCs, ergo my frustration.

This wasn't the first time I had run into this issue, though, so I went back to my notes... I had discussed this with our friends at Microsoft who had suggested / recommended a flag in the Preprocessor settings: _USE_RTM_VERSION, which supposedly will instruct the linker to embed the RTM version of the CRT and MFC libs in the manifest files...

The hard lesson is (after 4 hours of tests) that this holds true for executables (.EXE files) but NOT for DLLs. As most of our addon code is, well, added on to FSX, it comes as multiple DLLs and thus dependencies fail.

The fix isn't what I consider "beautiful" - rather than depending on the auto-magical way VS2005 embeds manifests, I had to make a manifest file myself with the appropriate versions and include that as an RT_MANIFEST resource in the .rc file.

Seems to work, but what happens if later I'd like to add another library dependency? I'll lose the ability for VS2005 to pick up on the new lib automatically and I'll have to remember to add it in the manifest file now...

So much for progress, I guess...

No comments: