Error 6 - Invalid handle while loading dll on a WinForms app

-2

Problem apppears while loading dll on a Windows Forms app, works okay on console. Haven't found anything similar to my problem yet, all the dll files seem to be correct. Following code usually shows error 6 Invalid handle or error 18(happened once i really don't know why). Worth noting that some dlls work fine and we couldn't find the difference between those that don't work and those that do.

public IntPtr LoadWin32Library(string dll_path)
{
    System.IntPtr dll_pointer = LoadLibraryEx(dll_path, IntPtr.Zero, 0x00000008);
    if (dll_pointer == IntPtr.Zero)
    {
        int errorCode = Marshal.GetLastWin32Error();
        throw new Exception(string.Format("There was an error during dll loading : {0}, error - {1}", dll_path, errorCode));
    }

    return dll_pointer;
}
c#
winforms
dllimport
asked on Stack Overflow May 10, 2020 by Pol'za • edited May 10, 2020 by VRoxa

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0