Add the correct interface first in Adding an MFC Class from an ActiveX Control wizard.

In good old times aka VC6, if you want to use an ActiveX in MFC, the Components and Controls Gallery would generate all the properties and methods of an ActiveX and pull dependent types and create wrapper classes for them as well. And it was good. It magically knows the main class of the Windows Media Player ActiveX is CWMPPlayer4 and that GetCurrentMedia method returns CWMPMedia.

Welcome to the modern Visual C++. Now comes a new wizard that gives you options to choose interfaces to import from. At the same time you got to decide if you really need that many types from an ActiveX.  If you went the unfortunate path of Adding a Member Variable wizard in the dialog editor and somehow got a COCX1 class back, you don’t have the luxury to choose, and you end up with an CWnd wrapper class that does not really wrap up the properties and methods of the ActiveX. It is still good for early binding (like querying IWMPPlayer4 from the result of CWnd::GetControlUnknown) but if you plan to use late binding and MFC’s OLE support (hello COleException!),  you probably want to delete the COCX1 files and start over with the Adding a Class from an ActiveX Control wizard.

Good thing about the new Adding a Class from an ActiveX Control wizard is that most of time we don’t care about the majority of the types in the ActiveX’s type library. We are not going to call most of the ActiveX’s functionality anyways, so selecting what we would use makes sense. Bad thing is that now we don’t know the return type of a method from the generated classes if the return type is LPDISPATCH, lead to guesswork or fire up OLEView to look up the types in the ActiveX’s type library).

Now comes the worst part of the new wizard. The wizard somehow lost its ability to find the correct ActiveX control class and opt to use the first selected interface to generate a CWnd wrapper.  If you naturally click on the >> button to select all interfaces in the Windows Media Player ActiveX at once, you get a CWMPCdromCollection derived from CWnd. That  won’t work as the ActiveX does not implement the IWMPCdromCollection interfaces (undefined behavior can happen if you call the generated methods), and certainly the WMPCdromCollection class isn’t an insertable ActiveX.

Fortunately it is easy to avoid this issue if you add the ActiveX’s main interface first (e.g. IWMPPlayer4 for the Windows Media Player control) before adding the rest of interfaces, or correct the generated code for the first interface. That is, swap the CWnd and COleDispatchDriver code between the wrong class and the correct class for the main interface. It takes some time to find the correct class for the ActiveX control, however.

Side note: For code cleanness, you probably want to move the InvokeHelper code in the headers to cpp files like VC6 did. A good C++ refactoring tool can help that tremendously.

Posted in enmsdn, MFC, Microsoft, Microsoft Foundation Class Library, Visual C++, Visual Studio | Tagged , , , | Leave a comment

Howto: reset IE security zone settings programmatically

Internet Explorer 7 introduced the IInternetZoneManagerEx2 interface, which has a FixUnsecureSettings method to reset all security zone settings. Like all other IInternetZoneManager* interfaces, you can query this interface from the internet zone manager object:

IInternetZoneManagerEx2* pzoneManager=NULL;

HRESULT hr=CoCreateInstance(CLSID_InternetZoneManager ,NULL,CLSCTX_INPROC_SERVER,IID_IInternetZoneManagerEx2,(LPVOID*)&pzoneManager);
if(hr==S_OK && pzoneManager!=NULL)

There’s another CoInternetCreateZoneManager function to get the zone manager object’s IInternetZoneManager interface.

Posted in enmsdn, Microsoft, Visual C++, Visual Studio, Webbrowser control | Tagged , , | 1 Comment

What’s new in MFC/ATL 11 Beta

Note this post is on Visual Studio 11 Beta, you can download it from

Since Sinofsky posted about no desktop apps on Windows on ARM (WOA), it looks like MFC and ATL are going to support metro-style apps, although most ATL classes are not going to be compatible with metro style apps.

#if !defined(_M_IX86) && !defined(_M_AMD64) && !defined(_M_ARM)
#error Compiling for unsupported platform. Only x86, x64 and ARM platforms are supported by MFC.

DAO support for ARM is missing, just like the lack of DAO support for 64 bit apps. Jet was deprecated a while ago, no surprise here.

You can now decide whether you want MFC’s feature pack code when static linking.

Added support for RichEdit 4.1. About time.

MFC now introduces dependency on uxtheme.dll and dwmapi.dll. Not sure why applications need to check MFC for DWM status.

