SysInfo demo

Started by airr, December 24, 2022, 10:04:48 PM

Previous topic - Next topic

airr

It's been over 15 years (!) since I've used BCX in Windows, so if my code is a bit sloppy..... ;D

Attached is the source code to a demo that will show the following in the System Tray:


  • Computer Name
  • User Logon
  • Internal IP Address
  • External IP Address
  • Mac Address
  • System Uptime

All done in code, no using an external web-site to get the external IP or running an external program, for example (I used the DnsQuery function to retrieve the external address).

I worked on this off and on for the last day; It's interesting how a bottle of Bourbon can inspire one to code!

Anyway, let me know your thoughts when you have a chance.

And, Happy Holidays To All!!!!

AIR.

P.S.  Forgot to mention that this is using MinGW-Nuwen; make note the $COMPILER directive if you need the libs used for other compilers...

dragon57

Thank you very much for the Christmas code!

MrBcx

Armando!  Muchas Gracias y Feliz Navidad !!!

To compile using the Equation Solution Mingw distro{1} required two trivial changes:

1) add  -lole32 to the list of libraries in the $COMPILER directive

2) In Function getUptime$(), declare tmp$ as :  DIM STATIC tmp$
    This eliminates the "Returning a local variable" warning.


{1}http://www.equation.com/servlet/equation.cmd?fa=fortran

airr

Quote from: MrBcx on December 25, 2022, 06:50:24 AM

2) In Function getUptime$(), declare tmp$ as :  DIM STATIC tmp$
    This eliminates the "Returning a local variable" warning.

I blame this on the Bourbon......Thanks, MrB!

AIR.

jbk

I tried several mingw distros but I always get
undefined reference to `GetAdaptersInfo'
undefined reference to `DnsQuery_A'

MrBcx

These work for me:

NUWEN             :  g++ (GCC) 11.2.0
EQUATION SOLUTIONS:  g++ (GCC) 13.0.0 20221218 (experimental)

jbk

I tried those ditros among others but no joy

MrBcx

Quote from: jbk on December 25, 2022, 01:13:13 PM
I tried those ditros among others but no joy

I used the latest version of BCX on Windows 10 Pro running on a Dell desktop PC, if that matters.

Otherwise, I'm out of ideas for why you can't get on base.


airr

Quote from: jbk on December 25, 2022, 11:33:34 AM
I tried several mingw distros but I always get
undefined reference to `GetAdaptersInfo'
undefined reference to `DnsQuery_A'

That usually suggests a linking issue, or an include path issue.

How are you building the applet?

MrBcx

JB,

Well, I thought I was out of ideas but I tried something else and it worked too.

I was able to use Clang++ to produce a working executable too. 
I simply replaced g++ with my batch filename (cl64) in the $COMPILER directive.
$COMPILER "cl64 $FILE$ -o $FILE$.exe -Wno-write-strings -lcomctl32 -lgdi32 -liphlpapi -lws2_32 -ldnsapi -lole32 -std=c++14 -O2 -s -mwindows"

CLANG reported 8 warnings but no errors:


Clang is compiling (sysinfo) as a 64-bit CONSOLE app : 
Clang++: warning: argument unused during compilation:

sysinfo.cpp:490:39: warning: missing field 'ComboIndex' initializer [-Wmissing-field-initializers]
  IP_ADAPTER_INFO  AdapterInfo[32]= {0};
                                      ^
sysinfo.cpp:490:38: warning: suggest braces around initialization of subobject [-Wmissing-braces]
  IP_ADAPTER_INFO  AdapterInfo[32]= {0};
                                     ^
                                     {}
sysinfo.cpp:516:26: warning: missing field 'sin_port' initializer [-Wmissing-field-initializers]
  sockaddr_in  server= {0};
                         ^
sysinfo.cpp:517:23: warning: missing field 'wHighVersion' initializer [-Wmissing-field-initializers]
  WSADATA  wsaData= {0};
                      ^
sysinfo.cpp:519:11: warning: unused variable 'iResult' [-Wunused-variable]
  int     iResult= {0};
          ^
sysinfo.cpp:520:11: warning: unused variable 'mac_address' [-Wunused-variable]
  char    mac_address[BCXSTRSIZE]= {0};
          ^
sysinfo.cpp:577:22: warning: missing field 's_b2' initializer [-Wmissing-field-initializers]
  IN_ADDR  ipaddr= {0};
                     ^
sysinfo.cpp:577:21: warning: suggest braces around initialization of subobject [-Wmissing-braces]
  IN_ADDR  ipaddr= {0};
                    ^
                    {}
8 warnings generated.
3 seconds


The resulting executable from Clang++ runs fine.

airr

#10
That's odd, does Clang do some sort of pre-optimization of the source before or while compiling?

This is what the emitted code for declaring AdapterInfo looks like on my machine:


  static   IP_ADAPTER_INFO  AdapterInfo[32];
  memset(&AdapterInfo,0,sizeof(AdapterInfo));


Even passing -Wall, I don't get those warnings (I do see a bunch of #PRAGMA COMMENT warnings, which I think is expected).

EDIT:  I wonder if this may be why I'm not seeing those:  "Version 6.1.6 (2010/08/02)  Compiled with Pelles C"

I downloaded the installer from the website....

airr

Okay, after downloading Version 7.9.7, I see what you're seeing, MrB, although MinGW doesn't throw a warning for the way the variables are initialized.

I did make a couple of changes to the getActiveIP$ function:


  • Removed iResult and mac_address variables, which weren't used
  • Changed "if socket_desc = -1 then" to "if socket_desc < 0 then", to address a warning about signed-ness


MrBcx

Quote from: airr on December 25, 2022, 07:46:47 PM
Okay, after downloading Version 7.9.7, I see what you're seeing, MrB, although MinGW doesn't throw a warning for the way the variables are initialized.

I did make a couple of changes to the getActiveIP$ function:


  • Removed iResult and mac_address variables, which weren't used
  • Changed "if socket_desc = -1 then" to "if socket_desc < 0 then", to address a warning about signed-ness

Chasing down warnings can turn into a full time job, if you let it.  :-)


jbk

hi MrBcx and airr
I think that there's a problem when trying to compile using bed, I can successfully compile the program from the command line however nothing appears when run but task manager shows that it's running

MrBcx

#14
Quote from: jbk on December 26, 2022, 04:20:10 AM
hi MrBcx and airr
I think that there's a problem when trying to compile using bed, I can successfully compile the program from the command line however nothing appears when run but task manager shows that it's running

Hi JB,

BED uses its own batch files. But it is still easy to build sysinfo in BED.

1) Comment or remove the $COMPILER directive from sysinfo.bas

2) Add the following libraries to \BED\Bat\GW32.bat, GW64.bat, and optionally to
    GC32.bat,  GC64.bat,  GD32.bat and GD64.bat, should you need them in future projects.
                                  -liphlpapi    -lws2_32    -ldnsapi

This worked for me, it should work for you too.

PS:  The workaround would be MUCH simpler, if GCC had a #pragma statement for
       linking libraries
like most other compiler systems, but sadly it doesn't.