1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 * This file is part of LibreOffice published API.
24 #ifndef INCLUDED_SAL_MAIN_H
25 #define INCLUDED_SAL_MAIN_H
27 #include "sal/config.h"
29 #include "sal/saldllapi.h"
30 #include "sal/types.h"
36 #if defined LIBO_INTERNAL_ONLY && defined __cplusplus
37 // Special token for sal_detail_initialize argc parameter, used by the soffice.bin process to tell
38 // SAL that it is running as part of that process (see sal/osl/unx/soffice.hxx); argv should be null
39 // in such a sal_detail_initialize call:
40 namespace sal::detail
{ constexpr int InitializeSoffice
= -1; }
43 SAL_DLLPUBLIC
void SAL_CALL
sal_detail_initialize(int argc
, char ** argv
);
44 SAL_DLLPUBLIC
void SAL_CALL
sal_detail_deinitialize(void);
46 #if !(defined IOS || defined ANDROID)
47 /* No code that uses this should be built for iOS or Android */
49 #define SAL_MAIN_WITH_ARGS_IMPL \
50 int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \
53 sal_detail_initialize(argc, argv); \
54 ret = sal_main_with_args(argc, argv); \
55 sal_detail_deinitialize(); \
59 #define SAL_MAIN_IMPL \
60 int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \
63 sal_detail_initialize(argc, argv); \
65 sal_detail_deinitialize(); \
72 /* Definition macros for CRT entries */
78 /* Sorry but this is necessary cause HINSTANCE is a typedef that differs (C++ causes an error) */
81 # define WINAPI __stdcall
84 #if !defined(DECLARE_HANDLE)
87 # define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
91 # define DECLARE_HANDLE(name) typedef HANDLE name
93 DECLARE_HANDLE(HINSTANCE
);
98 #define SAL_WIN_WinMain \
99 int WINAPI WinMain( HINSTANCE _hinst, HINSTANCE _dummy, char* _cmdline, int _nshow ) \
101 int argc = __argc; char ** argv = __argv; \
102 (void) _hinst; (void) _dummy; (void) _cmdline; (void) _nshow; /* unused */ \
103 return main(argc, argv); \
108 # define SAL_WIN_WinMain
110 #endif /* ! _WIN32 */
112 /* Implementation macro */
114 #define SAL_IMPLEMENT_MAIN_WITH_ARGS(_argc_, _argv_) \
115 static int SAL_CALL sal_main_with_args (int _argc_, char ** _argv_); \
116 SAL_MAIN_WITH_ARGS_IMPL \
118 static int SAL_CALL sal_main_with_args(int _argc_, char ** _argv_)
120 #define SAL_IMPLEMENT_MAIN() \
121 static int SAL_CALL sal_main(void); \
124 static int SAL_CALL sal_main(void)
127 "How to use" Examples:
129 #include <sal/main.h>
138 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
140 DoSomethingWithArgs(argc, argv);
151 #endif // INCLUDED_SAL_MAIN_H
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */