Thursday, March 7, 2013

unmanaged code and the C# extern keyword

[DllImport("avifil32.dll")]
private static extern void AVIFileInit();

 
 

System.Runtime.InteropServices is the namespace which empowers the code above I think. This will allow one to call the method in avifil32.dll from the class at hand merely by having a line reading "AVIFileInit();" within another method without having to have the project at hand have avifil32.dll as a reference and a using statement denoting the call to the reference. This is touched on in Chapter 20 of C# 4.0 in a Nutshell which is on security, but, truth be told, I am stealing this example from here. This in contrast gives a good write up of managed code (your code that compiles to common language runtime, or CLR for short, from C#) and unmanaged code which is code that ties into the operating system or other weird gunk. This is a great technical explanation I know. "Like x86 assembly language." is given as an example at the second link I gave which also suggests that unmanaged code is any code you might interact with from CLR code which does not itself compile to CLR.

No comments:

Post a Comment