VS2015 LoadLibrary failed to load DLL solution, GetLastError() return value 193

problems encountered

code show as below

void *p=NULL;
p=LoadLibrary("***.dll");

Through single-step debugging, it is found that the value of p is always 0X00000000, that is, the LoadLibrary call fails. After
checking a lot of information, the summary and my solution are recorded as follows


  • Check if the path is correct. I am using a relative path. The relative path needs to put the dll file in the directory of the exe file generated by the program (that is, project->properties->(configuration properties) general->output directory in VS), and then due to the character format problem , which can be written as a p=LoadLibrary(TEXT("***.dll"));TEXT macro that eliminates formatting issues.
  • DLL consistency issues. That is, the exe version must be consistent with the dll version in debug/release, and x64 or win32 may also need to be consistent. I am using the release x64 version.
  • If the problem has not been solved, use the GetLastError() function to get the error message. The GetLastError() function is the api to get the result of the last error, so call it in the next line of LoadLibrary
void *p=NULL;
p=LoadLibrary("***.dll");
DWORD error_id=GetLastError();
  • Check the value of error_id by printing or in single-step debugging, and then search for the corresponding solution. My return value is 193. The main problem is that the dll I loaded is also associated with other dlls, so I put all the dlls I need to use in the directory of the exe program and it runs successfully.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324853332&siteId=291194637