You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
main(): Take the user's main() function as a function pointer.
This allows us to move the UTF-16 → UTF-8 conversion into the DLL for
a dynamic build, and keep the actual definitions of the entry points so
small that they don't even need system headers, making them easily
expandable for other types of entry points.
Copy file name to clipboardExpand all lines: README.md
+15-3
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,10 @@ The following functions are wrapped in this way:
50
50
* GetFileVersionInfoEx()
51
51
52
52
### Building ###
53
-
Replace all inclusions of `windows.h` or `stdio.h` with `win32_utf8.h` in your existing native Win32 code. The rest differs between static and dynamic linking:
53
+
* Replace all inclusions of `windows.h` or `stdio.h` with `win32_utf8.h` in your existing native Win32 code.
54
+
* If your program is a standalone executable and not a (static or dynamic) library, see the [Custom `main()` function](#custom-main-function) section for details on how to get UTF-8 command-line parameters in `argv`.
55
+
56
+
The rest differs between static and dynamic linking:
54
57
55
58
#### Static linking ####
56
59
Make sure that `win32_utf8_build_static.c` is compiled as part of your sources.
@@ -63,9 +66,18 @@ For dynamic linking or other more special use cases, a project file for Visual C
63
66
To generate a DLL in a different compiler, simply compile `win32_utf8_build_dynamic.c`.
64
67
65
68
#### Custom `main()` function ####
66
-
When including `win32_utf8.h` (or the smaller `src/entry.h`), a later definition of `main()` is renamed to `win32_utf8_main()`. That function will in turn be called by win32_utf8's own `main()` function, defined in `src/entry.c`, which retrieves the Unicode command line, converts it to UTF-8, and transparently passes that to your actual `main()` function using the classic `argc` / `argv` scheme.
69
+
Together with win32_utf8's entry point wrappers, changing the name and parameter list of your `main()` function to
70
+
71
+
```c
72
+
int __cdecl win32_utf8_main(int argc, const char *argv[])
73
+
```
74
+
75
+
guarantees that all strings in `argv` will be in UTF-8. `src/entry.h`, which is included as part of `win32_utf8.h`, redefines `main` as `win32_utf8_main` and thereby eliminates the need for another preprocessor conditional block around `main()` in cross-platform console applications.
76
+
77
+
You then need to provide the *actual* entry point by compiling the correct `entry_*.c` file from this repository as part of your sources:
78
+
* `entry_main.c` if your program runs in the console subsystem.
67
79
68
-
When linking win32_utf8 statically as described above, `src/entry.c` is automatically compiled in as part of `win32_utf8_build_static.c`, so this should cause no further problems. For dynamic linking, however, `src/entry.c` has to be added to every target project's own sources as well.
80
+
It can either be a separate translation unit, or `#include`d into an existing one. Also, make sure that your compiler's subsystem settings match the entry point file.
69
81
70
82
#### Compiler support ####
71
83
**Visual C++** and **MinGW** compile the code just fine. Cygwin is not supported, as [it lacks Unicode versions of certain C runtime functions because they're not part of the POSIX standard](https://www.cygwin.com/ml/cygwin/2006-03/msg00539.html). (Of course, using MinGW's `gcc` through Cygwin works just fine.)
0 commit comments