locked
Code crash with VS11 beta RRS feed

  • Question

  • Hello everybody,

    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(VCProject * 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)
    }

    Tuesday, March 27, 2012 7:27 AM

Answers

  • 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.

    Ryan

    Thursday, March 29, 2012 9:49 PM

All replies

  • What is the crash/exception? The code above leaks btw, but that shouldn't cause a crash.

    edit: Also, and this should also be fine but it looks very odd, you are passed a VCProject * and then you QI it for VCProject....why?  Not that it is wrong, it should work fine, but does calling get_VCReferences on aProject crash here as well?

    Ryan


    Tuesday, March 27, 2012 2:07 PM
  • Hi,

    Thanks for the reply. There is a little error in my code snippet indeed. I have edited it in place and did not pay enough attention. Sorry for this .  SomeMethod should be as follows

    void SomeMethod(EnvDTE::Project * aProject)
    {
      CComPtr<IDispatch> pID;
      aProject->get_Object(&pID);
      CComPtr<VCProject> vcProject = GetVCProjectObject(pID);
    
      if (!vcProject)
        return;
    
      CComPtr<IDispatch> dipsProjRefs; 
      //CRASH HERE !!!! 
      vcProject->get_VCReferences(&dipsProjRefs)
    }

    Edit: It seems there are some differences in VCReferences object in VS11. I imported the latest version  of the vcpd2.tlb type library and it works in VS11 but it fails in prior versions.

    Wednesday, March 28, 2012 12:09 PM
  • What is the crash/exception you are seeing?

    Ryan

    Wednesday, March 28, 2012 3:24 PM
  • 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.

    Ryan

    Thursday, March 29, 2012 9:49 PM
  • Already done this.

    Thanks

    Friday, March 30, 2012 1:45 PM