This code returns the date and time.
Compatible with Borland 582#include "
minigui.ch"
function Main()
MsgInfo( Now() )
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#ifdef __BORLANDC__
#include <winsock2.h>
#include <windows.h> // For LoadLibrary/GetProcAddress
#else
#include <winsock2.h>
#include <ws2tcpip.h>
#endif
HB_FUNC( NOW )
{
// Declare ALL variables at the beginning (requirement for Borland C++ 5.82)
char buf[256];
time_t now;
struct tm *tm_info;
char time_str[64];
WSADATA wsaData;
struct hostent *he;
int wsainitialized = 0;
// Initialize variables
now = time(NULL);
tm_info = localtime(&now);
// Format time manually
if (tm_info) {
sprintf(time_str, "%02d/%02d/%04d %02d:%02d:%02d",
tm_info->tm_mday,
tm_info->tm_mon + 1,
tm_info->tm_year + 1900,
tm_info->tm_hour,
tm_info->tm_min,
tm_info->tm_sec);
} else {
strcpy(time_str, "Error getting time");
}
// Check network connection using gethostbyname (more compatible with BCC 5.82)
if (WSAStartup(MAKEWORD(2,2), &wsaData) == 0) {
wsainitialized = 1;
// Try to resolve
google.com he = gethostbyname("
www.google.com");
if (he != NULL) {
sprintf(buf, "Time: %s - Network: Connected", time_str);
} else {
sprintf(buf, "Time: %s - Network: No connection", time_str);
}
WSACleanup();
} else {
sprintf(buf, "Time: %s - Winsock: Error", time_str);
}
hb_retc(buf);
}
#pragma ENDDUMP
Regards,
Marcos Jarrin