I'm trying to connect my program to a dll.
Connect code:
HINSTANCE lib;
lib = LoadLibrary("DLL.dll");
if (lib)
{
cout << "Libary Loaded !";
FreeLibrary(lib);
}
else
{
cout<<GetLastError();
}
DLL code(at DLL.cpp):
#include "pch.h"
#include "DLL.h"
#include<iostream>
using namespace std;
int f()
{
return 11;
}
Once I run the program I get this error:
The program can't start because <dllname> is missing from your computer.
After each dll request I downloaded the dll from the internet and put it into the folder where the dll and the program are. Here are some of the dll I requested:
- VCRUNTIME140_APP.dll
- api-ms-win-core-processthreads-l1-1-2.dll
Once I get that error after clicking 'OK' button I get GetLastError() = 126
.
I tried to link my program to the lib VCRUNTIME140_APP.dll
just to check if it is going to load the library and it did. So the problem is probably in the library I try to connect to.
I work with Visual Studio 2015.Both the DLL and the program are compiled in x86(32bit). I have all redistribution packages installed. I tried with x64(64bit) but got same errors and the same dlls requests. I tried to put DLL in build and in debug folders both didn't work.
I also tried using **LoadLibaryA**
and **LoadLibaryW**
but these didn't work as well.
PS: Just tried dll I created in CodeBlocks instead of Visual Studio 2015 and it connected. Should be a Visual Studio Compiler specific problem.