将这一数量的 JSON 信息作为参数传递给 C# COM DLL 方法是否可以接受?

Is it acceptable to pass this amount of JSON information as a parameter to a C# COM DLL method?

这个问题是对这个问题 () 的扩展,建议我将 JSON 内容作为 BSTR 传递给我的 C# COM DLL。

这是传递的数据类型的示例:

{
  "BibleReading": "Bible Reading",
  "BibleReadingMain": "Bible Reading (Main)",
  "BibleReadingAux": "Bible Reading (Aux)",
  "InitialCall": "Initial Call",
  "InitialCallMain": "Initial Call (Main)",
  "InitialCallAux": "Initial Call (Aux)",
  "ReturnVisit": "Return Visit",
  "ReturnVisitMain": "Return Visit (Main)",
  "ReturnVisitAux": "Return Visit (Aux)",
  "BibleStudy": "Bible Study",
  "BibleStudyMain": "Bible Study (Main)",
  "BibleStudyAux": "Bible Study (Aux)",
  "Talk": "Talk",
  "TalkMain": "Talk (Main)",
  "TalkAux": "Talk (Aux)",
  "Assistant": "Assistant",
  "QuestionsAndAnswers": "Questions and Answers",
  "DiscussionWithVideo": "Discussion with Video",
  "SampleConversation": "Sample Conversation",
  "InitialCallVideo": "Initial Call Video",
  "ReturnVisitVideo": "Return Visit Video",
  "Video": "Video",
  "Presentations": "Prepare This Month’s Presentations",
  "SpiritualGems": "Spiritual Gems",
}

我想扩展此 JSON 以包含另外 15 个项目:

{
  "BibleReading": "Bible Reading",
  "BibleReadingMain": "Bible Reading (Main)",
  "BibleReadingAux": "Bible Reading (Aux)",
  "InitialCall": "Initial Call",
  "InitialCallMain": "Initial Call (Main)",
  "InitialCallAux": "Initial Call (Aux)",
  "ReturnVisit": "Return Visit",
  "ReturnVisitMain": "Return Visit (Main)",
  "ReturnVisitAux": "Return Visit (Aux)",
  "BibleStudy": "Bible Study",
  "BibleStudyMain": "Bible Study (Main)",
  "BibleStudyAux": "Bible Study (Aux)",
  "Talk": "Talk",
  "TalkMain": "Talk (Main)",
  "TalkAux": "Talk (Aux)",
  "Assistant": "Assistant",
  "QuestionsAndAnswers": "Questions and Answers",
  "DiscussionWithVideo": "Discussion with Video",
  "SampleConversation": "Sample Conversation",
  "InitialCallVideo": "Initial Call Video",
  "ReturnVisitVideo": "Return Visit Video",
  "Video": "Video",
  "Presentations": "Prepare This Month’s Presentations",
  "SpiritualGems": "Spiritual Gems",
  "Discuss": "Discussion",
  "DiscussDemos": "Discussion with Demonstration(s)",
  "DiscussDemosInterviews": "Discussion with Demonstration(s) and Interview(s)",
  "DiscussInterviews": "Discussion with Interview(s)",
  "DiscussVideo": "Discussion with Video",
  "DiscussVideos": "Discussion with Videos",
  "QuestionAnswer": "Questions and Answers",
  "QuestionAnswerDemos": "Questions and Answers with Demonstration(s)",
  "QuestionAnswerDemosInterviews": "Questions and Answers with Demonstration(s) and Interview(s)",
  "QuestionAnswerInterviews": "Questions and Answers with Interview(s)",
  "TalkDemos": "Talk with Demonstration(s)",
  "TalkDemosInterviews": "Talk with Demonstration(s) and Interview(s)",
  "TalkInterviews": "Talk with Interview(s)",
  "TalkVideo": "Talk with Video",
  "TalkVideos": "Talk with Videos"
}

将如此多的信息作为 BSTR 传递到我的 COM API 方法是否仍然可以接受?我假设对于可以传递多少数据存在某种限制。

感谢您的确认。

如果您不知道答案,您可以随时编写测试程序。这是验证 1 兆字节 BSTR 的一个,这比您的示例要多得多。您可以更改分配给任何您想要的金额。在某些时候它会破裂。

#include <windows.h>
#include <memory>
#include <string>
#include <iostream>
#include <comdef.h>

using namespace std;

int main(int argc, char* argv)
{
    const size_t MEGABYTEPLUSONE = 1024 * 1024 + 1;
    auto pChar = std::make_unique<OLECHAR[]>(MEGABYTEPLUSONE);
    for (size_t i = 0; i < MEGABYTEPLUSONE - 2; ++i)
        pChar[i] = (i % 26) + 65;

    pChar[MEGABYTEPLUSONE - 1] = 0;
    
    _bstr_t bstr(pChar.get());
    int len = bstr.length();
    wcout << L"Length of BSTR: " << len << endl;
    const WCHAR* const pwcStart = bstr.GetBSTR();
    for (const WCHAR* pwc = pwcStart;  pwc < pwcStart + 52; ++pwc)
        wcout << *pwc;
    wcout << endl;
    
    return 0;
}