Answer the question
In order to leave comments, you need to log in
How to call function from cpp file in winform?
Hello.
I am new to Winforms, only worked with C++ in console.
In the MyForm.cpp file, a function is declared - int check() , how can I call it in the form and write return to some variable?
Visual Studio 2017 development environment
Code in MyForm.cpp :
#include "MyForm.h"
#include "MyForm1.h"
#include <iostream>
#include <Windows.h>
#include <string>
#include <stdlib.h>
#include <conio.h>
#include <tchar.h>
using namespace System;
using namespace System::Windows::Forms;
DWORD pid;
[STAThread]
int main(array<String^>^ arg){
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Project1::MyForm form; //WinFormsTest - имя вашего проекта
Application::Run(%form);
}
int reply = 0;
int check(){
HWND hWnd = FindWindowA(0, ("notepad"));
GetWindowThreadProcessId(hWnd, &pid);
if(hWnd){
reply = 1;
return reply;
}else{
reply = 2;
return reply;
}
}
Answer the question
In order to leave comments, you need to log in
1. Right click on project -- > Properties --> Configuration Properties --> Linker --> Input
2. Select the 'Additional Dependencies" property node and then Click the on the 3 dotted (...) button
3. Then on the 'Additional Dependencies' popup, input "user32.lib" on the top textbox and click on 'Ok' button
4. Click on 'Apply' button and re-compile your application. .............. the linker errors are gone!
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question