简体   繁体   English

Visual Studio c ++ LoadLibary错误:无法启动程序,因为计算机中缺少dll

[英]Visual Studio c++ LoadLibary error: The program can't start because dll is missing from your computer

I'm trying to connect my program to a dll. 我正在尝试将程序连接到dll。

Connect code: 连接代码:

HINSTANCE lib;

    lib = LoadLibrary("DLL.dll");
    if (lib)
    {
        cout << "Libary Loaded !";
        FreeLibrary(lib);
    }
    else
    {
        cout<<GetLastError();
    }

DLL code(at DLL.cpp): DLL代码(位于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. 该程序无法启动,因为您的计算机缺少<dllname>。

After each dll request I downloaded the dll from the internet and put it into the folder where the dll and the program are. 在每个dll请求之后,我从互联网上下载了dll,并将其放入dll和程序所在的文件夹中。 Here are some of the dll I requested: 这是我要求的一些dll:

  1. VCRUNTIME140_APP.dll VCRUNTIME140_APP.dll
  2. api-ms-win-core-processthreads-l1-1-2.dll api-ms-win-core-processthreads-l1-1-2.dll

Once I get that error after clicking 'OK' button I get GetLastError() = 126 . 单击“确定”按钮后出现该错误后,我将得到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. 我试图将我的程序链接到lib VCRUNTIME140_APP.dll只是为了检查它是否要加载该库,是否确实如此。 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). 我使用Visual Studio 2015.DLL和程序都在x86(32bit)中编译。 I have all redistribution packages installed. 我已经安装了所有重新分发软件包。 I tried with x64(64bit) but got same errors and the same dlls requests. 我尝试使用x64(64bit),但出现相同的错误和相同的dlls请求。 I tried to put DLL in build and in debug folders both didn't work. 我试图将DLL放入构建和调试文件夹中都无法正常工作。

I also tried using **LoadLibaryA** and **LoadLibaryW** but these didn't work as well. 我也尝试使用**LoadLibaryA****LoadLibaryW**但这些效果不佳。

PS: Just tried dll I created in CodeBlocks instead of Visual Studio 2015 and it connected. PS:刚尝试了我在CodeBlocks中创建的dll,而不是Visual Studio 2015,并且它已连接。 Should be a Visual Studio Compiler specific problem. 应该是Visual Studio编译器特定的问题。

If you look to the syntax of LoadLibrary function: 如果您查看LoadLibrary函数的语法:

HMODULE WINAPI LoadLibrary(
   _In_ LPCTSTR lpFileName
);

You see that there is no option to specify from where to load your library 您会看到没有选项可以指定从何处加载库

Instead use the function LoadLibraryEx witch has the following syntax: 而是使用功能LoadLibraryEx来执行以下语法:

HMODULE WINAPI LoadLibraryEx(
   _In_       LPCTSTR lpFileName,
   _Reserved_ HANDLE  hFile,
   _In_       DWORD   dwFlags
);

So with the use of dwFlags parameter , you can now specify from where your program can try to load your library. 因此,使用dwFlags参数 ,您现在可以指定程序从何处尝试加载库。

example of dwFlags: dwFlags的示例:

LOAD_LIBRARY_SEARCH_APPLICATION_DIR 0x00000200: LOAD_LIBRARY_SEARCH_APPLICATION_DIR 0x00000200:

witch means: 女巫的意思是:

 If this value is used, the application's installation directory is searched  
 for the DLL and its dependencies. Directories in the standard search path  
 are not searched.

So to resume, you have to use the dwFlags parameter you want in order to find your dll. 因此,要恢复,必须使用想要的dwFlags参数才能找到您的dll。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “程序无法启动,因为您的计算机中缺少 opencv_world300.dll”错误 C++ - "The program can't start because opencv_world300.dll is missing from your computer" error in C++ 程序无法启动,因为您的计算机缺少mfc120ud.dll - The program can't start because mfc120ud.dll is missing from your computer 由于您的计算机上缺少freeglut.dll,因此无法启动该程序 - This program can't start because freeglut.dll is missing from your computer 该程序无法启动,因为您的计算机中缺少MSVCP90D.dll - The program can't start because MSVCP90D.dll is missing from your computer Qt + VS2010:程序无法启动,因为 <xyz> 您的计算机缺少.dll - Qt + VS2010: The program can't start because <xyz>.dll is missing from your computer 该程序无法启动,因为您的计算机缺少libgcc_s_dw2-1.dll。 简单的控制台 - The program can't start because libgcc_s_dw2-1.dll is missing from your computer. Simple console 我在Visual Studio中运行了一个Qt C ++项目,但缺少“由于QtCored4.dll而导致程序无法启动” - I run a Qt C++ project in Visual studio and got “the program can not start because QtCored4.dll” is missing Visual Studio 2012上的计算机错误导致GDAL201.dll丢失 - GDAL201.dll missing from your computer error on Visual studio 2012 该程序无法启动,因为缺少msvcr100.dll - the program can't start because msvcr100.dll is missing 程序无法启动,因为缺少* .dll - MinGW,Eclipse,Windows 7 - Program can't start because *.dll is missing - MinGW, Eclipse, Windows 7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM