Question

I have some code that used to work in prior versions of Visual Studio but crashes in the new beta and I can't seem to figure out why.

I am trying to obtain the VCReferences object for for a VCProject. The code it supposed to work on all version of VS.

Thanks.

VCProject * GetVCProjectObject(IDispatch * aDispatch)
{  
  IID VCProject_IID;
  switch(mStudioVersion)
  {
    case VS2003:
      ::IIDFromString(_bstr_t(L"{70b6c8e7-5b3e-49c7-9937-c5f0b3168af3}"), &VCProject_IID);
      break;
    case VS2005:
      ::IIDFromString(_bstr_t(L"{238b5174-2429-11d7-8bf6-00b0d03daa06}"), &VCProject_IID);
      break;
    case VS2008:
      ::IIDFromString(_bstr_t(L"{3990034a-3af2-44c9-bd22-7b10654b5721}"), &VCProject_IID);
      break;
    case VS2010:
      ::IIDFromString(_bstr_t(L"{885c172e-5b7a-43b9-8ad0-697f48233772}"), &VCProject_IID);
      break;
    case VS11:
      ::IIDFromString(_bstr_t(L"{F900F95E-1D99-4631-BBD1-E3E1E078D58E}"), &VCProject_IID);
      break;
}

  CComPtr<VCProject> vcProject;
  aDispatch->QueryInterface(VCProject_IID, (void**)&vcProject);

  return vcProject.Detach();
}


void SomeMethod(EnvDTE::Project * aProject)
{
  CComPtr<IDispatch> pID;
  aProject->get_Object(&pID);
  CComPtr<VCProject> vcProject = GetVCProjectObject(pID);

  if (!vcProject)
    return false;

  CComPtr<IDispatch> dipsProjRefs; 
  //CRASH HERE !!!! 
  vcProject->get_VCReferences(&dipsProjRefs)
}
Was it helpful?

Solution

This is from MSDN forums

Okay, word from the C++ team is they don't support back-compat of their object interfaces between VS versions, which is why they re-GUID them (which you already account for above).

That means they have likely changed the v-table layout of VCProject in Dev11 and it no longer matches the layout in previous versions.

Perhaps your code worked before because the GUIDs changed but the v-table layouts of the specific objects you are using did not.

I don't know if you NEED to import the TLB for some reason, but in theory you could special case Dev11 and define a local interface definition with the same v-table layout as the Dev11 VCProject class and the same GUID, and then when you find your code is running in Dev11 you would use that interface, otherwise you would use the 'old' one. QI works on GUID ids and only relies on the v-table layout matching, so if you make sure both of those are true it doesn't matter if the interface you use in your local code is actually one you defined yourself.

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