__declspec(dllimport)c结构:访问冲突

时间:2016-03-07 14:01:49

标签: c++ access-violation declspec

有一段时间以来,我一直试图找到解决以下问题的方案,但没有成功:

  1. 我有一个" c" dll,其中定义了以下结构:
  2. file:myDll.h

    #ifdef EXPORTS
    #define EXPORT __declspec(dllexport)
    #else
    #define EXPORT __declspec(dllimport)
    #endif
    
    EXPORT struct my_test 
    {
     unsigned char  dum0000001[2144];                                              
     int            test1[32];                                                                                                  
     unsigned char  test2[32];           
    } test;
    

    在我的c ++可执行文件中,我包含myDll.h文件并尝试修改test1和test2:

    extern "C" 
    {
    #include "myDll.h"
    }
    
    int main(int argc, char** argv)
    {
     test.test1[0] = 0; 
     test.test2[0] = 0;
    }
    

    程序正确通过:

    test.test1[0] = 0; 
    

    但是一次

    test.test2[0] = 0;
    
    到达

    ,我得到以下异常:

    First-chance exception at 0x00401028 in test.exe: 0xC0000005: Access violation writing location 0x1000c030.
    

    我真的不知道出了什么问题。也许有人可以给我一个建议?

    提前谢谢你。

0 个答案:

没有答案