-
-
Notifications
You must be signed in to change notification settings - Fork 6
🚀 New Feature in NitroPascal: {$INCLUDE_HEADER} Directive #6
jarroddavis68
started this conversation in
DevLog
-
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! 💪
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment