LibreOffice: sal/main.h Source File

LibreOffice LibreOffice 7.5 SDK C/C++ API Reference

Loading...
Searching...
No Matches
main.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20/*
21 * This file is part of LibreOffice published API.
22 */
23
24#ifndef INCLUDED_SAL_MAIN_H
25#define INCLUDED_SAL_MAIN_H
26
27#include "sal/config.h"
28
29#include "sal/saldllapi.h"
30#include "sal/types.h"
31
32#if defined AIX
33#include <unistd.h>
34#endif
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40#if defined LIBO_INTERNAL_ONLY && defined __cplusplus
41// Special token for sal_detail_initialize argc parameter, used by the soffice.bin process to tell
42// SAL that it is running as part of that process (see sal/osl/unx/soffice.hxx); argv should be null
43// in such a sal_detail_initialize call:
44namespace sal::detail { constexpr int InitializeSoffice = -1; }
45#endif
46
47 SAL_DLLPUBLIC void SAL_CALL sal_detail_initialize(int argc, char ** argv);
48 SAL_DLLPUBLIC void SAL_CALL sal_detail_deinitialize(void);
49
50#if !(defined IOS || defined ANDROID)
51 /* No code that uses this should be built for iOS or Android */
52
53#define SAL_MAIN_WITH_ARGS_IMPL \
54int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \
55{ \
56 int ret; \
57 sal_detail_initialize(argc, argv); \
58 ret = sal_main_with_args(argc, argv); \
59 sal_detail_deinitialize(); \
60 return ret; \
61}
62
63#define SAL_MAIN_IMPL \
64int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \
65{ \
66 int ret; \
67 sal_detail_initialize(argc, argv); \
68 ret = sal_main(); \
69 sal_detail_deinitialize(); \
70 return ret; \
71}
72
73#endif
74
75
76/* Definition macros for CRT entries */
77
78#ifdef _WIN32
79
80#include <stdlib.h>
81
82/* Sorry but this is necessary cause HINSTANCE is a typedef that differs (C++ causes an error) */
83
84#ifndef WINAPI
85# define WINAPI __stdcall
86#endif
87
88#if !defined(DECLARE_HANDLE)
89# ifdef STRICT
90 typedef void *HANDLE;
91# define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
92# else
93 typedef void *PVOID;
94 typedef PVOID HANDLE;
95# define DECLARE_HANDLE(name) typedef HANDLE name
96# endif
97DECLARE_HANDLE(HINSTANCE);
98#endif
99
100
101
102#define SAL_WIN_WinMain \
103int WINAPI WinMain( HINSTANCE _hinst, HINSTANCE _dummy, char* _cmdline, int _nshow ) \
104{ \
105 int argc = __argc; char ** argv = __argv; \
106 (void) _hinst; (void) _dummy; (void) _cmdline; (void) _nshow; /* unused */ \
107 return main(argc, argv); \
108}
109
110#else /* ! _WIN32 */
111
112# define SAL_WIN_WinMain
113
114#endif /* ! _WIN32 */
115
116/* Implementation macro */
117
118#define SAL_IMPLEMENT_MAIN_WITH_ARGS(_argc_, _argv_) \
119 static int SAL_CALL sal_main_with_args (int _argc_, char ** _argv_); \
120 SAL_MAIN_WITH_ARGS_IMPL \
121 SAL_WIN_WinMain \
122 static int SAL_CALL sal_main_with_args(int _argc_, char ** _argv_)
123
124#define SAL_IMPLEMENT_MAIN() \
125 static int SAL_CALL sal_main(void); \
126 SAL_MAIN_IMPL \
127 SAL_WIN_WinMain \
128 static int SAL_CALL sal_main(void)
129
130/*
131 "How to use" Examples:
132
133 #include <sal/main.h>
134
135 SAL_IMPLEMENT_MAIN()
136 {
137 DoSomething();
138
139 return 0;
140 }
141
142 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
143 {
144 DoSomethingWithArgs(argc, argv);
145
146 return 0;
147 }
148
149*/
150
151#ifdef __cplusplus
152} /* extern "C" */
153#endif
154
155#endif // INCLUDED_SAL_MAIN_H
156
157/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
saldllapi.h
SAL_DLLPUBLIC
#define SAL_DLLPUBLIC
Definition: saldllapi.h:34
sal_detail_deinitialize
SAL_DLLPUBLIC void sal_detail_deinitialize(void)
sal_detail_initialize
SAL_DLLPUBLIC void sal_detail_initialize(int argc, char **argv)
config.h
types.h