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?

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?

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)



Leave a Reply 1

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


seenagape

seenagape

I have the same idea. A