Loading multiple libraries with loadlibrary

Asked

Viewed 86 times

3

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");
if(!hlib){ 
  printf("error");
  MessageBox(NULL, "Erro -> mydll.dll não encontrado." , "Erro IB5 Printer" , MB_ICONERROR | MB_OK);}

HMODULE chlib = LoadLibrary("sph.dll");
if(!chlib){ 
  printf("error");
  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 arises saying that sph.dll was not found. When I call sph.dll first, mydll.dll is not found. I am using the DEV-C environment to program.

What’s the problem here?

  • 1

    When do you compile? If the error happens at the time of compilation, it is because you are sending Linker to link to these libraries and there is something wrong either in the paths passed to Linker, or in your command line. Already with the command LoadLibrary, libraries are loaded at runtime, manually, without the need for Linker instructions. Please get more details about the problem.

  • The error does not happen at build time, the error happens while running the program, it informs you that the dll was not found. Both dlls are in the same directory, which is the same directory as the executable.

  • How are you sure the problem is that the second DLL was not found? Use the command GetLastError to identify what really happened. Documentation: https://msdn.microsoft.com/en-us/library/windows/desktop/ms679360%28v=vs.85%29.aspx Add the error to the question, please.

  • Thank you, I did as you asked, the mistake is 998.

  • This is an error code. Only serves to search for the error message.

1 answer

0

The problem with your code is not that it does not find the DLL, but that it is occurring a segmentation fault at the time of loading the DLL.

Searching Microsoft documentation for error code 998 returned by command GetLastError, this code indicates the error ERROR_NOACCESS, which is the error code mapped to the Windows targeting flaws.

Make sure you are using compatible versions of these DLL; make sure your dependencies are correct (maybe they depend on other modules that are causing the failure to boot some variable used in the command DllMain, run on DLL upload); debug Dlls if you have your sources; check that the files are not corrupted (restore from a backup, or download them again).

To help determine dependencies, use the program Dependency Walker.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.