use a "permanent"/"static" variable in a DLL?

From a script language I will call functions from a DLL written in C++. In the DLL I want to initialize an array of double floats. And then use these values every time I call a function from that DLL. Is this possible?

I cannot declare this variable in the script language because it does not support doubles.
I'm not sure why you think you wouldn't be able to do that - could you explain your thinking a bit more?
Last edited on
Hello LB

I started to work with DLLs and DEVC++ just days ago. So I just don't know how to do this, or even google it. I tried Gloabal vars and Static vars but I had no luck. If you point me to the right article, or even tell me what is the terminology for it, then I guess I can do it.

My thinking:
1) I want to call the DLL function init_vars(). This will initialize an array of double floats.
2) I want to call func1() and func2() DLL functions. Those will use the array.

Simple, I just don't know how to declare stuff to do it.
You don't even need step 1.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
auto get_array()
-> std::vector<double> &
{
    static std::vector<double> v {0.0, 3.14, 10.0, 11.2}; //only initialized once
    return v;
};

void func1()
{
    auto &array = get_array();
    //...
}
void func2()
{
    auto &array = get_array();
    //...
}
By the way, some versions of DevC++ are terribly outdated and should not be used - check out this article and consider switching to another IDE:
http://www.cplusplus.com/articles/36vU7k9E/
Thank you very much for the help and the code provided.

I had read that article. I am using the latest Orwell Dev-C++.
Hi LB

I tried to understand your code and use it. It seems that the std::vector notation is about the Standard Vector. Since I am a beginner, I would prefer the "normal" array. So I am trying to rewrite the code, use memory allocation etc.

If it is easy for you, would you mind writing this in more simple terms?
You should have learned about std::vector before learning about plain arrays. Plain arrays are far more complicated than std::vector and I try to avoid using them as much as possible.
Topic archived. No new replies allowed.