Loadlibrary fails to load dll

前端 未结 7 2076
梦谈多话
梦谈多话 2021-02-10 01:18
    *******************UseDll1.cpp*********************

        #include 

typedef int (*function1_ptr) ();

function1_ptr function1=NULL;

int APIENTR         


        
相关标签:
7条回答
  • 2021-02-10 01:28

    Just because the code runs and exits doesn't mean it's right! Are you sure that:

    • The DLL is being correctly loaded (myDll!=null)
    • GetProcAddress is returning a valid pointer (function1!=null)

    You should step through the code in a debugger to make sure all this is happening and that the code does get to function1(). If it does then my guess would be that your email function has a bug in it.

    0 讨论(0)
  • 2021-02-10 01:28

    Have you verify that you have all external dependencies for "DLL1.dll" ?

    LoadLibrary will fail even if any of the indirect linked-library is not available.

    0 讨论(0)
  • 2021-02-10 01:31

    Why not debug it and see where it fails? Make sure your dll is actually being loaded(it could simply be a path issue or a bad dll(you might have not imported/exported the functions).

    Find out where the issue is first. It's either in loading the dll, calling the function, or inside the function

    0 讨论(0)
  • 2021-02-10 01:32

    Thank you very much, your web page helped me a lot :) I only had to use tchar.h to make it working. You can see it in the rest of the answer.

    #pragma once
    #include <windows.h>
    #include "spinapi.h"
    #include <tchar.h>
    
    typedef int (*count_boards_ptr)(void);
    
    int x = 0;
    HINSTANCE hinstDLL;
    hinstDLL = LoadLibrary(_T("C:\\Smajdalf\\doucko_C\\DLLProblem\\DLLProblem\\spinapi.dll"));
    count_boards_ptr count_boards = NULL;
    count_boards = (count_boards_ptr) GetProcAddress(hinstDLL, "pb_count_boards");
    
    if(count_boards != NULL) {
        x = count_boards();
    }
    
    FreeLibrary(hinstDLL);
    
    0 讨论(0)
  • 2021-02-10 01:47

    I had the same issue. This link resolved it. The issue was that I was not using _T macro.

    0 讨论(0)
  • 2021-02-10 01:48

    I think you have already checked existence of dll.

    Now Try this ::

    Try to change "Any CPU" to 86 or 64.

    Try to run your application as administrator.

    0 讨论(0)
提交回复
热议问题