Fixing problems with FindActCtxSectionString in MFC security updates

EDIT – June 18th, 2011 – the below blog entry is out of date – click here for up to date information.

In this blog entry I attempt to fix 3 of the problems associated with FindActCtxSectionString in a statically linked application (2005 and 2008). What I’m going to do is override the appcore.cpp that gets included in every static app with one that we’ll include in our app (again, like the last blog, no editing of the included file is necessary, which is a good thing because if there any updates you’ll get them by rebuilding)

1) Open up your stdafx.cpp file in your project (a statically linked MFC project)
2) Paste the following code after the include:

Hi Guy, thanks for the feedback. I should have mentioned, under 2005, there are warnings with WINVER and _WIN32_WINNT but they don’t prevent the compilation (unless you have warnings as errors turned on). But your solution is a valid one as well.

In case someone else needs the fix for 2008/2010, here’s what we did:
1. Copy the contents of appcore.cpp into stdafx.cpp
2. Remove the 3 #includes from the top
3. Use the following definitions before adding the fix in the post:

Hi Guy thanks for the clarification, just let me know the missing 2 includes that didn’t come in through your comment, and i’ll re-edit the response. Also with VC2008SP1 (not VC2010+v90) it seems to work in the original way I described, so thanks for testing your particular combination as well.

I think I have found the workaround. Even uninstalling the Microsoft patch doesn’t restore the old MFC files. Another link I found shows where the old files are stored in WINSXS and you can restore them into SYSTEM32. I think that has fixed the problem I was having with a Win2K computer and a version of the Sonicwall client.