Use only win32 functions in the launcher, no CRT functions

Reduces the size of the executables a little
This commit is contained in:
Kovid Goyal 2015-12-07 19:59:49 +05:30
parent 9a49104dac
commit ab3e048a95
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 19 additions and 15 deletions

View File

@ -575,7 +575,7 @@ class Win32Freeze(Command, WixMixIn):
dll = self.j(self.obj_dir, 'calibre-launcher.dll')
ver = '.'.join(__version__.split('.')[:2])
if self.newer(dll, objects):
cmd = [msvc.linker, '/DLL', '/VERSION:'+ver, '/OUT:'+dll,
cmd = [msvc.linker, '/DLL', '/VERSION:'+ver, '/LTCG', '/OUT:'+dll,
'/nologo', '/MACHINE:'+machine] + dlflags + objects + \
[self.embed_resources(dll),
'/LIBPATH:%s/libs'%self.python_base,
@ -605,10 +605,10 @@ class Win32Freeze(Command, WixMixIn):
self.run_builder(cmd)
exe = self.j(self.base, bname+'.exe')
lib = dll.replace('.dll', '.lib')
u32 = ['user32.lib'] if typ == 'gui' else []
u32 = ['user32.lib']
if self.newer(exe, [dest, lib, self.rc_template, __file__]):
self.info('Linking', bname)
cmd = [msvc.linker] + ['/MACHINE:'+machine,
cmd = [msvc.linker] + ['/MACHINE:'+machine, '/LTCG',
'/LIBPATH:'+self.obj_dir, '/SUBSYSTEM:'+subsys,
'/LIBPATH:%s/libs'%self.python_base, '/RELEASE',
'/OUT:'+exe] + u32 + dlflags + [self.embed_resources(exe),

View File

@ -5,24 +5,28 @@
#define UNICODE
#define WINDOWS_LEAN_AND_MEAN
#include<windows.h>
#include<stdio.h>
#include<strsafe.h>
size_t mystrlen(const wchar_t *buf) {
size_t ans = 0;
if (FAILED(StringCbLengthW(buf, 500, &ans))) return 0;
return ans;
}
static int show_error(const wchar_t *preamble, const wchar_t *msg, const int code) {
wchar_t *buf;
buf = (wchar_t*)LocalAlloc(LMEM_ZEROINIT, sizeof(wchar_t)*
(wcslen(msg) + wcslen(preamble) + 80));
(mystrlen(msg) + mystrlen(preamble) + 80));
if (!buf) {
MessageBox(NULL, preamble, NULL, MB_OK|MB_ICONERROR);
return code;
}
_snwprintf_s(buf,
LocalSize(buf) / sizeof(wchar_t), _TRUNCATE,
L"%s\r\n %s (Error Code: %d)\r\n",
preamble, msg, code);
#ifdef GUI_APP
MessageBeep(MB_ICONERROR);
if (FAILED(StringCbPrintfW(buf, LocalSize(buf), L"%s\r\n %s (Error Code: %d)\r\n", preamble, msg, code)))
MessageBox(NULL, preamble, NULL, MB_OK|MB_ICONERROR);
else
MessageBox(NULL, buf, NULL, MB_OK|MB_ICONERROR);
#else
wprintf_s(L"%s\n", buf);
#endif
LocalFree(buf);
return code;
}