tdd*_*tdd 5 c++ dll visual-c++
我正在使用def文件从dll导出一些静态函数和变量.导入dll后访问静态变量时,程序崩溃.任何想法为什么会这样?我使用的是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();
};
Run Code Online (Sandbox Code Playgroud)
library.cpp
int A::a = 0;
int A::get() {return a;}
int B::b = 0;
int B::get() {return b;}
Run Code Online (Sandbox Code Playgroud)
library.def
LIBRARY
EXPORTS
?b@B@@2HA
?get@B@@SAHXZ
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
112 次 |
| 最近记录: |