Page 2 of 4
Re: Get real date from the Internet
Posted: Thu Sep 29, 2022 7:43 pm
by Antonio Linares
This version works fine with Borland and MSVC 2022. many thanks to Lailton help!!!
Code: Select all | Expand
#include "FiveWin.ch"
function Main()
MsgInfo( Now() )
return nil
#pragma BEGINDUMP
#ifdef _CRT_SECURE_NO_WARNINGS
#undef _CRT_SECURE_NO_WARNINGS
#endif
#define _CRT_SECURE_NO_WARNINGS 1
#include <hbapi.h>
#ifndef __BORLANDC__
#define _WIN32_WINNT 0x0502
#endif
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ws2tcpip.h>
HB_FUNC( NOW )
{
struct addrinfo hints;
struct addrinfo *result;
int sockfd;
int rv;
char buf[64];
time_t t;
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2), &wsaData);
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET; /* Allow IPv4 */
hints.ai_socktype = SOCK_STREAM; /* Stream socket */
hints.ai_flags = AI_CANONNAME; /* Return canonical name */
rv = getaddrinfo("www.google.com", "http", &hints, &result);
if (rv != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
exit(1);
}
/* Create socket */
sockfd = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (sockfd == -1) {
perror("socket");
exit(1);
}
/* Connect */
if (connect(sockfd, result->ai_addr, result->ai_addrlen) == -1) {
perror("connect");
exit(1);
}
/* Get time */
t = time(NULL);
snprintf(buf, sizeof(buf), "GET / HTTP/1.0\r\n\r\n");
send(sockfd, buf, strlen(buf), 0);
recv(sockfd, buf, sizeof(buf), 0);
snprintf(buf, sizeof( buf ), "Current time: %s", ctime(&t));
closesocket(sockfd);
freeaddrinfo(result);
hb_retc( buf );
}
Re: Get real date from the Internet
Posted: Thu Sep 29, 2022 7:55 pm
by Antonio Linares
This version removes all the warnings with MSVC 2022 and also works with Borland !!!
Code: Select all | Expand
#include "FiveWin.ch"
function Main()
MsgInfo( Now() )
return nil
#pragma BEGINDUMP
#ifdef _CRT_SECURE_NO_WARNINGS
#undef _CRT_SECURE_NO_WARNINGS
#endif
#define _CRT_SECURE_NO_WARNINGS 1
#include <hbapi.h>
#ifndef __BORLANDC__
#define _WIN32_WINNT 0x0502
#endif
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ws2tcpip.h>
HB_FUNC( NOW )
{
struct addrinfo hints;
struct addrinfo *result;
int sockfd;
int rv;
char buf[ 64 ];
time_t now = time(NULL);
char str[ 26 ];
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2), &wsaData);
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_INET; /* Allow IPv4 */
hints.ai_socktype = SOCK_STREAM; /* Stream socket */
hints.ai_flags = AI_CANONNAME; /* Return canonical name */
rv = getaddrinfo("www.google.com", "http", &hints, &result);
if (rv != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
exit(1);
}
/* Create socket */
sockfd = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (sockfd == -1) {
perror("socket");
exit(1);
}
/* Connect */
if (connect(sockfd, result->ai_addr, result->ai_addrlen) == -1) {
perror("connect");
exit(1);
}
/* Get time */
snprintf(buf, sizeof(buf), "GET / HTTP/1.0\r\n\r\n");
send(sockfd, buf, strlen(buf), 0);
recv(sockfd, buf, sizeof(buf), 0);
ctime_s( str, 26, &now );
snprintf(buf, sizeof( buf ), "Current time: %s", str );
closesocket(sockfd);
freeaddrinfo(result);
hb_retc( buf );
}
#pragma ENDDUMP
Re: Get real date from the Internet
Posted: Thu Sep 29, 2022 8:15 pm
by Horizon
Thank you very much Antonio.
Re: Get real date from the Internet
Posted: Fri Sep 30, 2022 1:07 am
by Lailton
Excellent Antonio, Good job!
Re: Get real date from the Internet
Posted: Fri Sep 30, 2022 10:17 am
by Enrico Maria Giordano
Please add this to get it working with BCC:
Code: Select all | Expand
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#ifdef __BORLANDC__
#include <winsock2.h>
#endif
#include <ws2tcpip.h>
Re: Get real date from the Internet
Posted: Fri Sep 30, 2022 10:33 am
by Antonio Linares
Dear Enrico,
that breaks with MSVC 2022:
c:\harbour\include\hbdefs.h(51): fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
using FWH\samples\buildh32.bat
Re: Get real date from the Internet
Posted: Fri Sep 30, 2022 10:39 am
by Enrico Maria Giordano
Works fine here with BCC and MSC.
Re: Get real date from the Internet
Posted: Fri Sep 30, 2022 10:39 am
by Enrico Maria Giordano
Re: Get real date from the Internet
Posted: Fri Sep 30, 2022 10:40 am
by Antonio Linares
we need to compare your buildh32.bat and ours

