0

If I declare this struct in my CDialog header:

struct S_MWB_AUTO_ASSIGN_SETTING
{
    bool bIncludeReferencedWeeks{};
    bool bAvoidConflicts{};
    MSAToolsLibrary::AssignmentType eAssignType;
    CString strStartingName;
    void (CChristianLifeMinistryEntry::* pfnSetAssignName)(CString);
};

Then, I can use it in the dialog functions. Example:

std::vector<S_MWB_AUTO_ASSIGN_SETTING> vecAutoAssignSettings =
{
    {true, true, MSAToolsLibrary::AssignmentType_Host, L"Name 1", &CChristianLifeMinistryEntry::SetVideoHost },
    {true, true, MSAToolsLibrary::AssignmentType_CoHost, L"Name 2", &CChristianLifeMinistryEntry::SetVideoCohost },
};

This compiles and builds fine. Now, I tried to move my struct definition into another header file. Snippet:

namespace CChristianLifeMinistryDefines
{
    struct S_MWB_AUTO_ASSIGN_SETTING
    {
        bool bIncludeReferencedWeeks{};
        bool bAvoidConflicts{};
        MSAToolsLibrary::AssignmentType eAssignType;
        CString strStartingName;
        void (CChristianLifeMinistryEntry::* pfnSetAssignName)(CString);
    };

}

Now it will not compile:

error C2653: 'MSAToolsLibrary': is not a class or namespace name

error C3646: 'eAssignType': unknown override specifier

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

The MSAToolsLibrary namespace is created automatically by a TLH file. The problem is that the wrapper class that uses the TLH file also references the same header I am trying to add the struct too:

#pragma once
#include "ChristianLifeMinistryDefines.h"

#include <map>
#include <vector>

#ifdef _WIN64
#import "..\\..\\MSAToolsLibrary\\MSAToolsLibrary\\bin\\x64\\Release\\MSAToolsLibrary.tlb" raw_interfaces_only named_guids
#else
#import "..\\..\\MSAToolsLibrary\\MSAToolsLibrary\\bin\\x86\\Release\\MSAToolsLibrary.tlb" raw_interfaces_only named_guids
#endif

using namespace CChristianLifeMinistryDefines;

I tried to #include the TLH wrapper header. No joy.

At the moment I have kept the struct in the CDialog header.

I understand about forward declaring structures etc. This feels like a circular reference issue but I cant establish how to forward declare the namespace that is built by the TLH import.

user17732522
  • 53,019
  • 2
  • 56
  • 105
Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
  • The structure must be defined after the `#import` directive that introduces `MSAToolsLibrary`. E.g. by putting both in the same header, one after the other; or setting up a header that does `#import` first, and includes the header with the structure's definition second. – Igor Tandetnik May 08 '22 at 17:18
  • @IgorTandetnik Well, I tried moving the `#include` of the `Christian...` header to after the import else / if and it still caused the compile error. – Andrew Truckle May 08 '22 at 17:20
  • This means that somewhere you include the structure but not the `#import` directive. – Igor Tandetnik May 08 '22 at 17:21
  • @IgorTandetnik But if I add the `#include msatools.h` to the top of the `christian` header, so that the import is done first, then the `msatools` header which includes the christian header after the import says that the christiahn namespace is not valid???? – Andrew Truckle May 08 '22 at 17:31
  • @IgorTandetnik If I add the import e;se / if in both headers, then it compiles. – Andrew Truckle May 08 '22 at 17:34
  • 1
    You don't need to forward-declare a namespace. You need to forward-declare `AssignmentType` in that namespace. Which I'm guessing is an enum, and there's no mechanism in C++ to forward-declare untyped enums. If you can't arrange for the structure to be defined after `#import`, one possibility is to make `S_MWB_AUTO_ASSIGN_SETTING::eAssignType` a plain `int`, with the understanding that its values would come from `MSAToolsLibrary::AssignmentType`. – Igor Tandetnik May 08 '22 at 17:45
  • @IgorTandetnik OK, I understand. I like it staying as an `enum` because of intellisense. Thanks for the explanation. I will leave the structure define in the dialog header. – Andrew Truckle May 08 '22 at 17:47
  • You can forward-declare a typed `enum` or a `enum class` if that is preferrable: https://stackoverflow.com/questions/71416/forward-declaring-an-enum-in-c – user17732522 May 08 '22 at 17:51
  • 1
    @user17732522 It probably won't help. I'm pretty sure `#import` directive manufactures plain old untyped and unscoped enums. – Igor Tandetnik May 08 '22 at 17:59
  • @IgorTandetnik Correct, they are untyped. It is why I have a barrage of code analysis warnings about those enaumes wherever I use them. – Andrew Truckle May 08 '22 at 18:01
  • @IgorTandetnik OK, nevermind then. That's why I deleted my original comment anyway. I don't know about these MSVC-specific features. Sorry for the noise! – user17732522 May 08 '22 at 18:01

0 Answers0