Mercurial > dwindows
annotate winmain.c @ 2264:5c981407b0f3
GTK4: Add experimental support for GTK4... This is in progress and doesn't
compile yet. GTK4 support will likely be less full than GTK3 due to
architectural decisions by the GTK team. Certain features have been removed
with no replacements, such as status icon support. Additionally all of the
thread safety has been removed and everything MUST run on the main thread.
I will likely implement a similar solution to what I did on MacOS where
threads will call into the main thread to do API calls, passing the
arguments between threads. Copied from GTK3 removing all existing now dead
thread safety, all deprecated code and everything supporting earlier
versions of GTK3. GTK4 is not available in any mainstream distributions
yet... hoping to have it at least functional by the time there are any.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 29 Jan 2021 10:57:12 +0000 |
parents | 05dd5189099f |
children |
rev | line source |
---|---|
3 | 1 /* Dynamic Windows stub file to allow Win32 applications |
2 * to use the main() entry point instead of WinMain(). | |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
3 * |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
4 * (C) 2000-2012 Brian Smith <brian@dbsoft.org> |
3 | 5 */ |
6 | |
7 #include <windows.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 #include <stdio.h> | |
11 #include <process.h> | |
12 | |
49
bf42d08d72d7
Added font text extent querying code, and made it so winmain.c can be used
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
13 #ifndef NODW |
3 | 14 void Win32_Set_Instance(HINSTANCE hInstance); |
49
bf42d08d72d7
Added font text extent querying code, and made it so winmain.c can be used
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
15 #endif |
3 | 16 |
17 char **_convertargs(int *count, char *start, HINSTANCE DWInstance) | |
18 { | |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
19 char *tmp, *argstart, **argv; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
20 int loc = 0, inquotes = 0; |
3 | 21 |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
22 (*count) = 1; |
3 | 23 |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
24 tmp = start; |
3 | 25 |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
26 /* Count the number of entries */ |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
27 if(*start) |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
28 { |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
29 (*count)++; |
3 | 30 |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
31 while(*tmp) |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
32 { |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
33 if(*tmp == '"' && inquotes) |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
34 inquotes = 0; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
35 else if(*tmp == '"' && !inquotes) |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
36 inquotes = 1; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
37 else if(*tmp == ' ' && !inquotes) |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
38 { |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
39 /* Push past any white space */ |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
40 while(*(tmp+1) == ' ') |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
41 tmp++; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
42 /* If we aren't at the end of the command |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
43 * line increment the count. |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
44 */ |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
45 if(*(tmp+1)) |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
46 (*count)++; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
47 } |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
48 tmp++; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
49 } |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
50 } |
3 | 51 |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
52 argv = (char **)malloc(sizeof(char *) * ((*count)+1)); |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
53 argv[0] = malloc(260); |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
54 GetModuleFileNameA(DWInstance, argv[0], 260); |
3 | 55 |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
56 argstart = tmp = start; |
3 | 57 |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
58 if(*start) |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
59 { |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
60 loc = 1; |
3 | 61 |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
62 while(*tmp) |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
63 { |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
64 if(*tmp == '"' && inquotes) |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
65 { |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
66 *tmp = 0; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
67 inquotes = 0; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
68 } |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
69 else if(*tmp == '"' && !inquotes) |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
70 { |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
71 argstart = tmp+1; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
72 inquotes = 1; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
73 } |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
74 else if(*tmp == ' ' && !inquotes) |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
75 { |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
76 *tmp = 0; |
2164
05dd5189099f
Win: Fix some warnings reported with -W3 in Visual C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1802
diff
changeset
|
77 argv[loc] = _strdup(argstart); |
3 | 78 |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
79 /* Push past any white space */ |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
80 while(*(tmp+1) == ' ') |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
81 tmp++; |
3 | 82 |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
83 /* Move the start pointer */ |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
84 argstart = tmp+1; |
3 | 85 |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
86 /* If we aren't at the end of the command |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
87 * line increment the count. |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
88 */ |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
89 if(*(tmp+1)) |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
90 loc++; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
91 } |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
92 tmp++; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
93 } |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
94 if(*argstart) |
2164
05dd5189099f
Win: Fix some warnings reported with -W3 in Visual C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1802
diff
changeset
|
95 argv[loc] = _strdup(argstart); |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
96 } |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
97 argv[loc+1] = NULL; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
98 return argv; |
3 | 99 } |
100 | |
2164
05dd5189099f
Win: Fix some warnings reported with -W3 in Visual C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1802
diff
changeset
|
101 /* Protoype for the application entrypoint */ |
05dd5189099f
Win: Fix some warnings reported with -W3 in Visual C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1802
diff
changeset
|
102 int main(int argc, char **argv); |
05dd5189099f
Win: Fix some warnings reported with -W3 in Visual C.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1802
diff
changeset
|
103 |
3 | 104 /* Ok this is a really big hack but what the hell ;) */ |
105 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | |
106 { | |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
107 char **argv; |
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
108 int argc; |
3 | 109 |
49
bf42d08d72d7
Added font text extent querying code, and made it so winmain.c can be used
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
110 #ifndef NODW |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
111 Win32_Set_Instance(hInstance); |
49
bf42d08d72d7
Added font text extent querying code, and made it so winmain.c can be used
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
3
diff
changeset
|
112 #endif |
3 | 113 |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
114 argv = _convertargs(&argc, lpCmdLine, hInstance); |
3 | 115 |
1802
aedf5903db0a
Add DW_FCF_TEXTURED window style; relevant only for Mac port.
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1620
diff
changeset
|
116 return main(argc, argv); |
3 | 117 } |