what is unmanage code?

Posted by Bageshkumarbagi under .NET Certifications on 10/19/2012 | Points: 10 | Views : 1307 | Status : [Member] | Replies : 2
hi
Unmanaged code is the code that is executed directly by the operating system outside the CLR environment.
I want to know which type of code executed directly by os.plz give some example.

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied



Responses

Posted by: Ranjeet_8 on: 10/19/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Unmanaged code can be called through .NET applications in a number of ways:

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:
1)Win32 API Functions:
//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);

Example:

using System.Runtime.InteropServices;

class UCode_InvokeApp
{
[DllImport("user32.dll")]
static extern int Message_Box(int hWind, string stMsg, string stCaption, int intType);
public static void Main()
{
Message_Box(0, "Hello, World!", "This is called from dotnetfunda C# app.!!!", 0);
}
}



Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 10/19/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Hi @Bageshkumarbagi
Please Mark As Answer if my post helps you.

Bageshkumarbagi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response