artfuldev
artfuldev

Reputation: 1118

How to include struct in to-be-exported class in dll?

I'm trying to write a back-end in cpp, which can read binary files of quiz questions and only display the answers when asked. I want to use DLL-linking and followed the Microsoft's walkthrough at: http://msdn.microsoft.com/en-us/library/vstudio/ms235636.aspx which does not use class members. I would like to export them as well, and also include certain structs in the class.

Basically, I want to be able to declare and use objects of the class and use its member functions just by including the DLL in any further project I undertake. How do I go about this? In my following code,

#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;
    };
}

the VS 2010 compiler says "Error: Expected a declaration", at:

} solution;

and subsequent closing brackets. I'm yet to add the methods of the class.

What am I doing wrong? Also, will my code let me do what I have mentioned as my requirement?

Upvotes: 0

Views: 937

Answers (1)

john
john

Reputation: 87959

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

You have one error here, filled has been declared twice. When I fix that I can't reproduce the other errors you say you get.

Upvotes: 1

Related Questions