Why are the interop definitions in System.Windows.Forms internal?

In a comment on BradA's blog, Chris wonders why Windows Forms didn't expose the structures and p/invoke declarations it uses for interop. This would have saved users from having to redefine them for their own use.

I guess there were mainly two reasons:

1) These declarations were put together on an “as necessary“ basis. Whenever we needed to call some Win32 API to implement a Windows Forms class, we added some p/invoke declarations. Obviously, the list isn't quite complete - there are many declarations you might need that aren't there. We didn't really want to expose an incomplete set of declarations.

2) Since the declarations were added for internal use by Windows Forms, chances are we expose a managed way to accomplish whatever you need the declarations for in the first place. So, in most cases, you will probably not find the p/invoke declarations you need in our set.

That said, we do realize that defining p/invoke structures and functions can be difficult to get right. The CLR team has put together a list of common Win32 definitions you may need. You will find the link (and many other useful resources) here.

Comments