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)]extern bool MessageBox(int hWnd,
String^ text,
String^ caption,
unsigned int type);}
B. [DllImport("user32", EntryPoint = "MessageBoxA", CharSet = CharSet::Ansi)]extern
bool MessageBox(int hWnd,
[MarshalAs(UnmanagedType::LPWStr)]String^ text,
[MarshalAs(UnmanagedType::LPWStr)]String^ caption,
unsigned int type);}
C. [DllImport("user32", CharSet = CharSet::Unicode)]extern bool MessageBox(int
hWnd,
String^ text,
String^ caption,
unsigned int type);}
D. [DllImport("user32", EntryPoint = "MessageBoxA", CharSet =
CharSet::Unicode)]extern bool MessageBox(int hWnd,
[MarshalAs(UnmanagedType.LPWStr)]String^ text,
[MarshalAs(UnmanagedType.LPWStr)]String^ caption,
unsigned int type);}
Answer: C
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)]extern bool MessageBox(int hWnd,
String^ text,
String^ caption,
unsigned int type);}
B. [DllImport("user32", EntryPoint = "MessageBoxA", CharSet = CharSet::Ansi)]extern
bool MessageBox(int hWnd,
[MarshalAs(UnmanagedType::LPWStr)]String^ text,
[MarshalAs(UnmanagedType::LPWStr)]String^ caption,
unsigned int type);}
C. [DllImport("user32", CharSet = CharSet::Unicode)]extern bool MessageBox(int
hWnd,
String^ text,
String^ caption,
unsigned int type);}
D. [DllImport("user32", EntryPoint = "MessageBoxA", CharSet =
CharSet::Unicode)]extern bool MessageBox(int hWnd,
[MarshalAs(UnmanagedType.LPWStr)]String^ text,
[MarshalAs(UnmanagedType.LPWStr)]String^ caption,
unsigned int type);}
Answer: C
No comments:
Post a Comment