4

J'ai un projet C++/CLI qui utilise CWinFormsControl et CWinFormsView pour créer des contrôles .NET dans mes vues MFC. Pour ce faire, j'ai besoin de #include "afxwinforms.h".Comment exclure le code MFC de l'analyse de code VS2008

Lorsque j'exécute l'analyse de code sur le projet, j'obtiens toujours des avertissements sur certaines des classes MFC que j'ai incluses. Exemples:

3>Running Code Analysis... 
3>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwinforms.h(87) : warning: CA1704 : Microsoft.Naming : In method 'CWin32Window::CWin32Window(HWND__*)', correct the spelling of 'Wnd' in parameter name 'hWnd' or remove it entirely if it represents any sort of Hungarian notation. 
3>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwinforms.h(87) : warning: CA1704 : Microsoft.Naming : In method 'CWin32Window::CWin32Window(HWND__*)', correct the spelling of 'h' in parameter name 'hWnd' or remove it entirely if it represents any sort of Hungarian notation. 
3>warning: CA1051 : Microsoft.Design : Because field 'CWinFormsEventsHelper::m_pControl' is visible outside of its declaring type, change its accessibility to private and add a property, with the same accessibility as the field has currently, to provide access to it. 
3>warning: CA1051 : Microsoft.Design : Because field 'CWinFormsEventsHelper::m_pSink' is visible outside of its declaring type, change its accessibility to private and add a property, with the same accessibility as the field has currently, to provide access to it. 
3>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwinforms.inl(60) : warning: CA1704 : Microsoft.Naming : In method 'CWinFormsEventsHelper::OnHandleCreated(Object^, EventArgs^)', consider providing a more meaningful name than parameter name 'o'. 
3>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwinforms.inl(60) : warning: CA2109 : Microsoft.Security : Consider making 'CWinFormsEventsHelper::OnHandleCreated(Object^, EventArgs^)' not externally visible. 
3>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwinforms.inl(67) : warning: CA1704 : Microsoft.Naming : In method 'CWinFormsEventsHelper::OnHandleDestroyed(Object^, EventArgs^)', consider providing a more meaningful name than parameter name 'o'. 
3>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwinforms.inl(67) : warning: CA2109 : Microsoft.Security : Consider making 'CWinFormsEventsHelper::OnHandleDestroyed(Object^, EventArgs^)' not externally visible. 
3>c:\program files\microsoft visual studio 9.0\vc\atlmfc\include\afxwinforms.inl(54) : warning: CA1704 : Microsoft.Naming : Correct the spelling of 'Unadvise' in member name 'CWinFormsEventsHelper::Unadvise(IHandleEvents*)' or remove it entirely if it represents any sort of Hungarian notation. 
3>warning: CA1823 : Microsoft.Performance : It appears that field 'context_node_base::_Needs_Context' is never used or is only ever assigned to. Use this field or remove it. 
3>warning: CA1812 : Microsoft.Performance : 'context_node<char const *,System::String ^>' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static methods, consider adding a private constructor to prevent the compiler from generating a default constructor. 
3>c:\program files\microsoft visual studio 9.0\vc\include\msclr\marshal.h(366) : warning: CA2201 : Microsoft.Usage : 'context_node<char const *,System::String ^>::context_node<char const *,System::String ^>(const char*&, String^)' creates an exception of type 'OutOfMemoryException', an exception type that is reserved by the runtime and should never be raised by managed code. If this exception instance might be thrown, use a different exception type. 

De toute évidence, je voudrais supprimer ces avertissements MFC afin que je puisse voir mes propres plus clairement. Mais comment? Je ne veux pas désactiver les avertissements de mon propre code juste pour contourner ce problème.

Répondre

5

En ajoutant ce qui suit à StdAfx.h, tous les avertissements MFC ont été supprimés (trouvés en supprimant les avertissements de la fenêtre de la liste des erreurs dans le fichier de suppression du projet , puis de les déplacer dans stdafx)

CA_GLOBAL_SUPPRESS_MESSAGE("Microsoft.Usage", "CA2201:DoNotRaiseReservedExceptionTypes", Scope="member", Target="msclr.interop.context_node<char const *,System::String ^>.#.ctor({modopt(System.Runtime.CompilerServices.IsConst),modopt(System.Runtime.CompilerServices.IsSignUnspecifiedByte)}System.SByte*{modopt(System.Runtime.CompilerServices.IsImplicitlyDereferenced)}*,System.String)"); 
CA_GLOBAL_SUPPRESS_MESSAGE("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields", Scope="member", Target="Microsoft.VisualC.MFC.CWinFormsEventsHelper.#m_pControl"); 
CA_GLOBAL_SUPPRESS_MESSAGE("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields", Scope="member", Target="Microsoft.VisualC.MFC.CWinFormsEventsHelper.#m_pSink"); 
CA_GLOBAL_SUPPRESS_MESSAGE("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields", Scope="member", Target="msclr.interop.context_node_base.#_Needs_Context"); 
CA_GLOBAL_SUPPRESS_MESSAGE("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Scope="type", Target="msclr.interop.context_node<char const *,System::String ^>"); 
CA_GLOBAL_SUPPRESS_MESSAGE("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId="Wnd", Scope="member", Target="Microsoft.VisualC.MFC.CWin32Window.#.ctor(HWND__*)"); 
CA_GLOBAL_SUPPRESS_MESSAGE("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId="h", Scope="member", Target="Microsoft.VisualC.MFC.CWin32Window.#.ctor(HWND__*)"); 
CA_GLOBAL_SUPPRESS_MESSAGE("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId="o", Scope="member", Target="Microsoft.VisualC.MFC.CWinFormsEventsHelper.#OnHandleCreated(System.Object,System.EventArgs)"); 
CA_GLOBAL_SUPPRESS_MESSAGE("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers", Scope="member", Target="Microsoft.VisualC.MFC.CWinFormsEventsHelper.#OnHandleCreated(System.Object,System.EventArgs)"); 
CA_GLOBAL_SUPPRESS_MESSAGE("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId="o", Scope="member", Target="Microsoft.VisualC.MFC.CWinFormsEventsHelper.#OnHandleDestroyed(System.Object,System.EventArgs)"); 
CA_GLOBAL_SUPPRESS_MESSAGE("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers", Scope="member", Target="Microsoft.VisualC.MFC.CWinFormsEventsHelper.#OnHandleDestroyed(System.Object,System.EventArgs)"); 
CA_GLOBAL_SUPPRESS_MESSAGE("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId="Unadvise", Scope="member", Target="Microsoft.VisualC.MFC.CWinFormsEventsHelper.#Unadvise(Microsoft.VisualC.MFC.IHandleEvents*)"); 
#include <afxwinforms.h>  // MFC Windows Forms support 

La prochaine fois: Doit réfléchir davantage avant de poster SO question: D

1

Inclure afxwinforms.h cette façon:

#pragma warning(push) 
//disable whatever you need with #pragma warning(disable: warning number) 
#include <afxwinforms.h> 
#pragma warning(pop) 
+0

Vous ne pouvez pas supprimer les avertissements d'analyse de code en utilisant #pragma, mais votre réponse m'a fait réfléchir plus attentivement, c'est pourquoi je vous donne +1 – demoncodemonkey

Questions connexes