【发布时间】:2020-03-04 06:11:30
【问题描述】:
当我尝试使用我的 dll 中的函数时遇到问题
我按照这里所说的做了一切: https://docs.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=vs-2019
但是当我尝试运行测试应用程序时,我收到以下错误消息:
这是我的全部代码:
test.cpp:
#include "pch.h"
#include <iostream>
#include "SP_DLL.h"
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu
int main()
{
symbol_count();
}
dlltest.h:
#pragma once
#include <iostream>
using namespace std;
extern "C" _declspec(dllexport) bool symbol_count();
dlltest.cpp:
#include "pch.h"
#include "SP_DLL.h"
bool symbol_count()
{
char str[100];
char symbol;
size_t count = 0;
cout << "Enter string: ";
cin >> str;
cout << endl << "Enter symbol to count: ";
cin >> symbol;
for each (auto el in str)
if (el = symbol) count++;
return true;
}
如果有帮助:当我尝试运行空 symbol_count()(func 只有代码 {return true;} 并且 dll 没有包含)时,只有一个 .dll 没有找到。
【问题讨论】:
-
您链接的错误消息表明您尚未在目标 PC 上安装必要的运行时支持背景。也许请参阅here 以获得一些指导。
-
@Adrian-ReinstateMonica,感谢您的留言,但没有。我正在使用 ctrl+F5 从 VS 运行应用程序。此问题仅涉及使用 dll 引用运行应用程序。当我运行标准应用程序时一切都很好
-
我建议你可以尝试从C++ Runtime v14 framework package for Desktop Bridge (Project Centennial)下载安装的包,它提供了“msvcp140_app.dll”。然后从“C:\ProgramFiles\WindowsApps\Microsoft.VCLibs.140.00_
_ __8wekyb3d8bbwe”目录中复制“msvcp140_app.dll”,放到你的项目文件夹中。 -
@Jeaninez-MSFT,哦,谢谢,它正在工作!
标签: c++ c dll visual-studio-2017 dllexport