I am using a def file to export some static functions and variables from a dll. When accessing the static variable after importing the dll the program crashes. Any ideas why this is happening? I am using VS2017, Windows SDK 10.0.17763.0.
library.h
struct DLLEXPORT A {
static int a;
static int get();
};
struct B {
static int b;
static int get();
};
library.cpp
int A::a = 0;
int A::get() {return a;}
int B::b = 0;
int B::get() {return b;}
library.def
LIBRARY
EXPORTS
?b@B@@2HA
?get@B@@SAHXZ
main.cpp
int main() {
int a = A::get(); // Works fine
int b = B::get(); // Works fine
A::a = 1; // Works fine
B::b = 1; // CRASH (Access violation writing location ...)
return 0;
}
I think def file entry lacks DATA
attribute so B::b
is treated as code which is typically-read only:
?b@B@@2HA DATA
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With