2013-04-11 19 views
0

我想在cpp中写一个后端,它可以读取测验问题的二进制文件,并在问及时只显示答案。我想使用DLL链接,并遵循Microsoft的演练:http://msdn.microsoft.com/en-us/library/vstudio/ms235636.aspx,它不使用类成员。我也希望将它们导出,并在课堂中加入某些结构。如何在dll中包含待导出类中的struct?

基本上,我希望能够声明和使用类的对象,并使用它的成员函数,只需在我承担的任何其他项目中包含DLL即可。我如何去做这件事?在我下面的代码,

#ifdef CXWDLL_EXPORTS 
#define CXWAPI __declspec(dllexport) 
#else 
#define CXWAPI __declspec(dllimport) 
#endif 

#include<string> 

using namespace std; 

typedef unsigned long long UINT64 
#define SIZE 15 
#define GRIDSIZE 225 
#define MAXCLUES 50 

namespace cxw 
{ 
    class CXWAPI CXWPuzzle 
    { 
     public: 
      CXWPuzzle(); 
      virtual ~CXWPuzzle(); 
      struct Header 
      { 
       string signature; 
       string version; 
       short type; 
      } header; 
      struct Checksum 
      { 
       int header; 
       int crossie; 
       int grid; 
       int clues; 
       int solution; 
       int file; 
      } checksum; 
      struct Contents 
      { 
       struct CHeader 
       { 
        string title; 
        string author; 
        string copyright; 
        string notes; 
       } cHeader; 
       struct Grid 
       { 
        short size; 
        UINT64 grid[4]; 
        char filled[GRIDSIZE]; 
        UINT64 filled[4]; 
       } grid; 
       struct Clues 
       { 
        string across[MAXCLUES]; 
        string down[MAXCLUES]; 
       } clues; 
       struct Solution 
       { 
        char answers[GRIDSIZE]; 
        string across[MAXCLUES]; 
        string down[MAXCLUES]; 
       } solution; 
      } contents; 
    }; 
} 

的VS 2010编译器说 “错误:预期的声明”,网址为:

} solution; 

,并随后关闭支架。我还没有添加这个类的方法。

我在做什么错?另外,我的代码是否会让我按照我的要求执行所提及的操作?

+0

我不明白。您的结构只存在于头文件中。你不能只包含头文件吗? – john 2013-04-11 07:32:27

+0

我可以,但我试图将其导出为用于分发的DLL。无论如何,我仍然不明白错误,这是问题的原因。 – artfuldev 2013-04-11 07:38:31

+0

错误是因为您没有包含头文件。恐怕你将不得不分发DLL和头文件。 – john 2013-04-11 07:40:28

回答

1
struct Grid 
{ 
    short size; 
    UINT64 grid[4]; 
    char filled[225]; 
    UINT64 filled[4]; 
}; 

这里有一个错误,filled已被声明两次。当我修复,我不能重现你说的其他错误。

+0

感谢您指出。我纠正了它。不过,我收到各种其他错误,如“错误C2143:语法错误:缺少';'在'命名空间'之前“ – artfuldev 2013-04-11 07:51:02

+0

而且我仍然在指定的行中出现了”错误:预期声明“错误。 – artfuldev 2013-04-11 07:52:56

+0

@ kenshin.thebattosai这是因为你缺少一个分号'typedef unsigned long long UINT64'应该是'typedef unsigned long long UINT64;'。 – john 2013-04-11 07:56:00