I have several DllImports with respect to user32.dll in my code and I thought them to be declared in an interface. But that gives me errors saying public, static, extern are not valid with each item.
Example interface code is as follows:
public interface IWindowsFunctions
{
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int MessageBox(int hWnd, string msg, string title, uint flags);
}
Is there any specific way of using this in an interface, or is there an alternative or is it impossible with an interface?
Thanks
Well its already been mentioned many times now that a DLLImport is an implementation, and therefore cannot be defined on an interface, but I thought it would still be worth mentioning that normally I group by DLLImports into a “NativeMethods” class for organisation, like so:
Example use: