Which two keywords should you use to define the function?

You want to access a native Win32 function from a .NET application. You import the function. Which
two keywords should you use to define the function? (Each correct answer presents part of the
solution. Choose two.)

You want to access a native Win32 function from a .NET application. You import the function. Which
two keywords should you use to define the function? (Each correct answer presents part of the
solution. Choose two.)

A.
Extern

B.
Static

C.
Private

D.
Public

Explanation:
Example:
using System.Runtime.InteropServices;
using System.Windows.Interop;
using System.Diagnostics;
using System.Threading;
public partial class MainWindow : Window
{
[DllImport(“user32.dll”, SetLastError = true)]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport(“user32.dll”, SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
public MainWindow()
{
InitializeComponent();
}
private void btnHost_Click(object sender, RoutedEventArgs e)
{
WindowInteropHelper wndHelp = new WindowInteropHelper(this);
Process.Start(“Notepad.exe”);
// Sleep the thread in order to let the Notepad start completely
Thread.Sleep(50);
SetParent(FindWindow(“NotePad”, “Untitled – Notepad”), wndHelp.Handle);
}

}



Leave a Reply 0

Your email address will not be published. Required fields are marked *