Rather than writing your own DLL, you can import from one of the standard ones and do something you know will cause an exception. For instance, calling GetProcAddress with hModule = 0
should result in an exception. It might check for 0 since 0 can be NULL
, but I really doubt it will check for other small numbers like 1 or 2 :)
How to import GetProcAddress according to pinvoke.net:
[DllImport("kernel32.dll", CharSet=CharSet.Ansi, ExactSpelling=true, SetLastError=true)]
public static extern UIntPtr GetProcAddress(IntPtr hModule, string procName);
This program:
using System.Runtime.InteropServices;
using System;
public class x
{
[DllImport("kernel32.dll", CharSet=CharSet.Ansi, ExactSpelling=true, SetLastError=true)]
public static extern UIntPtr GetProcAddress(IntPtr hModule, string procName);
static void Main()
{
Console.WriteLine(GetProcAddress((IntPtr)5, "asdf"));
}
}
results in the following error in Mono, becuase I don't have kernel32:
Unhandled Exception: System.EntryPointNotFoundException: GetProcAddress
at (wrapper managed-to-native) x:GetProcAddress (intptr,string)
at x.Main () [0x00000]
so I'm not sure what it will do in .NET on Windows -- hopefully that will cause a crash!