I\'m getting an error when I attempt to use the following static function.
Error:
Expected class, delegate, enum, interface, or struct
I ran into this problem when getting re-acquainted with P-Invoke. Femaref had it right. Here's some sample code for quick visualization purposes:
Working Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace ConsoleApplication2
{
class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetModuleHandle(string lpModuleName);
static void Main(string[] args)
{
}
}
}
Broken Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public static extern IntPtr GetModuleHandle(string lpModuleName);
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
}
}
}