Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi every body,

I have a big problem. here a test code of Dll :

main.h
C++
#pragma once

#define BUILD_DLL

#ifdef BUILD_DLL
#define DLL_EXPORT __declspec(dllexport)
#else
#define DLL_EXPORT __declspec(dllimport)
#endif


#ifdef __cplusplus
extern "C"
{
#endif

   BOOL DLL_EXPORT Exe(int i);


#ifdef __cplusplus
}
#endif

Dll.cpp :
C++
// dllmain.cpp : Defines the entry point for the DLL application.
 #include <Windows.h>

 #include "main.h"


 BOOL DLL_EXPORT Exe(int i){

    int a = i;

    return TRUE;
 }


 BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
 {
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
 }

And the application code looks like this :

C++
#include <Windows.h>
#include <stdio.h>


int main(int argc, char* argv[])
{

   HMODULE hmodule;

   hmodule = LoadLibraryEx("Dll.dll", NULL, 0);

   if (hmodule == NULL)
   {
       printf("Fail : %d", GetLastError());
   }
   else
       printf("Loaded");

   int i;
   scanf("%d", &i);

   return 0;
}

Here is the problem :

I compile this dll code under VS 2015 community with the following parameter to avoid some dependency files :
- no precompiled header
- Multi thread Dll
- Multi bytes char set
- Use standard windows library
- platform toolset : Visual Studio 2015 - Windows XP (v140_xp)

After the compilation i test the application :

under windows 8.1 : Ok, i have the loaded message :)

under windows 10 : KO , error 126 (no module found)

I take exactly the same code. I compile this with Code::Blocks (GCC) witht the default parameters for a DLL project :

windows 8.1 : OK, loaded message

windows 10 : OK, loaded message

... the same code. So i'm looking for a compilation option to modify somewhere , but i found nothing until now.

Any ideas ?

Thanks by advance and sorry for my bad english :)
Posted
Updated 21-Aug-15 9:17am
v3
Comments
Richard MacCutchan 22-Aug-15 4:36am    
The DLL needs to be in a location that Windows checks when you try to load it. So that is one of the directories listed in your PATH environment variable, or the same directory that holds the .exe file.

1 solution

If you really named your library Dll.dll, that's a horrible name!

Aside from that, I'd check what Richard suggested above (make sure there's a path to the library or its in a good default location) and also check with a tool like Dependency Walker[^] to make sure there isn't some other library that it's attempting to load. Possible that you've loaded some external library when building with VisualStudio that is present in 8 and not in 10 (could have perhaps linked some of the VisualStudio redistributable packages).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900