Skip to content

Commit

Permalink
Fix stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ojwb committed Dec 23, 2024
1 parent 8c5b5c1 commit bea0c68
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ avenrc.o: $(srcdir)/aven.rc ../lib/icons/aven.ico
bin_PROGRAMS += wrapmsw

wrapmsw_SOURCES = wrapmsw.c
wrapmsw_LDFLAGS = -mwindows
wrapmsw_LDFLAGS = -mwindows -municode
endif

AM_CFLAGS += $(PROJ_CFLAGS)
Expand Down
16 changes: 2 additions & 14 deletions src/wrapmsw.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,12 @@
#include <windows.h>

int APIENTRY
WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR lpCmdLine, int nCmdShow)
{
DWORD len = 256;
wchar_t *buf = NULL;
PWSTR cmd_line;
(void)hInst; /* suppress compiler warning */
(void)hPrevInst; /* suppress compiler warning */
(void)lpCmdLine; /* suppress compiler warning */
while (1) {
DWORD got;
buf = realloc(buf, len * sizeof(wchar_t));
Expand All @@ -58,26 +56,16 @@ WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow)
wcscpy(e, L"OPENSSL_MODULES=");
memcpy(e + strlen("OPENSSL_MODULES="), e_val, e_len * sizeof(wchar_t));
e[strlen("OPENSSL_MODULES=") + e_len] = L'\0';
printf("setenv %ls\n", e);
_wputenv(e);
buf[got - 5] = L'_';
printf("command %ls\n", buf);
break;
}
len += len;
}
cmd_line = GetCommandLineW();
wchar_t *c = malloc(wcslen(cmd_line) + 1);
if (!c) exit(1);
wcscpy(c, cmd_line);
wchar_t *p = wcsstr(c, L".exe");
if (!p) exit(1);
p[-1] = '_';
printf("commandline %ls\n", c);
/* ShellExecute returns an HINSTANCE for some strange reason - the docs say
* the only valid operation is to convert it to "INT_PTR" (which seems to
* actually be an integer type. Marvellous. */
if ((INT_PTR)ShellExecuteW(NULL, NULL, buf, c, NULL, nCmdShow) <= 32) {
if ((INT_PTR)ShellExecuteW(NULL, NULL, buf, lpCmdLine, NULL, nCmdShow) <= 32) {
return 1;
}
return 0;
Expand Down

0 comments on commit bea0c68

Please sign in to comment.