what is unmanage code?

Posted by Bageshkumarbagi under .NET Certifications on 10/19/2012 | Points: 10 | Views : 1166 | Status : [Member] | Replies : 3
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

Posted by: Gaur1982 on: 7/24/2013 [Member] Starter | Points: 25

Up
0
Down
Unmanaged code is what you use to make before Visual Studio .NET 2002 was released. Visual Basic 6, Visual C++ 6, heck, even that 15-year old C compiler you may still have kicking around on your hard drive all produced unmanaged code. It compiled directly to machine code that ran on the machine where you compiled it—and on other machines as long as they had the same chip, or nearly the same. It didn't get services such as security or memory management from an invisible runtime; it got them from the operating system. And importantly, it got them from the operating system explicitly, by asking for them, usually by calling an API provided in the Windows SDK. More recent unmanaged applications got operating system services through COM calls.
FOR MUCH MORE Click on this link....
http://www.planetofcoders.com/unmanaged-code/

Gaurav Agrawal
http://www.planetofcoders.com/

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

Login to post response