Re: Get real date from the Internet
Posted: Fri Sep 30, 2022 10:40 am
by Antonio Linares
#pragma BEGINDUMP
#include <hbapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#ifdef __BORLANDC__
#include <winsock2.h>
#endif
#include <ws2tcpip.h>
Re: Get real date from the Internet
Posted: Fri Sep 30, 2022 10:41 am
by Enrico Maria Giordano
No. If you add this it won't make any difference with MSC.
Re: Get real date from the Internet
Posted: Fri Sep 30, 2022 10:43 am
by Enrico Maria Giordano
Please double check. There is something wrong in your code.
Re: Get real date from the Internet
Posted: Fri Sep 30, 2022 10:51 am
by Antonio Linares
please provide us a correct buildh32.bat

Re: Get real date from the Internet
Posted: Fri Sep 30, 2022 11:00 am
by Enrico Maria Giordano
The problem is not in the compile batch. Please copy here the full source code you are using and I will test it.
Re: Get real date from the Internet
Posted: Fri Sep 30, 2022 2:26 pm
by Antonio Linares
Dear Enrico,
Code: Select all | Expand
┌────────────────────────────────────────────────────────────────────────────┐
│ FiveWin for Harbour 22.06 (VS32bits) Jun. 2022 Harbour development power │▄
│ (c) FiveTech 1993-2022 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8/10 │█
└────────────────────────────────────────────────────────────────────────────┘█
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.2.2
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'
Compiling...
Harbour 3.2.0dev (r2004201301)
Copyright (c) 1999-2020, https://harbour.github.io/
Compiling 'horizon.prg' and generating preprocessed output to 'horizon.ppo'...
Lines 5046, Functions/Procedures 1
Generating C source output to 'horizon.c'... Done.
horizon.c
c:\harbour\include\hbdefs.h(51): fatal error C1083: Cannot open include file: 'stdio.h': No such file or directory
buildh32.bat
Code: Select all | Expand
@ECHO OFF
CLS
ECHO ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
ECHO ³ FiveWin for Harbour 22.06 (VS32bits) Jun. 2022 Harbour development power ³Ü
ECHO ³ (c) FiveTech 1993-2022 for Microsoft Windows 9X/NT/200X/ME/XP/Vista/7/8/10 ³Û
ECHO ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙÛ
ECHO ÿ ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
if A%1 == A GOTO :SINTAX
if NOT EXIST %1.prg GOTO :NOEXIST
set oldpath=%path%
set oldinclude=%include%
set oldlib=%lib%
set oldlibpath=%libpath%
@set current_dir=%cd%
call "%ProgramFiles%\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
if "%FWDIR%" == "" set FWDIR=.\..
if "%HBDIR%" == "" set HBDIR=c:\harbour
ECHO Compiling...
@set fwh=%FWDIR%
@set hdir=%HBDIR%
@set hdirl=%hdir%\lib\win\msvc
@cd %current_dir%
%hdir%\bin\win\msvc\harbour %1 /n /i%fwh%\include;%hdir%\include /w /p %2 %3 > comp.log 2> warnings.log
IF ERRORLEVEL 1 GOTO COMPILEERROR
@type comp.log
@type warnings.log
cl.exe -nologo -c -O2 -W4 -wd4127 /I%hdir%\include %1.c
:ENDCOMPILE
IF EXIST %1.rc rc -r -d__FLAT__ %1
IF EXIST %1.rc IF NOT EXIST %1.res rc -r -d__FLAT__ %1
echo %1.obj > msvc.tmp
echo %fwh%\lib\FiveH32.lib %fwh%\lib\FiveHC32.lib %fwh%\lib\libmysql32.lib >> msvc.tmp
echo %fwh%\lib\hbhpdf32.lib >> msvc.tmp
echo %fwh%\lib\libhpdf32.lib >> msvc.tmp
echo %hdirl%\hbrtl.lib >> msvc.tmp
echo %hdirl%\hbvm.lib >> msvc.tmp
echo %hdirl%\gtgui.lib >> msvc.tmp
echo %hdirl%\hblang.lib >> msvc.tmp
echo %hdirl%\hbmacro.lib >> msvc.tmp
echo %hdirl%\hbrdd.lib >> msvc.tmp
echo %hdirl%\rddntx.lib >> msvc.tmp
echo %hdirl%\rddcdx.lib >> msvc.tmp
echo %hdirl%\rddfpt.lib >> msvc.tmp
echo %hdirl%\hbsix.lib >> msvc.tmp
echo %hdirl%\hbdebug.lib >> msvc.tmp
echo %hdirl%\hbcommon.lib >> msvc.tmp
echo %hdirl%\hbpp.lib >> msvc.tmp
echo %hdirl%\hbcpage.lib >> msvc.tmp
echo %hdirl%\hbwin.lib >> msvc.tmp
echo %hdirl%\hbcplr.lib >> msvc.tmp
echo %hdirl%\hbpcre.lib >> msvc.tmp
echo %hdirl%\hbct.lib >> msvc.tmp
echo %hdirl%\xhb.lib >> msvc.tmp
echo %hdirl%\png.lib >> msvc.tmp
echo %hdirl%\hbzlib.lib >> msvc.tmp
echo %hdirl%\hbziparc.lib >> msvc.tmp
echo %hdirl%\hbmzip.lib >> msvc.tmp
echo %hdirl%\minizip.lib >> msvc.tmp
echo %hdirl%\hbtip.lib >> msvc.tmp
echo %hdirl%\hbzebra.lib >> msvc.tmp
rem Uncomment these two lines to use Advantage RDD
rem echo %hdirl%\rddads.lib >> msvc.tmp
rem echo %hdirl%\ace32.lib >> msvc.tmp
echo kernel32.lib >> msvc.tmp
echo user32.lib >> msvc.tmp
echo gdi32.lib >> msvc.tmp
echo winspool.lib >> msvc.tmp
echo comctl32.lib >> msvc.tmp
echo comdlg32.lib >> msvc.tmp
echo advapi32.lib >> msvc.tmp
echo shell32.lib >> msvc.tmp
echo ole32.lib >> msvc.tmp
echo oleaut32.lib >> msvc.tmp
echo uuid.lib >> msvc.tmp
echo odbc32.lib >> msvc.tmp
echo odbccp32.lib >> msvc.tmp
echo iphlpapi.lib >> msvc.tmp
echo mpr.lib >> msvc.tmp
echo version.lib >> msvc.tmp
echo wsock32.lib >> msvc.tmp
echo msimg32.lib >> msvc.tmp
echo oledlg.lib >> msvc.tmp
echo psapi.lib >> msvc.tmp
echo gdiplus.lib >> msvc.tmp
echo winmm.lib >> msvc.tmp
echo vfw32.lib >> msvc.tmp
echo runtimeobject.lib >> msvc.tmp
echo ws2_32.lib >> msvc.tmp
echo shlwapi.lib >> msvc.tmp
echo strmiids.lib >> msvc.tmp
IF EXIST %1.res echo %1.res >> msvc.tmp
@link @msvc.tmp /nologo /subsystem:windows /NODEFAULTLIB:msvcrt
IF ERRORLEVEL 1 GOTO LINKERROR
ECHO * Application successfully built *
@set path=""
@set include=%oldinclude%
@set lib=%oldlib%
@set libpath=%oldlibpath%
@set oldpath=""
@set oldinclude=""
@set oldlib=""
@set oldlibpath=""
%1
GOTO EXIT
ECHO
rem delete temporary files
@del %1.c
@del msvc.tmp
:COMPILEERROR
@type comp.log
@type warnings.log
ECHO * Compiling errors *
GOTO EXIT
:LINKERROR
ECHO * Linking errors *
GOTO EXIT
:SINTAX
ECHO SYNTAX: Build [Program] {-- No especifiques la extensi?n PRG
ECHO {-- Don't specify .PRG extension
GOTO EXIT
:NOEXIST
ECHO The specified PRG %1 does not exist
:EXIT