I’m trying to write a dll that will store some values passed to it in between calls.
Currently, I have:
MyDll.h:
namespace MyDllNamespace
{
class MyClass
{
public:
static int getValue(int &a);
};
}
MyDll.cpp:
#include "ALERTDataAnalysisLibrary.h"
#include <stdexcept>
using namespace std;
namespace MyDllNamespace
{
int storedValue=0;
int MyClass::getValue(int &a)
{
a=a+storedValue;
}
}
MyDll.def
LIBRARY MyDllLibrary
EXPORTS
getValue @1
The idea is that the first time it is called, it returns the passed value, and the second time it’s called it returns the sum of the passed value, and the previously passed value. (This is a bit cut down, the final version will have to work on arrays, and with more values, but one step at a time!)
I think what I want to do is stop getValue being static. Which would mean instantiating a class within the DLL (perhaps when it’s loaded), and storing data in that. Then exposing a function of that class. I’ve no idea if that’s the way to do it, I’ve not found anything like it after much searching.
You could export the whole class (and optionally use the pimpl idiom, but that’s not mandatory):
In your DLL header file “MyDll.h”, write the following:
Then, make sure that MYDLL_EXPORTS is defined in your DLL project only, so when you compile your DLL, your class is “dllexported”, while when included in your main application, it’s “dllimported”.
Also, you won’t need the .def file anymore.