开发者

Simply declaring a function signature from an external DLL does not give a runtime exception if the DLL or function doesn't exist, right?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