Question

Hello I'm currently running Visual Studio 2010 and have a context menu shell extension completely working in 32 bit on a 32 bit machine so all the methods exist. It is an ATL project. No errors or even warnings on the 32 bit.

Here is the issue. When i go into the configuration Manager under visual studio and switch the active solution platform from Win32 to x64 and try to compile i get the error "error C2259: 'ATL::CCOMObject : cannot instantiate abstract class".

Since this exact same project does compile and run in 32bit why does it throw me that error for x64?

Any Ideas or a point in the right direction would be appreciated.
Main Methods that are required and are implemented as follows:

STDMETHODIMP Initialize(LPCITEMIDLIST, LPDATAOBJECT, HKEY);
STDMETHODIMP GetCommandString(UINT, UINT, UINT*, LPSTR, UINT);
STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO);
STDMETHODIMP QueryContextMenu(HMENU, UINT, UINT, UINT, UINT);

To save Code Space Create an Atl Project. Once initial items have been created add a new class "TestingContextMenu" Rest of Code will be referencing this.

stdafk.h

#include "resource.h"
#include <atlbase.h>
#include <atlcom.h>
#include <atlctl.h>
#include <shlobj.h>
#include <comdef.h>

#include <string>
#include <list>
typedef std::list< std::basic_string<TCHAR> > string_list;

TestingContextMenu.h Only parts that have been added/Changed will be included

#include "stdafx.h"
using namespace std;
class ATL_NO_VTABLE CTestingContextMenu:
        public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CTestingContextMenu, &CLSID_TestingContextMenu>,
    public IShellExtInit,
    public IContextMenu
    {
        // Comment out or remove IDispatch
BEGIN_COM_MAP(CMainMagnimbusContextMenu)
    //COM_INTERFACE_ENTRY(ITestingContextMenu)
    //COM_INTERFACE_ENTRY(IDispatch)
    COM_INTERFACE_ENTRY(IShellExtInit)
    COM_INTERFACE_ENTRY(IContextMenu)
END_COM_MAP()

protected:
    TCHAR m_szFile[MAX_PATH];
    list<string> Filenames;
    list<string> FilenamesCopier;
public:
    STDMETHODIMP Initialize(LPCITEMIDLIST, LPDATAOBJECT, HKEY);

    STDMETHODIMP GetCommandString(UINT, UINT, UINT*, LPSTR, UINT);
    STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO);
    STDMETHODIMP QueryContextMenu(HMENU, UINT, UINT, UINT, UINT);
};  //There is other code within this but it is autogenerated

TestingContextMenu.cpp

#include "stdafx.h"
#include "TestingContextMenu"
#include <sstream>
using namespace std;
#pragma comment(lib, "comsuppw")

STDMETHODIMP CMainMagnimbusContextMenu::Initialize ( 
  LPCITEMIDLIST pidlFolder,
  LPDATAOBJECT pDataObj,
  HKEY hProgID )
  {
  FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
    STGMEDIUM stg = { TYMED_HGLOBAL };
    HDROP     hDrop;

    if ( FAILED( pDataObj->GetData ( &fmt, &stg ) ))
        return E_INVALIDARG;
    hDrop = (HDROP) GlobalLock ( stg.hGlobal );

    UINT uNumFiles = DragQueryFile ( hDrop, 0xFFFFFFFF, NULL, 0 );
   HRESULT hr = S_OK;

   if ( 0 == uNumFiles )
    {
       GlobalUnlock ( stg.hGlobal );
       ReleaseStgMedium ( &stg );
       return E_INVALIDARG;
    }

   UINT counter = 0;
    // Get the name of the every file and store it in our member variable m_szFile.
   for(counter = 0; counter < uNumFiles; counter++)
   {
        if ( 0 == DragQueryFile ( hDrop, counter, m_szFile, MAX_PATH ) )
        {   
            hr = E_INVALIDARG;
        }
        wchar_t* t = _wcsdup(m_szFile);
        char ch[260];
        char DefChar = ' ';
        WideCharToMultiByte(CP_ACP,0,t,-1, ch,260,&DefChar, NULL);
        string ss(ch);
        Filenames.push_back(ss);
        FilenamesCopier.push_back(ss);
   }

   GlobalUnlock ( stg.hGlobal );
   ReleaseStgMedium ( &stg );

   return hr;
}

The Rest of the Functions are Availible upon request. However I have noticed something new. If you have just the above function and code implemented and the Config manager set to build x64 you get the initial error I am having. This even means not implementing the QueryContextMenu, GetCommandString, or the invoke command. Only error you'll get with this set up is my original which is what we would expect since they are not implemented. However switch that config manager back to Win32 and you get the expected errors such as 3 unresolved externals, and 3 errors following it naming GetCommandString, InvokeCommand, and QueryContextMenu. Again expected if they aren't implemented but why does the compiler on x64 recognize only my original error which is what a lot of people would assume it is, not implemented methods, but on the win32 set it shows the full errors when not implemented.

The previous paragraph was just something I noticed. I do have all 3 methods implemented correctly and compiles correctly in Win32 but not x64.

Was it helpful?

Solution

Your GetCommandString parameters do not match those defined by the interface method.

Your

STDMETHODIMP GetCommandString(UINT, UINT, UINT*, LPSTR, UINT)

needs to be

STDMETHODIMP GetCommandString(UINT_PTR, UINT, UINT*, LPSTR, UINT)

In Win32 the mismatch is not so much important (the parameter types resolve to the same type), and in x64 is becomes important. Compiler build output should have given you a hint on this, including the missing method name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top