Search code examples
c++cdllvisual-studio-2017dllexport

problem when i try to use function from my dll


I have a problem when i try to use function from my dll

I did everything as it says here: https://learn.microsoft.com/en-us/cpp/build/walkthrough-creating-and-using-a-dynamic-link-library-cpp?view=vs-2019

But when i'm trying to run the test app, i get the following error messages:

img1

img2

Here is my whole code:

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;
}

If it helps: when i'm trying to run empty symbol_count() (func have only code {return true;} and dll have no includes) there is the only one .dll not found.


Solution

  • I suggestyou could try to downloaded the installed packages from C++ Runtime v14 framework package for Desktop Bridge (Project Centennial),which provided the "msvcp140_app.dll". And then copied "msvcp140_app.dll" from the "C:\ProgramFiles\WindowsApps\Microsoft.VCLibs.140.00____8wekyb3d8bbwe " directory, placed it into your project folder.

    – Jeaninez - MSFT Nov 8 at 2:25