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 .
20 #ifndef INCLUDED_SAL_MAIN_H
21 #define INCLUDED_SAL_MAIN_H
23 #include <sal/config.h>
25 #include <sal/saldllapi.h>
26 #include <sal/types.h>
36 SAL_DLLPUBLIC
void SAL_CALL
sal_detail_initialize(int argc
, char ** argv
);
37 SAL_DLLPUBLIC
void SAL_CALL
sal_detail_deinitialize(void);
39 #if defined IOS || defined ANDROID
41 #error No code that includes this should be built for iOS or Android
45 #define SAL_MAIN_WITH_ARGS_IMPL \
46 int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \
49 sal_detail_initialize(argc, argv); \
50 ret = sal_main_with_args(argc, argv); \
51 sal_detail_deinitialize(); \
55 #define SAL_MAIN_IMPL \
56 int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \
59 sal_detail_initialize(argc, argv); \
61 sal_detail_deinitialize(); \
68 /* Definition macros for CRT entries */
74 /* Sorry but this is necessary cause HINSTANCE is a typedef that differs (C++ causes an error) */
77 # define WINAPI __stdcall
80 #if !defined(DECLARE_HANDLE)
83 # define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
87 # define DECLARE_HANDLE(name) typedef HANDLE name
89 DECLARE_HANDLE(HINSTANCE
);
94 #define SAL_WIN_WinMain \
95 int WINAPI WinMain( HINSTANCE _hinst, HINSTANCE _dummy, char* _cmdline, int _nshow ) \
97 int argc = __argc; char ** argv = __argv; \
98 (void) _hinst; (void) _dummy; (void) _cmdline; (void) _nshow; /* unused */ \
99 return main(argc, argv); \
102 #else /* ! SAL_W32 */
104 # define SAL_WIN_WinMain
106 #endif /* ! SAL_W32 */
108 /* Implementation macro */
110 #define SAL_IMPLEMENT_MAIN_WITH_ARGS(_argc_, _argv_) \
111 static int SAL_CALL sal_main_with_args (int _argc_, char ** _argv_); \
112 SAL_MAIN_WITH_ARGS_IMPL \
114 static int SAL_CALL sal_main_with_args(int _argc_, char ** _argv_)
116 #define SAL_IMPLEMENT_MAIN() \
117 static int SAL_CALL sal_main(void); \
120 static int SAL_CALL sal_main(void)
123 "How to use" Examples:
125 #include <sal/main.h>
134 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
136 DoSomethingWithArgs(argc, argv);
147 #endif // INCLUDED_SAL_MAIN_H
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */