views:

144

answers:

3

I'm writing some code that uses some unmanaged calls into user32 functions such as SetWindowsHookEx, etc.

This requires me to use lots of constants that I'm not sure what their value is. For example, if I want to set the hook as a low-level mouse hook I need to know that WM_MOUSE_LL = 14.

Where can I look these up?

I need to know what WM_MOUSEMOVE, WM_MOUSEDOWN, and more are. When I'm dealing with interop code, what is the easiest way for me to find these? Is it possible for me to import them into C# so they will be defined?

A: 

Sometimes the MSDN pages will list them, but I find the best way is to have a C++ program open and to right click on the constant and say go to definition.

Another way to instantly find out for almost anything is to use Google code search. Many times you'll find the answer in WINE header files.

Brian R. Bondy
+1  A: 

Do you know about PInvoke.net?

Niall C.
+1  A: 

It's on your machine. If you've got VS2008 then open c:\program files\microsoft skds\windows\v6.0a\winuser.h and search for the message identifier. No, you can't use this file in a C# program, it is written in C.

There's a tool available that translated these SDK header files to C#, download the P/Invoke Interop Assistant. Click the "SigImp Search" tab and type the identifier you are looking for. Click Generate to create the C# declaration. Its okay for message identifiers but gets ugly for API functions. The declarations are auto-translated and are pretty noisy and not always optimal. Double-check the generated definition with what's available at pinvoke.net

Hans Passant