views:

311

answers:

2

Hello!

It is safe to ignore this warning?

Argument type 'uint' is not CLS-compliant

I'm developing a Compact Framework applicatin and I have a lot of P/Invoke and I have to use uint, ushort, etc. as parameter's types.

I've used [CLSCompliantAttribute(false)] to avoid the warning messages but I don't know it is safe.

Some help would be apreciated.

Thanks.

+8  A: 

If you are not writing a component intended to be used by others in a different language, then you do not need to be CLS-compliant. Just declare that you are not (as you've already done).

However, it is possible to use uint internally and still provide a CLS compliant interface. Writing CLS-Compliant Code.

regentgal
Yeah, you're great!
VansFannel
+2  A: 

You can safely substitute a CLS compliant signed type for its same sized non-CLS compliant unsigned type.

The following are effectively the same (the first User32 function I found on pinvoke.net):

[DllImport("user32.dll")] static extern int ActivateKeyboardLayout(IntPtr nkl, uint Flags);

[DllImport("user32.dll")] static extern int ActivateKeyboardLayout(IntPtr nkl, int Flags);

Signed and unsigned bit fields behave identically. The only place you might have an issue is if you need to pass or receive truely huge numbers, which will map to negative numbers (look up 2's complement).

Pete