Can you really read the error message? This is what it is. You are trying to apply the
DllImport
attribute to a field, which makes no sense whatsoever.
Technically, it is implemented through application of another attribute,
System.AttributeUsageAttribute
to this attribute, to limit the targets of some attributes:
http://msdn.microsoft.com/en-us/library/system.attributeusageattribute.aspx[
^],
http://msdn.microsoft.com/en-us/library/system.attributetargets.aspx[
^].
You can apply the attribute
System.Runtime.InteropServices.DllImportAttribute
only to methods, as you should have understood from your error message:
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx[
^].
I doubt you have a clue why using
DllImport
. To learn about it, please see:
http://en.wikipedia.org/wiki/P/Invoke[
^],
http://msdn.microsoft.com/library/en-us/vcmxspec/html/vcmg_PlatformInvocationServices.asp[
^].
This CodeProject article can also be used:
http://www.codeproject.com/csharp/EssentialPInvoke.asp[
^].
—SA