Anti-nuisance lawsuit warning: The purpose of these notes is to remind me, Zoegond, of stuff or to help me work stuff out. They may contain mistakes.

Quick

  • ($a, $b....) = unpack("A2A7...", $packed)
  • push( array, list )

Saturday, September 24, 2011

C++ conversion

int(n) and (int)n have exactly the same effect. But the C++-style int() syntax can only be used with types which have 'simple names' (I think this means eg int but not int *).

This explains btw why the mistaken use of

p = new int(n);

instead of

p = new int[n];

doesn't cause a warning or error: the compiler thinks you want a pointer to a new int, which int has been initialised with n.

C++ references

The & operator is no different to other operators when used on a reference: in all cases, the reference is dereferenced first. So

int i;
int &r = i;
int *p;

p = &r;

gives you a pointer to i in p. &r dereferences r, to get i, before taking its address.

C++ constructor fumblings

Object a;

causes the constructor for Object to be called.

Object *pa;

does not (as I expected), but

pa = new Object;

does, which I suppose I also expected.

If it doesn't exist then the compiler gives up. Interestingly, gcc reports the constructors it does find, and I noticed that if I define no constructors at all for Object, then there is no complaint from the compiler, but if the only one I define is an unsuitable candidate, then gcc reports trying both my constructor and Object::Object(const Object&).

This is really confusing, it suggests that if no constructors are defined, then one for no arguments is created by default; but if one is defined, then a copy constructor is created by default??

Thursday, September 22, 2011

gcc gotchas and easy mistakes

(all these notes are re gcc with mingw)

The 'cc' in 'gcc' is not a way of representing 'C++'. There is a separate invocation g++ - if you use gcc instead of g++ you'll get tons of confusing errors as soon as your program incorporates anything too C++-ish, like templates.

PRECOMPILED HEADERS

I get the impression that compiling header files in order to check their syntax leaves some kind of precompiled header behind that gcc will use in future compilations, which is not what you want if you're frequently changing a header file that you're writing.

I couldn't find any .pch or .gch files lying about that might be implementing this - because I was looking in the mingw installation directories. The .gch file is written to the directory that the corresponding source file is in.

STL string notes

::c_str() returns char * equivalent.

Saturday, September 17, 2011

Windows API tabbing

To get tabbing between controls working two steps are necessary:

1. The WS_TABSTOP window style must be or'd onto all controls that are to be tab stops.

2. The TranslateMessage/DispatchMessage bit in your GetMessage loop in WinMain should have this condition put round it:

if (!IsDialogMessage(hwnd, &msg)) ...

(hwnd being the handle you got back from CreateWindow and msg being the MSG structure you gave GetMessage a pointer to - see the minimal mingw app)

This stops 'dialogue' messages (which despite their name are useful in any window that contains controls [MSDN]) from being sent to your WindowProc callback. IsDialogMessage doesn't just check the message type; if it detects a dialogue message, it also translates and dispatches it to make the tabbing happen. And that's why the message must not be dispatched to your WindowProc.

Having done all this you should find tabbing miraculously taking place between the controls.

Friday, September 16, 2011

More mingw linking

Been trying a series of progressively bolder mini-apps, starting with the mingw minimal Windows app and working upwards.

It wasn't till I tried to use GetStockObject or SystemParametersInfo that I needed to put -mwindows into the gcc command line. Probably because those are both functions from libraries (user32 and wingdi) whereas no library is given for eg CreateWindow.

Windows API basics & gotchas

When supplying a window width and height to CreateWindow, NB that this will be the size of the whole window, not just the client rectangle (the usable bit). So to make a window with enough height to accommodate a client rect with height h, you'll need h + caption height + 2 * border height (for top and bottom borders)

Get the various heights with GetSystemMetrics, using constants SM_CYCAPTION and SM_CYBORDER respectively.

mingw minimal Windows app

Article with example minimal program for showing a window and writing text to it and handling closure. To be used as a base.

Just like 1996!

Thursday, September 15, 2011

Taming Java add-on

If you install the Java browser add-on you're liable to find jqs.exe ("Java Quick Starter") consuming system resources at startup. This is because the install adds a Windows service called "Java Quick Starter". Get rid of it with the command

sc delete "JavaQuickStarterService"

NB the lack of spaces in the argument there.

Tested a page which had a Java applet the day after doing this and it worked fine.

Followers

Blog Archive