@@ -1456,7 +1456,9 @@ pgwin32_doRegister(void)
14561456NULL ,NULL ,"RPCSS\0" ,register_username ,register_password ))== NULL )
14571457{
14581458CloseServiceHandle (hSCM );
1459- write_stderr (_ ("%s: could not register service \"%s\": error code %lu\n" ),progname ,register_servicename ,GetLastError ());
1459+ write_stderr (_ ("%s: could not register service \"%s\": error code %lu\n" ),
1460+ progname ,register_servicename ,
1461+ (unsigned long )GetLastError ());
14601462exit (1 );
14611463}
14621464CloseServiceHandle (hService );
@@ -1484,14 +1486,18 @@ pgwin32_doUnregister(void)
14841486if ((hService = OpenService (hSCM ,register_servicename ,DELETE ))== NULL )
14851487{
14861488CloseServiceHandle (hSCM );
1487- write_stderr (_ ("%s: could not open service \"%s\": error code %lu\n" ),progname ,register_servicename ,GetLastError ());
1489+ write_stderr (_ ("%s: could not open service \"%s\": error code %lu\n" ),
1490+ progname ,register_servicename ,
1491+ (unsigned long )GetLastError ());
14881492exit (1 );
14891493}
14901494if (!DeleteService (hService ))
14911495{
14921496CloseServiceHandle (hService );
14931497CloseServiceHandle (hSCM );
1494- write_stderr (_ ("%s: could not unregister service \"%s\": error code %lu\n" ),progname ,register_servicename ,GetLastError ());
1498+ write_stderr (_ ("%s: could not unregister service \"%s\": error code %lu\n" ),
1499+ progname ,register_servicename ,
1500+ (unsigned long )GetLastError ());
14951501exit (1 );
14961502}
14971503CloseServiceHandle (hService );
@@ -1627,7 +1633,9 @@ pgwin32_doRunAsService(void)
16271633
16281634if (StartServiceCtrlDispatcher (st )== 0 )
16291635{
1630- write_stderr (_ ("%s: could not start service \"%s\": error code %lu\n" ),progname ,register_servicename ,GetLastError ());
1636+ write_stderr (_ ("%s: could not start service \"%s\": error code %lu\n" ),
1637+ progname ,register_servicename ,
1638+ (unsigned long )GetLastError ());
16311639exit (1 );
16321640}
16331641}
@@ -1708,7 +1716,14 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
17081716/* Open the current token to use as a base for the restricted one */
17091717if (!OpenProcessToken (GetCurrentProcess (),TOKEN_ALL_ACCESS ,& origToken ))
17101718{
1711- write_stderr (_ ("%s: could not open process token: error code %lu\n" ),progname ,GetLastError ());
1719+ /*
1720+ * Most Windows targets make DWORD a 32-bit unsigned long. Cygwin
1721+ * x86_64, an LP64 target, makes it a 32-bit unsigned int. In code
1722+ * built for Cygwin as well as for native Windows targets, cast DWORD
1723+ * before printing.
1724+ */
1725+ write_stderr (_ ("%s: could not open process token: error code %lu\n" ),
1726+ progname , (unsigned long )GetLastError ());
17121727return 0 ;
17131728}
17141729
@@ -1721,7 +1736,8 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
17211736SECURITY_BUILTIN_DOMAIN_RID ,DOMAIN_ALIAS_RID_POWER_USERS ,0 ,0 ,0 ,0 ,0 ,
172217370 ,& dropSids [1 ].Sid ))
17231738{
1724- write_stderr (_ ("%s: could not allocate SIDs: error code %lu\n" ),progname ,GetLastError ());
1739+ write_stderr (_ ("%s: could not allocate SIDs: error code %lu\n" ),
1740+ progname , (unsigned long )GetLastError ());
17251741return 0 ;
17261742}
17271743
@@ -1740,7 +1756,8 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
17401756
17411757if (!b )
17421758{
1743- write_stderr (_ ("%s: could not create restricted token: error code %lu\n" ),progname ,GetLastError ());
1759+ write_stderr (_ ("%s: could not create restricted token: error code %lu\n" ),
1760+ progname , (unsigned long )GetLastError ());
17441761return 0 ;
17451762}
17461763
@@ -1791,7 +1808,8 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
17911808HANDLE job ;
17921809char jobname [128 ];
17931810
1794- sprintf (jobname ,"PostgreSQL_%lu" ,processInfo -> dwProcessId );
1811+ sprintf (jobname ,"PostgreSQL_%lu" ,
1812+ (unsigned long )processInfo -> dwProcessId );
17951813
17961814job = _CreateJobObject (NULL ,jobname );
17971815if (job )