Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🚀 New Feature in NitroPascal: {$INCLUDE_HEADER} Directive #6

jarroddavis68 started this conversation in DevLog
Discussion options

When transpiling Pascal to C++, one challenge is managing platform-specific headers without creating conflicts. For example, if you want to call Windows API functions like MessageBoxW, you need <windows.h> on the C++ side. But including Windows headers globally causes conflicts with cross-platform libraries like raylib (due to functions like CloseWindow and DrawText).

The Solution: {$INCLUDE_HEADER}

Just added a simple directive that lets you specify which C/C++ headers to include directly from your Pascal code:

{$APPTYPE GUI}
{$INCLUDE_HEADER 'windows.h'}
program ProgramMessageBox;
function MessageBoxW(hWnd: Cardinal; lpText: PChar; 
 lpCaption: PChar; uType: Cardinal): Integer; 
 stdcall; external 'user32.dll';
begin
 MessageBoxW(0, 'Hello from NitroPascal!', 'Test', 0);
end.

How it works:

  • Headers are emitted at the top of the generated .h file (after pragma guards)
  • No global header pollution - only include what you need
  • Supports both system headers (<header.h>) and local headers ("header.h")
  • Works with conditional compilation for cross-platform code

Platform-Specific Headers:

{$IFDEF MSWINDOWS}
 {$INCLUDE_HEADER 'windows.h'}
{$ENDIF}
{$IFDEF POSIX}
 {$INCLUDE_HEADER 'unistd.h'}
{$ENDIF}

Clean, simple, and solves the header conflict problem elegantly! 💪

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
DevLog
Labels
devlog Regular development progress
1 participant

AltStyle によって変換されたページ (->オリジナル) /