Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do you create global variables in a C++ plugin?

Engaged ,
Oct 26, 2025 Oct 26, 2025

How do you create global variables in a C++ plugin?

TOPICS
SDK
322
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 18, 2025 Nov 18, 2025

Multiple ways I suppose. I am stating generically as I don't know your specific context/usecase

Staying within the InDesign SDK constructs you can use the following

  • Add non persistent interface to boss classes like session, workspace. Set and get them as per your needs
  • Using IBlackBoxCommands which can store key/value pairs

Outside InDesign SDK

  • Something like a singleton class which is set/get as needed and accessible in any code file

-Manan

Translate
Community Expert ,
Nov 18, 2025 Nov 18, 2025

Multiple ways I suppose. I am stating generically as I don't know your specific context/usecase

Staying within the InDesign SDK constructs you can use the following

  • Add non persistent interface to boss classes like session, workspace. Set and get them as per your needs
  • Using IBlackBoxCommands which can store key/value pairs

Outside InDesign SDK

  • Something like a singleton class which is set/get as needed and accessible in any code file

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 03, 2025 Dec 03, 2025

>>Add non persistent interface to boss classes like session, workspace. Set and get them as per your needs

// .fr
resource ImplementationAlias(1)
{
	{
		kMyIntDataImpl, kIntDataImpl,
	}
};
resource ClassDescriptionTable(kMyClassDescriptionTableResourceID)
{{{
	AddIn
	{
		kSessionBoss,
		kInvalidClass,
		{
			IID_IMYINTDATA, kMyIntDataImpl,
		}
	},
}}};

// .cpp
InterfacePtr<IIntData> iIntData(::GetExecutionContextSession(), IID_IMYINTDATA);

That's how it went, and this method worked out well.

 

Adding class variables also requires a header, but it worked out fine.
For example, I've added class variables to the script provider and am using them.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 03, 2025 Dec 03, 2025
LATEST

Great news. Look into the IBlackBoxCommands as well. The good thing about this is that you are saved the work to add things in the fr. You can straightaway use them in the cpp files

-Manan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines