c – Loading multiple libraries with loadlibrary


I have two libraries, sph.dll and mydll.dll , and I try to load them using LoadLibrary as shown below:

HMODULE hlib = LoadLibrary("mydll.dll");
  MessageBox(NULL, "Erro -> mydll.dll não encontrado." , "Erro IB5 Printer" , MB_ICONERROR | MB_OK);}

HMODULE chlib = LoadLibrary("sph.dll");
  MessageBox(NULL, "Erro -> sph.dll não encontrado." , "Erro IB5 Printer" , MB_ICONERROR | MB_OK);}

The problem is that when I compile an error message comes up saying that sph.dll was not found. When I call sph.dll first, mydll.dll is not found. I'm using the DEV-C environment to program.

What's the problem here?


The problem with your code is not that it cannot find the DLL, but that a segmentation fault is occurring when the DLL is loaded.

By searching Microsoft documentation for the 998 error code returned by the GetLastError command, this code indicates the error ERROR_NOACCESS , which is the error code mapped to Windows segmentation faults.

Check if you are using compatible versions of these DLLs; check if your dependencies are correct (maybe they depend on other modules that are causing the failure of some variable used in the DllMain command, executed when the DLL loads to initialize); debug DLLs if you have their source code; check that the files are not corrupted (restore from a backup, or download them again).

To help determine dependencies, use the Dependency Walker program.

Scroll to Top