Lots of defensive programming added to OLE and ActiveX document support. MFC developers have too much free time? I thought ActiveX document was dead. Or maybe someone else is pushing those changes, like Adobe or the Office team. Or Microsoft’s security police. Lots of function prototype changes, probably because MFC headers need to pass static code analysis. Some other security improvements, like loading known Dlls only from system path, skipping DLL search paths.  CDatabase now stores the connection string in memory in encrypted form.

Some new OS API exposure like CFile gets a lot more NTFS-specific attributes. CFileDialog gets a pick non-system folder mode.

Some design changes are head-scratching, CPropertyPage gets a GetParentSheet function. Looks like the parent of the page may no longer be a property sheet.

In summary, there isn’t much code change in MFC. The demands I see from community forums are mostly on C++11, which is not surprisingly the focus of the Visual C++ team in this release and probably will continue for a while.

Posted in Visual C++ | Tagged , , , | Leave a comment

Choosing formats when putting data on clipboard

The topic is from a forum discussion at

Generally an application should provide data in as many formats as possible so more applications can recognize the data. For example, IE stores text data in CF_UNICODETEXT, CF_TEXT and CF_HTML formats.

Because a lot of application would stop enumerating the clipboard on first supported format, to avoid data lose in round trips, clipboard formats that contain the most information should be placed on the clipboard first, followed by less descriptive formats. For example, CF_HTML first, CF_UNICODETEXT second and CF_TEXT last. Sometimes you get to choose from the paste format (e.g. paste special in Microsoft Word), but that’s the exception, not many program can paste the format that is not the first supported format (e.g. you don’t have paste special in Microsoft Paint).

Of course sometimes you want to limit, say, the format being exposed to the clipboard, e.g. when copying code from Visual Studio but expect the code to make a round trip back to Visual Studio without the formatting, then you may want to put a less descriptive format first. 

If using the webbrowser control as the text editor, you can remove the formatting in pasting by implementing OnFilterDataObject.


Posted in enmsdn, Webbrowser control | Tagged | Leave a comment

What’s new in Windows 8 Developer Preview SDK headers

This is by no means a complete list but just some observation on files that caught my eye. Some are just regular header file updates for Windows 7 and does not necessary require Windows 8. Some other APIs moved to header files with more readable names.

Improvements are focused, of course, in natural input, efficiency, gaming experience and IE. You can hear the silence scream of “Tablet!Tablet!Tablet!” here. Note Windows 8 is still a developer preview and there is no guarantee any new feature will survive the final cut or there won’t be new API for existing features add in Beta/RC/Gold.


There is no improvement in the GDI-based shell common controls. No surprise here. The new UI would be based on WinRT and will use GPU to render instead of CPU. There are COM API for printing, which is traditionally performed via GDI.

A lot of Direct2D and Direct3D improvements. XAudio2 added and battery/pad support  added to XInput. Improvement in 3D rendering, device removal during capturing and stream seeking in Windows Media Foundation. API for H264 codec.


Header guard for IE5.01 or lower are removed. Building for Windows 2000 is now practically impossible. Some header guard switched to NTDDI_VERSION. There is A new camera UI control based on COM. Somehow the version guard of Shell_NotifyIconGetRect is lost, this might be a header file bug.


Lots of IE 10 APIs and HTML 5 support. ActiveScript optimized for multiple instance and webworker. Also there is a new IActiveScriptContext interface to get url, line and offset of the script. New timeout configuration in WinInet. ActiveX filtering, and options to enable/disable audio/video plugins added for IE security zones.


Accessibility for windowless controls and lots of UI automation improvements, including grid and spreadsheet types. Candidate list integration and async document support with Text Service Framework. ARM support to .Net APIs.  A lot of pointer device and touch messages, notification and drawing.

Posted in enmsdn, Microsoft, Visual C++ | Tagged , , , , , | Leave a comment

Where is the forum for Internet Explorer?

People get confused by various Microsoft IE forum sites so here is the steps to find the forum closer to IE related questions

Basically, the mentality of different Microsoft forum brand is:

MSDN: How can my software do something on my customers’ machines.

Technet: How can I manage things on machines in my network.

Answers: How can I do something on my own machine.

