Sunday, January 3, 2016

ATL Surprise: GetCommandString Declaration Changes Based on Bitness

I am trying to learn how to write Windows shell extensions. I initially wrote something that compiled to a 32-bit DLL, but then I realized that since 64-bit programs (like Explorer) can't load 32-bit DLLs, my plan had no chance of working. So I switched Visual Studio to produce a 64-bit DLL, but then I got a build error:

'ATL::CComObject': cannot instantiate abstract class in atlcom.h, line 2000

I was very confused, since that error wasn't even in my code.

It turns out that the declaration of GetCommandString (one of the context menu handler functions) changed in the move from 32- to 64-bit. Its first parameter becomes a UINT_PTR instead of just a UINT. Somehow, that discrepancy confused ATL.

If, for some reason, you want to be able to easily compile for both 32- and 64-bit platforms, you'll need to use some #ifdef preprocessor statements to adjust the signature appropriately.

No comments:

Post a Comment