What does the macro ProjectName_API do?

I see this macro in class declaration, for example:

class SURVIVALGAME_API USCarryObjectComponent : public USpringArmComponent

as in the sample game project. It says this macro cannot be found in the source file. I wonder where this macro exactly is and what does it mean? A similar macro I usually see is Engine_API, and I can’t find the definition of this one too.

Thanks.

wcl1993

See this page

From what I know, it basically exports functions that are marked with the macro (or all functions in class if class is marked with this macro) so they can be used outside of the module they were declared in. If you know, that you won’t use given class outside of the module you develop it in (for example if you write customizations for details panels in editor), you don’t need to export that functionality to other modules.

It increases performance a bit, but I’m not sure if just a compilation/building will be faster, or if a game will run faster too.

2 Likes

Thanks! I looked through it, and it doesn’t tell where it is defined. I am sorry but I am really curious about that. Could you give more explanations? Thanks!

wcl1993

I don’t know where it’s located. I believe it’s hidden under one of UE4’s macros in one of generated files in your project.

Why do you need to know where it is defined if I may ask?

strongly suspect it’s defined in the *.generated.h headers produced by the Unreal Header Tool

I am simply curious about this macro since I have seen it in all c++ projects and I think knowing more about it might help me understand the engine better.

Cheers,
wcl1993

That is not in *.generated.h, that’s for sure , i have searched entire solution for declaration but without successes.

The definition is probably passed from unreal build tool to the compiler via the command line.

It pastes extern to make entire class or invidual functions to be callable outside of module dll. It is macro so extern can be skipped on monolith (exe only) build where extern is not needed only create security hole.

use something like the following code in .h file On the next line of #pragma once:

	#define PI 3.1415926
	#define MAX(a,b) (a)>(b) ? (a) :(b)
	
	
	//define 2 Assist Macro
	#define   PRINT_MACRO_HELPER(x)   #x  
	#define   PRINT_MACRO(x)   #x"="PRINT_MACRO_HELPER(x)  
	
	//print Macro content
	//examples:
	#pragma message(PRINT_MACRO(PI))
	#pragma message(PRINT_MACRO(PI2))
	#pragma message(PRINT_MACRO(MAX(a,b)))
	#pragma message(PRINT_MACRO(MAX(x,y)))
	//print ProjectName_API Macro
	#pragma message(PRINT_MACRO(ProjectName_API))
	
	click build and look at the output window