So for the case involving IE:

  1. using IE
  2. manage IE on someone else’s machine, or IE behaves abnormally only when the IE settings is managed by the network administrator
  3. Writing IE-aware software or IE-aware web sites

What about other tasks?

  1. I have problem with an IE add-on
    contact the support channel of the add-on. For example if there is a problem when viewing PDF in IE, most likely you need to visit the Adobe Reader forum at A question that occurs only after installing Google ToolBar should be posted to Google’s help groups.
  2. I see an error message in IE when visiting a web site
    does the error message appear when you switch to another web browser?

    1. Yes
      Contact the author of the web site

      1. But I am the author of the web site!
        Then try ask in a forum that covers the server programming framework, for example, visit if you have ASP.Net errors.
    2. No
      Run IE in no-addon mode(shortcut can be found in programs->accessories), is the problem still there?

      1. Yes
        Do you see this error when visiting other web sites?

        1. Yes
        2. No
          Contact the author of the web site

          1. But I am the author of the web site!
            Then visit and remember to include your web site’s link when asking
      2. No, where do I find the faulty add-on?
        Tools->Manage addons, and disable one-by-one, I guess. Those experts in probably have more experience in known faulty add-ons.
  3. IE tells me there is a script error on the web site
    Does this problem occur regardless which web sites IE is showing?

    1. Yes
      Visit Oh, and if you are going to do a repair install of IE before asking, remember to turn antivirus off.
    2. No, the script error only occur on certain web sites
      Are you the author of the web site involved?
      1. No
        Contact the authors of the web sites.

        1. The author cannot be found or I can’t wait the author to release an update
          Add the web site to the compatibility view list to see if the site works in old browser emulation mode.
      2. Yes, I am the author
        If you can reproduce your problem in no-addon mode, visit 
Posted in Uncategorized | Tagged , | Leave a comment

Windows Update KB2538242 or KB2538243 offered repeatedly

Microsoft Update in Windows XP.

Image via Wikipedia

Recently there is an outburst of posts related to the KB2538242 update being offered repeatedly on MSDN’s Visual C++ forums, TechNet’s various Windows security forums and the Windows Update forum on Microsoft Answers forums. Questions about KB2538243 appear as well, but to a less degree.

To save your time going to the forums or calling Microsoft’s free security hotline, this is my answer:

KB2538242 (maybe KB2538243 as well, but I did not find an official response from Microsoft) is defective and will be replaced. In the mean time, you can hide it and unhide after the fix is released (probably in a week or so), or manually download the updates from Microsoft’s download center.


This update is offered when Microsoft Visual C++ Redistributable is installed along with one of the apps created using a Microsoft software developer tool called Visual C++. To make those app more secure, Microsoft offers security update for the customers of its customers of developer tools. You may not have those components installed, if you did not install one of these apps that ship with Visual C++ components. On a 64bit computer, the system could have both x86 and x64 editions of Visual C++ Redistributable installed, since Visual C++ is a common used component, and it is normal to have 32bit apps and 64bit apps installed on a 64bit system


From reading the reports on Microsoft Answer’s Windows Update forum, Windows Update correctly detects the x64 edition of Visual C++ Redistributable needs to be updated, but downloads the x86 edition to install. Some Windows x64 edition users reports the problem goes away by manually download the x64 edition to install, probably inspired by an old walkaround for KB2467175.

Based on the number of error reports and those “me too” comments, Visual C++ 2005 programs probably have a customer base 9 times larger than Visual C++ 2008. Looks like either those Visual C++ programmers are slow to update their tools, or the customers of those programmers are slow to update their apps.

A Microsoft tech support is quoted as saying “Visual C++ packages were written by a ‘third party’. ” Who wrote these update packages? Microsoft’s Visual C++ team should not be called like this. To Windows users, Microsoft is a single entity.

See also

How to troubleshoot Windows Update or Microsoft Update when you are repeatedly offered an update

Posted in Microsoft, Visual C++ | Tagged , , , | 3 Comments

Bug in Security Update for Visual C++ Redistributable Package: April 12, 2011 causes program error on Windows 2000

Windows Update version 3 in Windows 98

Image via Wikipedia

Update:Microsoft’s Visual C++ team has released workarounds on the problem. AVG has released an utility that can revert the KB2467175 update, downloadable at

Avira is reporting that its AntiVir software throws “The procedure entry point FindActCtxSectionStringW could not be located in the dynamic link library KERNEL32.dll.” error after installing the update released earlier this week.

This is caused by the introduction of FindActCtxSectionStringW in the MFC update which is distributed to affected computers where the Visual C++ Redistributable is installed by affected programs. I guess Microsoft did not test the update on Windows 2000 since Windows 2000’s support has expired, and indeed removed Windows 2000 from the supported platform list of the redistributables on the Microsoft download center page, but nonetheless those who develop software using Visual  C++ 2005 and Visual  C++ 2008, two currently supported products, would still not able to support Windows 2000 users after this update (KB2467174  and KB2467175).

Microsoft already withdrawn the update to fix this issue. On April 21, 2001, Microsoft rereleased the update, and made only a detection change, means the update won’t be offered to Windows 2000 again.

Suggestion to end users and software developers who already installed the update on Windows 2000: Uninstall the April 12, 2011 updates, remove leftovers mentioned in the KB articles identified by the updates and install the ATL security update versions (search in to get those updates) for now.

Suggestion to software developers: Call SetSearchPathMode to turn on the safe dll searching mode at the beginning of the app, and join the discussion Always ask the developer before applying a security fix or service pack to Visual Studio that need changed the C++ runtime DLLs ATL/MFC/CRT.

Affected software:

Other known issues in this update can be found in a follow up post at the Visual C++ blog.
Alternative error message: 
Posted in enmsdn, MFC, Microsoft, Visual C++, Visual Studio | Tagged , , , , | 10 Comments

How to solve LNK2001 errors related to Windows SDK CLSIDs

User IMFCoder wants to know how to solve a LNK2001 error related to CLSID_CMpeg4sDecMediaObject. The user has no problem linking a lib file in the project but couldn’t find which lib the CLSID is in.

The Windows SDK is strangely cryptic on which lib file the CLSID is exported from. Luckily you can find out the library file you need to link with, if you execute the following command line in the SDK command prompt

Update: use findstr /m /S /c:”CMpeg4″ *.lib
is easier 

C:\Program Files\Microsoft SDKs\Windows\v7.0\Lib>for %a in (*.lib) do dumpbin /symbols %a |find “CMpeg4”

After a bunch of fruitless searches, the search yields the results when it encounters wmcodecdspuuid.lib

C:\Program Files\Microsoft SDKs\Windows\v7.0\Lib>dumpbin /symbols wmcodecdspuuid.lib   | find “CMpeg4”
056 00000000 SECT1D notype       External     | _CLSID_CMpeg4DecMediaObject
059 00000000 SECT1E notype       External     | _CLSID_CMpeg43DecMediaObject
05C 00000000 SECT1F notype       External     | _CLSID_CMpeg4sDecMediaObject
05F 00000000 SECT20 notype       External     | _CLSID_CMpeg4sDecMFT
065 00000000 SECT22 notype       External     | _CLSID_CMpeg4EncMediaObject
068 00000000 SECT23 notype       External     | _CLSID_CMpeg4sEncMediaObject

There is a big uuid.lib file contains most of the SDK CLSIDs in the Windows SDK, and it is likely linked by default if you use Visual C++’s project templates, so you may not see the link error at all if you use common CLSIDs like CLSID_InternetExplorer.

There are also GUIDs defined in the Windows SDK using the DEFINE_GUID macro. The SDK assumes you to initialize the GUID using the methods demonstrated in How to avoid error “LNK2001 unresolved external” by using DEFINE_GUID.

Posted in enmsdn, Microsoft, Visual C++, Visual Studio | Tagged , , | Leave a comment

More ADO issues with KB983246/Windows 7 SP1: a reference count leaking when event is used

Windows Update

Image via Wikipedia

Update: Microsoft fixed the issue in Windows 8.

User Angus Robertson is reporting that in an application that references ADO 2.1 type library and getting records using the adAsyncExecute method, each execute call  leaks three handles and about 20K of memory. A fix is promised in a future version of windows but since MDAC is an in-band OS component, an widely-available update would be in a service pack just like how kb983246 was delivered. Concerned ADO users should contact Microsoft Customer Support service and request a hotfix, once that is available.

By the way, if you are still in XP or 2003, there is a deadlock issue when using the same adAsyncExecute option. This issue is fixed on Vista.

Posted in Microsoft | Tagged , | Leave a comment