Which code segment should you use?

You write the following code segment to call a function from the Win32 Application Programming Interface (API) by using platform invoke.
string personName = “N?el”;
string msg = “welcome ” + personName + “to club”!;
bool rc = User32API.MessageBox(0, msg, personName, 0); You need to define a method prototype that can best marshal the string data.
Which code segment should you use?

You write the following code segment to call a function from the Win32 Application Programming Interface (API) by using platform invoke.
string personName = “N?el”;
string msg = “welcome ” + personName + “to club”!;
bool rc = User32API.MessageBox(0, msg, personName, 0); You need to define a method prototype that can best marshal the string data.
Which code segment should you use?

A.
[DllImport(“user32”, CharSet = CharSet.Ansi)]
public static extern bool MessageBox(int h Wnd, String text,
String caption, unit type);

B.
[DllImport(“user32”, EntryPoint = “MessageBoxA”, CharSet = CharSet.Ansi)]
public static extern bool MessageBox(int hWnd, [MarshalAs(UnmanagedType.LPWStr)]String text,[MarshalAs(UnmanagedType.LPWStr)]
String caption, unit type);

C.
[DllImport(“user32”, CharSet = CharSet.Unicode)]
public static extern bool MessageBox(int h Wnd, String text, String caption, unit type);

D.
[DllImport(“user32”, EntryPoint = “MessageBoxA”, CharSet = CharSet.Unicode)]
public static extern bool MessageBox(int hWnd, [MarshalAs(UnmanagedType.LPWStr)]String text, [MarshalAs(UnmanagedType.LPWStr)]
String caption,unit type);



Leave a Reply 1

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


mr_tienvu

mr_tienvu

I have the same idea. C