LoadLibray returns 0 when I'm trying to load a dll file. I'm using Visual Studio 2017

#include "App.h"
#include <windows.h>
#include <iostream>

using namespace std;

typedef int(__stdcall *f_funci)(unsigned char, unsigned int);

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

    SetDllDirectory((LPCWSTR)L"C:\\xmrig-master\\build\\Debug");
    HINSTANCE hGetProcIDDLL = LoadLibrary(L"asm.dll");

    if (!hGetProcIDDLL) {
        cout << "could not load the dynamic library" << endl;
        //return EXIT_FAILURE;
    }else{
        cout << "cy" << endl;
    }
    /*
    f_funci assemblerMode = (f_funci)GetProcAddress(hGetProcIDDLL, "asm");

    if (!assemblerMode) {
        cout << "could not locate the function " << assemblerMode << GetLastError() << endl;
        //return EXIT_FAILURE;
    }

    cout << "assemblerMode() returned " << assemblerMode(1,0) << endl;
    //*/
    App app(argc, argv);
    return app.exec();
}

Recommended Answers

All 10 Replies

What does the call to SetDllDirectory return?

SetDllDirectory returns 1

Line 11 looks odd to me. Are you sure about what's in the ()? Did you check if the dll exists?

Yes, the dll file is in the path

I wonder about that L in the () line 11. Also, just call out the full path since well, may as well try it. Of course if there are permission issues or the dll is bum, none of this applies.

I tried all the above, still nothing

I removed the L and I tried like this:

HINSTANCE  hGetProcIDDLL = LoadLibrary((LPCWSTR)"c:\\xmrig-master\\build\\Debug\\asm.dll");

still the same

Why was that L there? I've never seen that? Didn't the compiler bark at you?

Also, now that we know a bit more about what you are trying to build. Back to https://github.com/xmrig/xmrig/wiki/Windows-Build

If the build instructions fail, ask them why or how to fix.

PS. I wish folk would share when they are trying to build apps from github.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.