PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You write the following code to call a function from the Win32 Application Programming Interface (API) by using platform invoke.
int rc = MessageBox(hWnd, text, caption, type);
You need to define a method prototype. Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
[DllImport(“user32”)]
public static extern int MessageBox(int hWnd, String text, String caption, unit type);

B.
[DllImport(“user32”)]
public static extern int MessageBoxA(int hWnd, String text,String caption, unit type);

C.
[DllImport(“user32”)]
public static extern int Win32API_User32_MessageBox(int h wnd, String text, String caption, unit type);

D.
[DllImport(@”C:WINDOWSsystem32user32.dll”)]
public static extern int MessageBox(int hWnd, String text, String caption, unit type);

Explanation:
Mark the prototype with the Dllimport attribute specifying the librarydll that the function resides in.
B creates a prototype for the MessageBoxA function not MessageBox .
C it is not necessary to specify the physical path because user32.dll will be in the path environment variable.
Also it will not work with versions of windows (some may use c:winntsystem32)

One Comment on “Which code segment should you use?


Leave a Reply