简体   繁体   中英

dll loading error using LoadLibraryA

We are trying to load a dll-library from inside a 64-bit dll using LoadLibraryA function. It returns 126 error - mod not found. The dll file path given to the function is correct, we are sure.

We have tried a dummy dll to test and it worked, it is loaded.

We also tried adding the dll (which is a dependcy of the first dll that we want to load) to the dummy dll. It also worked. So the problem seems not about the dependency dlls, but the original dll that we want to load in the first place.

We also tried converting the dl to 64-bit, and tried that, still no good.

We also checked the dependencies with Dependency Walker. Everything is OK.

The operating system that we are using is Windows 8, 64bit. If it makes any difference.. Does anyone have any idea about this poblem?

EDIT: We also tried this code:

hModule = LoadLibraryW(L"C:\\temp\\dllToLoad.dll");

and received this error code:

"First-chance exception at 0x00000000 in C_Test_TSMPPKCS11.exe: 0xC0000005: Access violation at location 0x0000000000000000."

EDIT 2: The code that we used in the first place is:

hModule = LoadLibraryA((char*)aDLLFile);

EDIT 3: We are using complete path to load the dll. In order to test this we tried this code:

FILE *fp;
    int size = 0;
    fp=fopen("C:\\temp\\dllToLoad.dll", "r");
    size = fgetc(fp);
    printf("size:%d\n",size);
    fclose(fp);

There was no problem, we received the file size which is 77.

We also tried converting the dl to 64-bit, and tried that, still no good.

There's no way you can load a 32-bit dll as executable code into a 64-bit process (and since you're using LoadLibraryA() that's all you can be trying to do).

Assuming the dll that you are trying to load and the process that you're loading it into are the same type then are you passing a complete path to LoadLibraryA() or a relative path or just a dll name? If you're not using a complete path then consider using LoadLibraryEx() if possible as this gives you much more control over the search path used. If you are using a complete path try opening the file using normal file operations if you fail to load the dll, does this work? If that works then try LoadLibraryEX() with LOAD_LIBRARY_AS_DATAFILE and see if that will load the dll as a simple data file (which proves that it's finding the file).

Run up Sysinternal's ProcMon and watch the code open the DLL, that may show you dependent DLL load failures.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM