Tutorials
ASP.NET
ASP .NET Migration and Interoperability
ASP .NET Migration and Interoperability - Page 2
Platform Invocation Services (PInvoke) allows managed code to call unmanaged functions that are implemented in a DLL.
This is a simple example that shows how you can use the DllImport to import any dll file using C# code.
Platform Invocation Services (PInvoke) allows managed code to call unmanaged functions that are implemented in a DLL.
This tutorial shows you what you need to do to be able to call unmanaged DLL functions from C#. The attributes discussed in the tutorial allow you to call these functions and have data types be marshaled correctly.
This is a simple example that shows how you can use the DllImport to import any dll file using C# code.
// PInvokeTest.cs
using System;
using System.Runtime.InteropServices;
class PlatformInvokeTest
{
[DllImport("msvcrt.dll")]
public static extern int puts(string c);
[DllImport("msvcrt.dll")]
internal static extern int _flushall();
public static void Main()
{
puts("Test");
_flushall();
}
}
This example shows that how you can use DllImport to produce string.
// Marshal.cs
using System;
using System.Runtime.InteropServices;
class PlatformInvokeTest
{
[DllImport("msvcrt.dll")]
public static extern int puts(
[MarshalAs(UnmanagedType.LPStr)]
string m);
[DllImport("msvcrt.dll")]
internal static extern int _flushall();
public static void Main()
{
puts("Hello World!");
_flushall();
}
}
I hope you liked the tutorial and in the next tutorial we will learn about Session variables which are used to pass values arround.
First Page: ASP .NET Migration and Interoperability