locked
ExecuteCommand of DTE objet always fails RRS feed

  • Question

  • Hi,

          I am trying execute saveAll command from C++ code using DTE object . I have written a sample C++ (Win32 Console  app) ..

     

        HRESULT hret=CoInitialize(NULL);

        CLSID clsid;
        hret = CLSIDFromProgID(L"VisualStudio.DTE.8.0",&clsid);
        assert(SUCCEEDED(hret));

        // Get IUnknown Interface
        IUnknown *pUnknown=0;
        hret = GetActiveObject(clsid,NULL,&pUnknown)    ;
        assert(SUCCEEDED(hret));
       
        EnvDTE80::DTE2Ptr pDTE2 = pUnknown;


        hret = pDTE2->ExecuteCommand(_T("File.NewFile"),_T(""));
        if(SUCCEEDED(hret))
        {
            MessageBox(NULL,L"Execute Command Success",L"TEST3",MB_OK);   
        }

       CoUninitialize();

    But every time Execute Command  returns E_FAIL..Any help will be appreciated

     

    Thursday, May 13, 2010 2:29 PM

Answers

  • My initial guess would be that you are passing strings instead of BSTR's to the ExecuteCommand method.

    Try something like:

       hret=pDTE2->ExecuteCommand(_bstr_t("File.NewFile"), _bstr_t(""));


    Ed Dore
    Friday, May 14, 2010 1:22 AM