2

I'm about to develop a API that should be distributed with a DLL. Because I can't test my code written in the DLL directly, I have to load the DLL within a Test-Project and run it there.

I'm using Visual Studios 2015. There I made a Testproject and within that, I made my Project for the DLL:

Solution-Tree "TestProject"

  • DLLProject

  • TestProject

I export a dummy function to test if I am able to load the DLL:

#ifndef EXPORT
#define EXPORT __declspec(dllexport)
#endif

extern "C" {
    EXPORT int dummy() {
        return 5;
    }
}

Then, in my Testproject, I try to load the DLL, extract the function and run it:

#include <windows.h>
#include <iostream>
using namespace std;

typedef int (__stdcall *dll_func)();

int main() {
    HINSTANCE hGetProcIDDLL = LoadLibrary(TEXT("H:\\path\\to\\project\\Debug\\DLLProject\\DLLProject.dll"));

    if (hGetProcIDDLL == NULL) {
        cout << "DLL could not be loaded. " << GetLastError() << endl;
        return;
    }

    dll_func f = (dll_func)GetProcAddress(hGetProcIDDLL, "create");

    if (f == NULL) {
        cout << "Factory function could not be resolved. " << GetLastError() << endl;
        return;
    }

    cout << "Factory function returns: " << f() << endl;
}

I copied almost everything from this question. Unfortunately, when I run my Testproject, my console prints out: "DLL could not be loaded. 4250"

At this point I really don't know what to do because the Error as described here basicly says nothing. With a bit of research, I couldn't get any answers... hope you can help me :D

Community
  • 1
  • 1
Rockettomatoo
  • 257
  • 6
  • 18
  • Grab [procmon](https://technet.microsoft.com/en-us/sysinternals/processmonitor.aspx), set the filter to your test exe and see what file operations fail. – GSerg Apr 20 '17 at 09:07
  • Maybe I have to add that the testproject is a "Visual C++/CLR/CLR-Consoleprogramm"-Project and the DLLProject is a "Visual C++/Windows/DLL (Universal Windows)"-Project :D – Rockettomatoo Apr 20 '17 at 09:10
  • @GSerg all your Process monitor gives me, is a "Create Process". Nothing to see from my dll – Rockettomatoo Apr 20 '17 at 09:16
  • 1
    Clunky, but it is a simple "file not found" error. The path you typed certainly does not look correct, that is not where VS builds a DLL. Double-check with Explorer. Getting the function pointer declaration wrong does not score any points either. – Hans Passant Apr 20 '17 at 09:19
  • @HansPassant the path I wrote in my code leads to a my DLL. Maybe my Project-Setup is wrong because I created a new CLR-Project, then right-clicked on my solution-tree and created another project which is a DLL-Project... – Rockettomatoo Apr 20 '17 at 09:24

1 Answers1

-1

This is likely caused by linker settings. Make sure you specify "/APPCONTAINER:NO" in the linker settings.

Felix Lehmann
  • 263
  • 2
  • 4