For example, if I'm declaring:
internal static class WinAPI
{
[DllImport("DwmApi.dll", PreserveSig = false)]
internal static extern bool DwmIsCompositionEnabled();
}
but I'm not calling the DwmIsCompositionEnabled function in my project, I hope this will not开发者_高级运维 raise an exception when running the program on systems where DwmApi.dll does not exist (or the function does not exist in that DLL). (Real case: DwmApi.dll requires Windows Vista, so it doesn't exist on Windows XP).
This will only be a problem if and when the API is called.
You could consider a thin C# wrapper on the P/Invoke to facilitate handling the error, if you call this from multiple places.
As long as you don't call it or don't use NGEN for deployment (ie: if you always rely on .NET Jit), you're fine.
精彩评论