如何转发声明导入的TLH名称空间,以便可以在结构定义中使用它?

发布于 2025-01-27 15:29:14 字数 2015 浏览 1 评论 0原文

如果我在我的cdialog标题中声明此struct

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

然后,我可以在对话框函数中使用它。示例:

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

编译并构建正常。现在,我尝试将我的struct定义移至另一个标头文件。摘要:

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

}

现在它不会编译:

错误c2653:'msatoolslibrary':不是类或名称空间名称

错误c3646:'eassigntype':未知覆盖词

错误C4430:缺少类型指定符 - 假定int。注意:C ++不支持Default-Int

msatoolslibrary由TLH文件自动创建的名称空间。问题在于,使用TLH文件的包装类也引用了我尝试添加struct的同一标头:

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

我尝试#include TLH包装器标头。没有快乐。

目前,我将struct保留在cdialog标题中。

我了解前向声明的结构等。这感觉像是一个循环参考问题,但我无法确定如何转发宣布由TLH导入构建的名称空间。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文