Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Windows API Constants and Structs for P/Invoke

Tags:

c#

.net

winapi

Quick question: How can I access the BN_CLICKED constant and other constants defined for the Win32 API from .NET? Are they defined in some library? Do I have to define them myself? If so, where can I find these values? And are the values version-specific between versions of Windows?

like image 898
Squirrelsama Avatar asked Feb 25 '11 20:02

Squirrelsama


People also ask

How do I access Windows API?

Open a new Windows Application project by clicking New on the File menu, and then clicking Project. The New Project dialog box appears. Select Windows Application from the list of Visual Basic project templates. The new project is displayed.

How does PInvoke work?

P/Invoke is the technique a programmer can use to access functions in these libraries. Calls to functions within these libraries occur by declaring the signature of the unmanaged function within managed code, which serves as the actual function that can be called like any other managed method.

What overarching namespace provides PInvoke to net?

Most of the P/Invoke API is contained in two namespaces: System and System. Runtime.

What is PInvoke net?

PInvoke.net is primarily a wiki, allowing developers to find, edit and add PInvoke* signatures, user-defined types, and any other information related to calling Win32 and other unmanaged APIs from managed code (written in languages such as C# or VB.NET).


2 Answers

I find the PInvoke Interop Assistant to be really helpful: http://blogs.microsoft.co.il/blogs/sasha/archive/2008/01/12/p-invoke-signature-generator.aspx.

It has almost everything and can convert the C++ to C#/VB for you. I rarely, if ever, resort to searching google/pinvoke.net anymore. Screenshot

Here's the MSDN Magazine Article: http://msdn.microsoft.com/en-us/magazine/cc164193.aspx

The original January 2008 MSDN Magazine Article is now only available as a .CHM help file download, linked from the very bottom of https://msdn.microsoft.com/magazine/msdn-magazine-issues. (Column "CLR Inside Out: Marshaling between managed and unmanaged code.")

And here's the download: http://download.microsoft.com/download/f/2/7/f279e71e-efb0-4155-873d-5554a0608523/CLRInsideOut2008_01.exe. The source code can be found at http://clrinterop.codeplex.com/.

like image 170
Mark Sowul Avatar answered Nov 06 '22 22:11

Mark Sowul


You could download the Microsoft Platform SDK and take a look at the header files (*.h). E.g. the BN_CLICKED is defined in the winuser.h file.

Usually, if you just need one or two constants, a Google search and a look at the first few results is also sufficient, since the value is printed there.

like image 6
Uwe Keim Avatar answered Nov 07 '22 00:11

Uwe Keim