Showing archive results for 2004

Nov 11, 2004
Post comments count0
Post likes count0

Advantages of knowing your x86 machine code

Raymond Chen

Next time you find yourself debugging in assembly language (which for some of us is the only way we debug), here are some machine code tricks you may wish to try out: 90 This is the single-byte NOP opcode. If you want to patch out code and don't want to think about it, just whack some 90's over it. To undo it, you have to patch the or...

Code
Nov 10, 2004
Post comments count0
Post likes count0

Why does Windows not recognize my USB device as the same device if I plug it into a different port?

Raymond Chen

You may have noticed that if you take a USB device and plug it into your computer, Windows recognizes it and configures it. Then if you unplug it and replug it into a different USB port, Windows gets a bout of amnesia and thinks that it's a completely different device instead of using the settings that applied when you plugged it in last time. Why ...

Other
Nov 9, 2004
Post comments count0
Post likes count0

A history of GlobalLock, part 4: A peek at the implementation

Raymond Chen

On one of our internal discussion mailing lists, someone posted the following question: We have some code that was using DragQueryFile to extract file paths. The prototype for DragQueryFile appears as follows: UINT DragQueryFile( HDROP hDrop, UINT iFile, LPTSTR lpszFile, UINT cch ); In the code we have, instead of passing an ...

History
Nov 8, 2004
Post comments count0
Post likes count0

A history of GlobalLock, part 3: Transitioning to Win32

Raymond Chen

Now that you know how the 16-bit memory manager handled the global heap, it's time to see how this got transitioned to the new 32-bit world. The function continued to emulate all its previous moveability rules, but the return value of was no longer a selector since Win32 used the processor in "flat mode". This means that the old trick of ca...

History
Nov 8, 2004
Post comments count0
Post likes count0

Ein hundert Dinge, die in den Vereinigten Staaten besser bleiben

Raymond Chen

I think it is a trait common to many people that they are fascinated by how their country is viewed by others. The leftist Die Tageszeitung from Germany reacted to the result of the most recent U.S. presidential election with their list of one hundred things that are still better in the United States. Those who cannot read German can use a tra...

Non-Computer
Nov 5, 2004
Post comments count0
Post likes count0

A history of GlobalLock, part 2: Selectors

Raymond Chen

With the advent of the 80286, Windows could take advantage of that processor's "protected mode". processor. There was still no virtual memory, but you did have memory protection. Global handles turned into "descriptors", more commonly known as "selectors". Architectural note: The 80286 did have support for both a "local descriptor table" and a ...

History
Nov 4, 2004
Post comments count0
Post likes count0

A history of GlobalLock, part 1: The early years

Raymond Chen

Once upon a time, there was Windows 1.0. This was truly The Before Time. 640K. Segments. Near and far pointers. No virtual memory. Co-operative multitasking. Since there was no virtual memory, swapping had to be done with the co-operation of the application. When there was an attempt to allocate memory (either for code or data) and insuffici...

History
Nov 3, 2004
Post comments count0
Post likes count0

Why do I sometimes see redundant casts before casting to LPARAM?

Raymond Chen

If you read through old code, you will often find casts that seem redundant. SendMessage(hwndListBox, LB_ADDSTRING, 0, (LPARAM)(LPSTR)"string"); Why was "string" cast to LPSTR? It's already an LPSTR! These are leftovers from 16-bit Windows. Recall that in 16-bit Windows, pointers were near by default. Consequently, "string" was a near pointe...

History
Nov 2, 2004
Post comments count0
Post likes count0

What was the point of the GMEM_SHARE flag?

Raymond Chen

The GlobalAlloc function has a GMEM_SHARE flag. What was it for? In 16-bit Windows, the GMEM_SHARE flag controlled whether the memory should outlive the process that allocated it. By default, all memory allocated by a process was automatically freed when that process exited. Passing the GMEM_SHARE flag suppressed this automatic cleanup. That's...

History
Nov 2, 2004
Post comments count0
Post likes count0

And to think they let me get away with it for five years

Raymond Chen

According to the Constitution of the State of New Jersey, Article II, paragraph 6: No idiot or insane person shall enjoy the right of suffrage. Why are constitutional articles labelled with Roman numerals? Makes it sound like the Super Bowl or something. The state appellate court did rule a few years ago that being hospitalized...

Non-Computer