I would like to use a c++ library given by a company. I only have the .lib and the .h files. I would like to use it in unity. So I need a DLL. So I want to create a DLL that permit me to access the functions I need in the .lib .
To do so I created a visual studio c++ DLL project with a c++ file that call the desired functions from the library. The .lib is linked to visual studio in linker/input/additional dependences.
In order to make it simple I am trying to call fonctions of my DLL from a normal c++ file instead of unity.
My test file look like this :
#include <windows.h>
#include <iostream>
void CallMyDLL(void)
{
HINSTANCE hGetProcIDDLL = LoadLibrary("C:\\path\\museDLL.dll");
FARPROC lpfnGetProcessID = GetProcAddress(HMODULE (hGetProcIDDLL),"startConnection");
typedef void (__stdcall * pICFUNC)();
pICFUNC startConnection;
startConnection = pICFUNC(lpfnGetProcessID);
//std::cout << test<< std::endl;
startConnection();
FreeLibrary(hGetProcIDDLL);
}
int main () {
CallMyDLL();
}
and my main DLL file look like this :
#include "dllmain.h"
#include <iostream>
#include <fstream>
#include "main_muse.h"
namespace museDLL
{
MainPage* mp;
void startConnection()
{
mp = new MainPage();
}
double getValue()
{
return mp->getValueEEG();
}
double test()
{
return 1.2f;
}
}
dllmain.h
#pragma once
#ifdef DLL_EXPORTS
#define DLL_API __declspec(dllexport)
#else
#define DLL_API __declspec(dllimport)
#endif
namespace museDLL
{
extern "C" {
DLL_API void __cdecl startConnection();
DLL_API double __cdecl getValue();
DLL_API double __cdecl test();
}
}
If I call the test function in my DLL it works. However If I call the startConnection function that use functions from the original .lib it crashes ( no error messages ) .
so to make it clear , I want test file-> calling my custom DLL -> calling the downloaded .lib .
I don't understand what I am doing wrong?
I wonder if the initial .lib is included in the .DLL or do I need to link it somehow?