win32, MFC, WPF, winforms… vs Java/swing

Earliest/lowest support is win32api — a platform specific C [1] API. No counterpart in Java because JVM hides all platform-specific complexities, though the win32 JVM is written against win32api.

[1] C with Microsoft extensions, but not C++. I guess It’s a proprietary language based on ANSI-C.

win32api functions are like system calls AND standard library functions in unix. Plain old C functions, as low-level functions must be. All windows/unix applications rely on system API in C as not every app uses C++.

MFC is a c++ thin object wrapper over win32api functions, therefore platform-specific too. No counterpart in java. Borland used to offer a MFC competitor (viz OWL), but it also relies on win32api. So win32api is a choke-point, but MFC isn’t.

Similarly, winforms is also a wrapper over win32api (not over MFC). Unlike MFC, winforms was created for the dotnet virtual machine.

Someone on Stackoverflow said — Most application frameworks for Windows (at least partially) wrap the win32api. Thus, the .NET and JVM, likewise any other programming languages under Windows, are (or contain) wrapper libraries over win32api.

Winforms and WPF built on top of a virtual machine — the dotnet framework, and are (partially?) shielded from platform-specific complexities. I think these are like the swing library.

However, winforms is a dotnet wrapper over win32api, therefore faster than WPF.

———– gcc ————–

GCC also goes through the choke point viz win32api. Mingw includes
* w32api (not spelt “win..”): This is a bunch of files, a free (compatible) implementation of the MS win32api, equivalent to the Windows SDK, which provides the system-level (OS level?) interface needed by mingw-runtime. It is possible, with some modifications, to use Microsoft’s Platform-SDK instead.

* mingw-runtime (version 3.12 or higher): This is a bunch of files, the equivalent of libc on Unix which provides an interface to Microsoft’s C runtime that is shipped with Windows.

——— how many ways to write an equivalent GUI app ——-
* write a C app against win32api direclty
* write a c++ app against MFC (wrapper over win32api) — no virtual machine at all
* write a c#/c++ winforms app, running in the virtual machine
* write a c# WPF app, running in the virtual machine
* write a mingw C/C++ app, against w32api — no virtual machine at all
* write a swing app, running in the JVM

However, if you want a windows app without a GUI, then you need a console app. You can use C++ without any of these complexities. Just use STL/boost. Windows programming != GUI programming.


3 + N ways to create a shared_ptr

Background — Like any useful software component, Shared_ptr offers a clean api but has a sophisticated implementation, and many non-trivial interactions when integrated into an application — Complexity. Many ways to wrap your mind around the complexity. This is one of the best Perspectives.

The various ways to construct a shared_ptr clearly illustrates the fundamental use cases. An experienced user is probably familiar with all these use cases. These use cases are so important that you should be able to explain each constructor. Here’s what I remember.

1) pass in a raw ptr — starting a new club as the first member.
2) copier — joining an existing club.
3) pass in a weak_ptr
) pass in an auto_ptr

Note the good old auto_ptr is a club of 1. When “joining” a club you must remove the existing “owner”.

nested class having ptr to outer-class Object]java,c#,c++

Usually java is cleaner than c++ and c#. However, in this case I believe java is the Least clean.

Java “non-static nested class” feature is not “embraced” by Microsoft. All c# nested classes are static and can’t access non-static fields of the enclosing class.

C++ doesn’t support java style inner class either. See

b4 and af select() syscall

Note select() is usually used on the server-side. It allows a /single/ server thread to handle hundreds of concurrent clients.
— B4 —
open the sockets. Each socket is represented by an integer file descriptor. It can be saved in an int array. (A vector would be better, but in C the array also looks like an int pointer).

FD_SET(socketDes1, &readfds); /* add socketDes1 to the readfds */

select() function argument includes readfds — the list of existing sockets[1]. Select will test each socket.

— After —
check the set of incoming sockets and see which socket is “ready”.

FD_ISSET(socketDes1, &readfds)

If ready, Then you can either read() or recvfrom() has sample code.

[1] Actually Three independent sets of file descriptors are watched, but for now let’s focus on the first — the incoming sockets

&& and || together

[ -f unixfile ] && rm unixfile || print “unixfile was not found, or is not a regular file” — to be tested

Finally, multiple commands can be executed based on the result of command1 by incorporating braces and semi-colons:

command1 &

If the exit status of command1 is true (zero), commands 2, 3, and 4 will be performed.

See other post(s) on exit status

perl one-liner – sum across lines

A common perl-n/perl-p challenge is to sum over loops. Solution is the END{} block.

This example below is from

   ls -lAF | perl -ne ‘   next if /^d/; $sum += (split)[4]; END{ print $sum }   ‘

(I guess this sums up all the files’… sizes?)

Note you need not pre-declare $sum as a static-local (in C lingo). I guess it’s static-local by default.

colon^semi-colon^curly-braces for group statements in python

Python does use semi-colon but not curly braces in compound statements.

if condition: do_something(); do_something_else() # is same as

if condition: