Hello,
I'm new in programming. I tried to reproduce the code, mentioned in the following link:
"Simple C++ DLL Programming Tutorial"
https://www.youtube.com/watch?v=fzO9L6tlXDIDLL was created successfully, but exe-file was not created and I received a message:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-------------- Build: Release in DLL (compiler: GNU GCC Compiler)---------------
Target is up to date.
Nothing to be done (all items are up-to-date).
-------------- Build file: "no target" in DLL (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -c ..\TEST_LAUNCH_DLL\LaunchDLL.cpp -o ..\TEST_LAUNCH_DLL\LaunchDLL.o
mingw32-g++.exe -o ..\TEST_LAUNCH_DLL\LaunchDLL.exe ..\TEST_LAUNCH_DLL\LaunchDLL.o
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
After that I clicked "Debug" and popup widow appeared with a message:
"You must select a host application to "run" a library"
Please, explain me what to do in order to fix the problem.
Thanks!
3 files attached:
1. LaunchDLL.cpp
// ``````````````````````````````````````````````````````````````````````````````````````````````````
#include <iostream>
#include <windows.h>
using namespace std;
typedef int (*MsgFunction) (int);
HINSTANCE hinstDLL;
int main() {
MsgFunction MsgBox(0);
hinstDLL = LoadLibrary("InfernoDevelopment.dll");
if(hinstDLL != 0) {
MsgBox = (MsgFunction)GetProcAddress(hinstDLL,"MsgBox");
}
if(MsgBox == 0) {
cout << "MsgBox is NULL" << endl;
}
int x = MsgBox(5);
if(x == 5) {
cout << "Message Displayed!" << endl;
}
FreeLibrary(hinstDLL);
return 0;
}
// ``````````````````````````````````````````````````````````````````````````````````````````````````
2. main.cpp
// ``````````````````````````````````````````````````````````````````````````````````````````````````
#include "main.h"
// a sample exported function
int DLL_EXPORT MsgBox(int x = 0) {
MessageBox(0, "Join Us at Inferno Dev!", "DLL Message", MB_OK | MB_ICONINFORMATION);
return x;
}
extern "C" DLL_EXPORT BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}
// ``````````````````````````````````````````````````````````````````````````````````````````````````
3. main.h
// ``````````````````````````````````````````````````````````````````````````````````````````````````
#ifndef __MAIN_H__
#define __MAIN_H__
#include <windows.h>
/* To use this exported function of dll, include this header
* in your project.
*/
#define DLL_EXPORT __declspec(dllexport)
#ifdef __cplusplus
extern "C"
{
#endif
int DLL_EXPORT MsgBox(int x);
#ifdef __cplusplus
}
#endif
#endif // __MAIN_H__
// ``````````````````````````````````````````````````````````````````````````````````````````````````