I am trying to use several functions from the kernal32.dll file. However, when my application tries to call the first function, it throws an EntryPointNotFoundException elementUnable to find an entry point named 'SetDllDirectory' in DLL 'kernel32.dll'.
public class MyClass
{
internal static class UnsafeNativeMethods
{
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
internal static extern IntPtr LoadLibrary(string lpFileName);
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
internal static extern bool SetDllDirectory(string lpPathName);
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
}
private void MyFunc()
{
if (UnsafeNativeMethods.SetDllDirectory(_location) == false)
{
throw new FileNotFoundException(_location);
}
_dllHandle = UnsafeNativeMethods.LoadLibrary(_fullPath);
_fptr = UnsafeNativeMethods.GetProcAddress(_dllHandle, _procName);
}
}
Any thoughts on what I am doing wrong and how I can get a job will be greatly appreciated. Thank.
source
share