2013-06-08 1 views
3

Carlos J. Quintero semble en savoir beaucoup sur l'ETTD. Dans un article mis à jour en Mars de cette année et publié sur le Web (http://www.mztools.com/articles/2007/mz2007027.aspx), il dit que la méthode Open sur un EnvDTE. ProjectItem renvoie un EnvDTE.Window, dont la propriété Document peut être transtypée en un EnvDTE.TextDocument.DTE: tentative de conversion de Window.Document de ProjectItem en un objet TextDocument

Mais quand j'essaye ceci, j'obtiens une exception (HRESULT: 0x80004002 [E_NOINTERFACE]). Il semble que le __ComObject par open ne sait pas TextDocument:

enter image description here

Un (extrait et légèrement modifié) extrait de mon code VB .Net (VS2008 fonctionnant sous Windows 7 Pro 64 dans WOW):

...handler for BuildEvents.OnBuildBegin recursively traverses all items in all projects; filters names to find those containing ".Designer.vb" (apparently works fine to here). For each found, want to replace certain text; to do so, need TextDocument object:

'the below returns __ComObject instead of EnvDTE.Window 
Dim ItemWindow as EnvDTE.Window = ProjectItem.Open(EnvDTE.Constants.vsext_vk_Code) 
'the below throws exception 
Dim ItemTextDocument as EnvDTE.TextDocument = CType(ItemWindow.Document, EnvDTE.TextDocument) 

erreur complète:

Unable to cast COM object of type 'System.__ComObject' to interface type 'EnvDTE.TextDocument'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{CB218890-1382-472B-9118-782700C88115}' failed due to the following error: Interface wordt niet ondersteund (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)). 

Qu'est-ce qui ne va pas? Toute aide appréciée.

+0

Merci pour votre aide – albondiga

Répondre

2

je suis tombé sur le même problème

Vous pouvez résoudre ce problème en spécifiant quel type de document que vous voulez obtenir de l'objet fenêtre

public static void SetCode(ProjectItem projectItem, string newCode) 
{ 

    Window EditWindow = projectItem.Open(Constants.vsext_vk_Code); 
    EditWindow.Visible = true; //hide editor window 

    TextDocument TextDocument = (TextDocument)EditWindow.Document.Object("TextDocument"); 

    EditPoint EditPoint = TextDocument.StartPoint.CreateEditPoint(); 
    EditPoint.Delete(TextDocument.EndPoint); //delete content 
    EditPoint.Insert(newCode); 

    EditWindow.Close(vsSaveChanges.vsSaveChangesYes); 
} 

vous devrez convertir ce retour à VB. NET vous-même

Questions connexes