AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
4 #ifndef INCLUDED_SAL_MAIN_H
5 #define INCLUDED_SAL_MAIN_H
6 
7 #include "sal/config.h"
8 
9 #include "sal/saldllapi.h"
10 #include "sal/types.h"
11 
12 #if defined AIX
13 #include <unistd.h>
14 #endif
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 #if defined LIBO_INTERNAL_ONLY && defined __cplusplus
21 // Special token for sal_detail_initialize argc parameter, used by the soffice.bin process to tell
22 // SAL that it is running as part of that process (see sal/osl/unx/soffice.hxx); argv should be null
23 // in such a sal_detail_initialize call:
24 namespace sal::detail { constexpr int InitializeSoffice = -1; }
25 #endif
26 
27 SAL_DLLPUBLIC void SAL_CALL sal_detail_initialize(int argc, char ** argv);
28 SAL_DLLPUBLIC void SAL_CALL sal_detail_deinitialize(void);
29 
30 #if !(defined IOS || defined ANDROID)
31  /* No code that uses this should be built for iOS or Android */
32 
33 #define SAL_MAIN_WITH_ARGS_IMPL \
34 int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \
35 { \
36  int ret; \
37  sal_detail_initialize(argc, argv); \
38  ret = sal_main_with_args(argc, argv); \
39  sal_detail_deinitialize(); \
40  return ret; \
41 }
42 
43 #define SAL_MAIN_IMPL \
44 int SAL_DLLPUBLIC_EXPORT SAL_CALL main(int argc, char ** argv) \
45 { \
46  int ret; \
47  sal_detail_initialize(argc, argv); \
48  ret = sal_main(); \
49  sal_detail_deinitialize(); \
50  return ret; \
51 }
52 
53 #endif
54 
55 
56 /* Definition macros for CRT entries */
57 
58 #ifdef _WIN32
59 
60 #include <stdlib.h>
61 
62 /* Sorry but this is necessary cause HINSTANCE is a typedef that differs (C++ causes an error) */
63 
64 #ifndef WINAPI
65 # define WINAPI __stdcall
66 #endif
67 
68 #if !defined(DECLARE_HANDLE)
69 # ifdef STRICT
70  typedef void *HANDLE;
71 # define DECLARE_HANDLE(name) struct name##__ { int unused; }; typedef struct name##__ *name
72 # else
73  typedef void *PVOID;
74  typedef PVOID HANDLE;
75 # define DECLARE_HANDLE(name) typedef HANDLE name
76 # endif
77 DECLARE_HANDLE(HINSTANCE);
78 #endif
79 
80 
81 
82 #define SAL_WIN_WinMain \
83 int WINAPI WinMain( HINSTANCE _hinst, HINSTANCE _dummy, char* _cmdline, int _nshow ) \
84 { \
85  int argc = __argc; char ** argv = __argv; \
86  (void) _hinst; (void) _dummy; (void) _cmdline; (void) _nshow; /* unused */ \
87  return main(argc, argv); \
88 }
89 
90 #else /* ! _WIN32 */
91 
92 # define SAL_WIN_WinMain
93 
94 #endif /* ! _WIN32 */
95 
96 /* Implementation macro */
97 
98 #define SAL_IMPLEMENT_MAIN_WITH_ARGS(_argc_, _argv_) \
99  static int SAL_CALL sal_main_with_args (int _argc_, char ** _argv_); \
100  SAL_MAIN_WITH_ARGS_IMPL \
101  SAL_WIN_WinMain \
102  static int SAL_CALL sal_main_with_args(int _argc_, char ** _argv_)
103 
104 #define SAL_IMPLEMENT_MAIN() \
105  static int SAL_CALL sal_main(void); \
106  SAL_MAIN_IMPL \
107  SAL_WIN_WinMain \
108  static int SAL_CALL sal_main(void)
109 
110 /*
111  "How to use" Examples:
112 
113  #include <sal/main.h>
114 
115  SAL_IMPLEMENT_MAIN()
116  {
117  DoSomething();
118 
119  return 0;
120  }
121 
122  SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv)
123  {
124  DoSomethingWithArgs(argc, argv);
125 
126  return 0;
127  }
128 
129 */
130 
131 #ifdef __cplusplus
132 } /* extern "C" */
133 #endif
134 
135 #endif // INCLUDED_SAL_MAIN_H
136 
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC void sal_detail_deinitialize(void)
SAL_DLLPUBLIC void sal_detail_initialize(int argc, char **argv)
#define SAL_DLLPUBLIC
Definition: saldllapi.h:14