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:
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.
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
Related
I'm programming a tool in C++ to remove the 000.exe malware. The malware creates a lot of files on the desktop named "UR NEXT UR NEXT UR NEXT" etc. My first step is to remove all these files from the desktop. What can I do to check every file on the desktop and for each one that contains the string "UR NEXT" somewhere in the file name, delete it. I have a basic structure of my program already written but I'm really stuck figuring out the user's username folder, then deleting ever file containing "UR NEXT" on the desktop. Any help would be greatly appreciated. I'm using Visual Studio 2019 and I already have an elevation added to the program.
#include <iostream>
#include <Windows.h>
#include <WinUser.h>
using namespace std;
int main()
{
string answer;
cout << "=~=~=~=~=~=~=~=~=~=~=~=~=~=\n000.exe Removal Tool\n\nby OrcaTech\n\nThis tool can be used to remove the 000.exe malware from your Windows PC. Type \"y\" below and press [ENTER] to begin the removal process.\n=~=~=~=~=~=~=~=~=~=~=~=~=~=" << endl;
cin >> answer;
if (answer == "y")
{
cout << "Starting Removal Process..." << endl;
cout << "Your computer will restart multiple times." << endl;
//Stop "run away" spam message boxes
system("taskkill /f /im runaway.exe");
//Change the wallpaper back to the default.
const wchar_t* path = L"%SystemRoot%\\Web\\Wallpaper\\Windows\\img0.jpg";
SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, (void*)path, SPIF_UPDATEINIFILE);
/* code to delete all files on desktop containing UR NEXT goes here */
system("pause");
return 0;
} else {
exit(0);
}
}
You can use std::filesystem::directory_iterator to iterate over every file in the desktop folder and remove the files with specific names:
#include <filesystem>
#include <string>
#include <vector>
int main()
{
std::vector<std::filesystem::path> filesToRemove;
for (const auto& i : std::filesystem::directory_iterator("path_to_desktop"))
{
std::string fileName = i.path().filename().string();
if (fileName.find("UR NEXT") != std::string::npos)
{
filesToRemove.emplace_back(i);
}
}
for (const auto& i : filesToRemove)
{
std::filesystem::remove(i);
}
}
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib>
using namespace std;
int main() {
string line;
cout << "HW\n";
getline(cin,line);
cout << "Your line is - " << line << "\n";
system("pause");
return 0;
}
I want to do gui to factorio headless server by myself so i need to exec few bash scripts. I think i need function system() to that ?
I think I got problem with lib path. Please don't blame to wrong installed vcpkg. Paths is :
/opt/factorio/bin/x64/vcpkg/installed
/usr/include/c++/9/x86_64-redhat-linux
/usr/include/linux
/usr/include/c++/9/tr1
Command system() not found says Visual Studio.
system("pause"); is meant to be used only on Windows. It runs the Windows command-line "pause" program and waits for that to terminate before it continues execution of your program. That's why it's a bad practice to use it in your code, no matter if you are running your code on Windows or Linux.
Here is a better way you can achieve the same result:
#include <iostream>
using namespace std;
int main() {
do {
cout << '\n' << "Press the Enter key to continue.";
} while (cin.get() != '\n');
return 0;
}
instead of:
#include <iostream>
using namespace std;
int main() {
system("pause");
return 0;
}
this is my code i am using vs2013. i have set dependencies and all the linkers but still my code compiles correctly but when cosole opens it says error initializing vm, unable to find native libraries
#include <iostream>
#include <voce.h>
#include <Windows.h>
#include <string>
#pragma comment(lib, "jvm.lib")
#pragma comment(lib, "jawt.lib")
using namespace std;
int main()
{
init("C:\\voce-0.9.1\\lib\\", false, true, "C:\\voce - 0.9.1\\lib\\gram", "digits.gram");`
string s;
// Speech recognition in C++
while (voce::getRecognizerQueueSize() > 0)
{
s = voce::popRecognizedString();
cout << "You said: " << s << endl;
}
return 0;
}
I am writing a simple program down below in C++ using Visual Studio 2015 and when I #include <iostream> I get a bunch of errors like in the image below:
My code can be found below and in the image.
// FirstProject.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
int main()
{
std::cout << "Hello World!";
int pause;
pause = 0;
std::cin >> pause;
return 0;
}
Code and Errors
The Errors came from Visual Studio 2015 not being able to properly locate the include files.
I am still fairly new to NetBeans, and am writing code for class in C++. I am currently on my third project, and I have run into an error I can't seem to resolve when trying to compile+run my project. I have quadruple-checked my code, going so far as to copy code from a previous project. I have tried quiting, rebooting the computer, and starting NetBeans up again. I ran CppCheck on my code and it found no errors.
The error message:
build/Debug/MinGW-Windows/main.o: In function `main':
C:/Users/Martin/Documents/NetBeansProjects/Lab3/main.cpp:52: undefined reference to `Dictionary::Dictionary()'
C:/Users/Martin/Documents/NetBeansProjects/Lab3/main.cpp:52: undefined reference to `Dictionary::~Dictionary()'
I tried copying code from a previous project, and even with the exact same code as a previous project which works, it's still having this problem. Basically, the build is failing to recognize the Dictionary class.
What things can I check that might cause this problem? Any obscure (or even obvious) settings I can check? Should I just start a new project and copy my code over?
Edit: Adding main():
#include <cstdlib>
#include <iostream>
#include "Dictionary.h"
using namespace std;
/*
* argv[1] dictionary file
* argv[2] boggle board file
* argv[3] output file
*/
int main(int argc, char** argv) {
if (argc > 3) {
Dictionary dict;
dict.loadDictFile(argv[1]);
} else {
cout << "Not enough arguments. Needed: ./lab3 [dictionary file] "
"[board file] [output file]" << endl;
}
return 0;
}
And Dictionary.h:
#ifndef DICTIONARY_H
#define DICTIONARY_H
#include <string>
#include <set>
using namespace std;
class Dictionary {
public:
Dictionary();
Dictionary(const Dictionary& orig);
virtual ~Dictionary();
virtual void loadDictFile(char * fileName);
virtual bool find(string word);
private:
set<string> dict;
set<string> fullDictionary; // Contains all words, not just those 4+ char long.
};
#endif /* DICTIONARY_H */
And Dictionary.cpp:
#include "Dictionary.h"
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <set>
//using namespace std;
Dictionary::Dictionary() {
}
Dictionary::Dictionary(const Dictionary& orig) {
dict = orig.dict;
fullDictionary = orig.fullDictionary;
}
Dictionary::~Dictionary() {
}
void Dictionary::loadDictFile(char* fileName) {
ifstream infile;
infile.open(fileName);
if (infile) {
while(!infile.eof()) {
string line;
getline(infile, line);
fullDictionary.insert(line);
if (line.size() > 3) {
dict.insert(line);
}
}
} else {
cout << "Dictionary File not loaded: " << fileName << endl;
}
}
bool Dictionary::find(string word){
if (dict.find(word) != dict.end()) {
return true;
} else {
return false;
}
}
Found my problem. Netbeans didn't consider the Dictionary class to be part of my project, so it wasn't compiling Dictionary.cpp. I added it in the Project window by right-clicking the Source Files folder and using Add existing item... menu option. Now it compiles fine.
Does anyone know why the class wouldn't be added if I used Netbean's New File interface and added to the project specifically?