LibreOffice: sal/main.h Source File

LibreOffice LibreOffice 25.8 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#ifdef __cplusplus
33extern "C" {
34#endif
35
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:
40namespace sal::detail { constexpr int InitializeSoffice = -1; }
41#endif
42
43 SAL_DLLPUBLIC void SAL_CALL sal_detail_initialize(int argc, char ** argv);
44 SAL_DLLPUBLIC void SAL_CALL sal_detail_deinitialize(void);
45
46#if !(defined IOS || defined ANDROID)
47 /* No code that uses this should be built for iOS or Android */
48
49#define SAL_MAIN_WITH_ARGS_IMPL \
50int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \
51{ \
52 int ret; \
53 sal_detail_initialize(argc, argv); \
54 ret = sal_main_with_args(argc, argv); \
55 sal_detail_deinitialize(); \
56 return ret; \
57}
58
59#define SAL_MAIN_IMPL \
60int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \
61{ \
62 int ret; \
63 sal_detail_initialize(argc, argv); \
64 ret = sal_main(); \
65 sal_detail_deinitialize(); \
66 return ret; \
67}
68
69#endif
70
71
72/* Definition macros for CRT entries */
73
74#ifdef _WIN32
75
76#include <stdlib.h>
77
78/* Sorry but this is necessary cause HINSTANCE is a typedef that differs (C++ causes an error) */
79
80#ifndef WINAPI
81# define WINAPI __stdcall
82#endif
83
84#if !defined(DECLARE_HANDLE)
85# ifdef STRICT
86 typedef void *HANDLE;
87# define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
88# else
89 typedef void *PVOID;
90 typedef PVOID HANDLE;
91# define DECLARE_HANDLE(name) typedef HANDLE name
92# endif
93DECLARE_HANDLE(HINSTANCE);
94#endif
95
96
97
98#define SAL_WIN_WinMain \
99int WINAPI WinMain( HINSTANCE _hinst, HINSTANCE _dummy, char* _cmdline, int _nshow ) \
100{ \
101 int argc = __argc; char ** argv = __argv; \
102 (void) _hinst; (void) _dummy; (void) _cmdline; (void) _nshow; /* unused */ \
103 return main(argc, argv); \
104}
105
106#else /* ! _WIN32 */
107
108# define SAL_WIN_WinMain
109
110#endif /* ! _WIN32 */
111
112/* Implementation macro */
113
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 \
117 SAL_WIN_WinMain \
118 static int SAL_CALL sal_main_with_args(int _argc_, char ** _argv_)
119
120#define SAL_IMPLEMENT_MAIN() \
121 static int SAL_CALL sal_main(void); \
122 SAL_MAIN_IMPL \
123 SAL_WIN_WinMain \
124 static int SAL_CALL sal_main(void)
125
126/*
127 "How to use" Examples:
128
129 #include <sal/main.h>
130
131 SAL_IMPLEMENT_MAIN()
132 {
133 DoSomething();
134
135 return 0;
136 }
137
138 SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
139 {
140 DoSomethingWithArgs(argc, argv);
141
142 return 0;
143 }
144
145*/
146
147#ifdef __cplusplus
148} /* extern "C" */
149#endif
150
151#endif // INCLUDED_SAL_MAIN_H
152
153/* 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