Information Technology Reference
In-Depth Information
For example, the following code uses an external method, GetCurrentDirectory , whose
implementation is the Win32 system call for getting a string that contains the current directory.
using System;
using System.Text;
using System.Runtime.InteropServices;
namespace ExternalMethod
{
class MyClass
{
[DllImport("kernel32", SetLastError=true)]
public static extern int GetCurrentDirectory(int a, StringBuilder b);
}
class Program
{
static void Main( )
{
const int MaxDirLength = 250;
StringBuilder sb = new StringBuilder();
sb.Length = MaxDirLength;
MyClass.GetCurrentDirectory(MaxDirLength, sb);
Console.WriteLine(sb);
}
}
}
This code produces the following output:
C:\BookPrograms\ExternalMethod\ExternalMethod\bin\Debug
Search WWH ::




Custom Search