Answer:
Unmanaged code can be called through .NET applications in a number of ways:
Example:
1)Pointer code is an unmanaged code:
Mark the pointer code secton with unsafe keyword.
compile the code with /unsafe switch
example:
class abc
{
static void Main()
{
unsafe
{
//Write the pointer code
}
}
}
example:
2)Win32 API Functions:
1)
//add this namespace
using System.Runtime.InteropServices;
(C#)
2)Mark the relevant dll with DllImport attribute
3)Put static and extern modifiers before the function
example:FlashWindow to blink the form's caption bar.
[DllImport("user32.dll")]
static extern void FlashWindow(IntPtr a, bool b);
Asked In: Many Interviews |
Alert Moderator