views:

870

answers:

2

I was looking over some code that another developer wrote and found this:

Private Declare Function ShowWindow Lib "user32" (ByVal handle As IntPtr, ByVal nCmdShow As Integer) As Integer
Private Declare Function SetForegroundWindow Lib "user32" (ByVal handle As IntPtr) As Integer

What does it do and what is it for?

+2  A: 

These are PInvoke declarations. They represent functions that exist in C libraries and are defined in such a way as to allow them to be called from VB.Net. For instance, ShowWindow is a declaration of the Win32 ShowWindow function present in user32.dll. Calling this stub will end up calling the C function.

ShowWindow: http://msdn.microsoft.com/en-us/library/ms633548.aspx

This particular style of declaration is known as Dll Declare. The more common syntax is to use DllImport and shared methods (mainly because its' compatible with C#'s implementation). The DllDeclare syntax is in many ways a holdover from VB6 style interop.

JaredPar
You may also want to look at: http://pinvoke.net/default.aspx/user32/ShowWindow.html
Chris Pietschmann
I see no reason to avoid the Declare syntax unless you actually need to specify the optional parameters in the DllImport attribute.
Jonathan Allen
A: 

These are almost certainly P/Invoke calls; i.e. a declaration that allows you to call a Windows API function, that is declared in user32.dll.

Paul Betts