Long time listener, first time caller. Does anyone know of a good interop library for the Win32API?
I found pinvok.net which is OK. (FWIW I got the addin to work with MSVS 2010 by following the instructions here: http://www.red-gate.com/supportcenter/GeneralContent.aspx?c=knowledgebase\PInvoke\KB200711000198.htm and using 10.0 instead of 9.0)
...and the Windows API Code Pack 1.1 from MSDN seems not to have the basic Win32 stuff from user32.dll or am I missing something?
More specifics... I am trying to take an external window and make it a child of a control in my managed System.Windows.Form (embedded GUI in a panel or tab of my main form). Researching here and on goo开发者_StackOverflow社区gle it seems like Win32/user32.dll is the way to go. My application is a framework that launches 3rd party GUIs (dlls and exes). The 3rd party code/forms are all unmanaged (mostly MSVC) code. These unmanaged forms are launched from within my process hierarchy. My preference would be to stay in .NET if is possible.
The best interop library available is the .NET Framework. User32.dll is wrapped very well by Windows Forms.
The Windows API code pack concentrates on wrapping API additions made in Vista and Win7. Those were not additions to user32, mostly shell stuff.
You'll probably get a better answer if you can be specific about exactly what user32 APIs you want to use.
After seeing edit: what you are trying to do is explicitly forbidden by the Win32 SDK documentation. The parent of a window must belong to the same process. There are however some appcompat hacks in Windows, designed to support Windows 3.x programs where this restriction did not exist. Because it didn't support threading.
You can try, but beware you'll void the warranty. P/Invoke SetParent(). Visit pinvoke.net for the declaration you'll need.
Much of the Windows 32 API is exposed in .NET in the framework itself - so it's rare that you need to P/Invoke into user32.dll. You're better off using the managed versions of the framework.
When you do need to setup a P/Invoke call, pinvoke.net is a great resource for the specific API required for a call into most of the Win32 API.
精彩评论