0

I am using LoadLibrary function from kernel32.dll to load some 64-bit assembly files with full file path in C#. But it returns null pointer. And also it returns 0 for getLastError() function. Below is the function definition code in C#.

[DllImport("kernel32.dll"), SuppressUnmanagedCodeSecurity]
static extern uint LoadLibraryEx(string fileName, uint notUsedMustBeZero, uint flags);

Below is the code that I tried to load the 64-bit assembly.

var hLib = LoadLibraryEx(filePath, 0, DONT_RESOLVE_DLL_REFERENCES | LOAD_IGNORE_CODE_AUTHZ_LEVEL);

How to fix this issue?

Shehan V
  • 164
  • 1
  • 14
  • 2
    Why do you want to LoadLibrary an _assembly_, by which I assume you mean a .NET assembly? And what bitness is your application compiled with? Also, use `SetLastError=true` to be able to call `GetLastError()`. – CodeCaster Oct 31 '18 at 11:34
  • Assembly is not only mean .Net assembly. It means all managed and unmanaged assembly files. I didn't set SetLastError=true. I will try with that also. – Shehan V Nov 01 '18 at 11:14
  • I don't know the bitness of the application that compiled with. – Shehan V Nov 01 '18 at 11:15
  • No, in the context of DLLs, "assembly" means a [".NET Assembly"](https://stackoverflow.com/questions/2972732/what-are-net-assemblies). An [unmanaged PE DLL](https://en.wikipedia.org/wiki/Dynamic-link_library) is not called an "assembly". – CodeCaster Nov 01 '18 at 11:17

0 Answers0