0
votes

Is it possible to export a struct of an wrapped class without wrapping it (struct only contains enums and primitives)? Let say my wrapper looks like this:

WorkerWrapper.h

#ifdef TESTEXPORTDLL_EXPORTS
#define TESTEXPORTDLL_API __declspec(dllexport)
#else
#define TESTEXPORTDLL_API __declspec(dllimport)
#endif

class Worker;
struct JobTypeInfo;

template class TESTEXPORTDLL_API std::unique_ptr<Worker>;

class TESTEXPORTDLL_API WorkerWrapper {
private:
    std::unique_ptr<Worker> fWorker;

public:
  WorkerWrapper();
  ~WorkerWrapper();
  WorkerWrapper(WorkerWrapper&& aThat);
  WorkerWrapper& operator= (WorkerWrapper&& aThat);

  void DoJob(JobTypeInfo aTypeInfo);
};

The WorkerWrapper.cpp is regulary implemented handling unique_ptr by using std::move and it is not the reason of my question. The Worker class is forward declarated in WorkerWrapper and contains a struct which I want to export.

Worker.h

struct JobTypeInfo
{
    typedef enum
    {
        DoThis,
        DoThat,
        DoNothing
    } CalcType;
    CalcType sCalcType;

    //... primitives
};

class Worker
{
public:
    void DoJob(JobTypeInfo aTypeInfo);
};

What can I do here?

Thanks in advance.

2

2 Answers

4
votes

If there are no contained methods, exporting a struct does nothing -- exporting a class means exporting all of its methods and its typeinfo if it contains a vtable.

Your export of WorkerWrapper in this way is also problematic, because std::unique_ptr<Worker> is not exported. It will work if you do not have any inline methods (including default implementations), but MSVC will give you a warning C4251.

Try to pass an interface pointer only. Virtual destructors are okay, as they call the proper deallocator.

0
votes

I solved it simply by extracting the struct into its own header file.