簡體   English   中英

如何將ComObject轉換為ENVDTE.Project?

[英]How to cast ComObject to ENVDTE.Project?

我正在使用以下代碼:

Object projObj = htProjects[selectedNode]; // htProjects is a Hashtable:key-project Name,value-ENVDTE.Project
Project selectedProject = (Project)projObj; 

我收到以下錯誤:

Unable to cast COM object of type 'System.__ComObject' to interface type 'EnvDTE.Project'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{866311E6-C887-4143-9833-645F5B93F6F1}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

我嘗試按此處所述注冊DLLS,但似乎還有其他問題。

找到了解決方案。 一些哈希表條目具有ENVDTE.ProjectItems作為值。 因此需要檢查。

碼:

        if (projObj is Project)
        {
            Project selectedProject = (Project)projObj;
            MessageBox.Show(selectedProject.FullName);
        }
        else if(projObj is ProjectItem)
        {
            ProjectItem selectedProject = (ProjectItem)projObj;
            MessageBox.Show(selectedProject.get_FileNames(1));
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM