gpt4 book ai didi

c# - 如何将 ComObject 转换为 ENVDTE.Project?

转载 作者:行者123 更新时间:2023-12-02 01:13:45 25 4
gpt4 key购买 nike

我正在使用以下代码:

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 here但似乎还有其他问题。

最佳答案

找到解决方案。一些哈希表条目将 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));
}

关于c# - 如何将 ComObject 转换为 ENVDTE.Project?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14291769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com