Showing tag results for Code

Oct 6, 2005
Post comments count0
Post likes count0

The unfortunate interaction between LOAD_LIBRARY_AS_DATAFILE and DialogBox

Raymond Chen
Raymond Chen

Some people have noticed that if you load a DLL with the flag, you sometimes get strange behavior if you then pass that to a dialog box function. The problem here is that since the bottom 16 bits of a proper are always zero, different components have "borrowed" those bits for different purposes. The kernel uses the bottom bit to distinguish mo...

CodeHistory
Oct 4, 2005
Post comments count0
Post likes count0

Consequences of the scheduling algorithm: Sleeping doesn’t always help

Raymond Chen
Raymond Chen

More often I see the reverse of the "Low priority threads can run even when higher priority threads are running" problem. Namely, people who think that is a clean way to yield CPU. For example, they might have run out of things to do and merely wish to wait for another thread to produce some work. Recall that the scheduler looks for the highest...

Code
Oct 3, 2005
Post comments count0
Post likes count0

Consequences of the scheduling algorithm: Low priority threads can run even when higher priority threads are running

Raymond Chen
Raymond Chen

Just because you have a thread running at a higher priority level doesn't mean that no threads of lower priority will ever run. Occasionally, I see people write multi-threaded code and put one thread's priority higher than the other, assuming that this will prevent the lower-priority thread from interfering with the operation of the higher-prior...

Code
Sep 29, 2005
Post comments count0
Post likes count0

On objects with a reference count of zero

Raymond Chen
Raymond Chen

One commenter claimed that When the object is first constructed, the reference count should be 0 and AddRef should be called at some point (probably via QueryInterface) to increment the reference count. If you construct your object with a reference count of zero, you are playing with matches. For starters, when the object is created, there re...

Code
Sep 16, 2005
Post comments count0
Post likes count0

Fiddling with the fonts, part 2: Keeping the English font small

Raymond Chen
Raymond Chen

We concluded last time that we wanted the custom large font to apply only to the columns containing Chinese characters and leave the original font in place for the English columns. We do this by carrying two fonts around, choosing the appropriate one for each column. class RootWindow : public Window { ... private: HWND m_hwndLV; HWND m_hwndEd...

Code
Sep 15, 2005
Post comments count0
Post likes count0

Fiddling with the fonts, part 1: Making the Chinese characters larger

Raymond Chen
Raymond Chen

Let's pay a quick visit to our continuing dictionary project. One of the things you may have noticed is that the Chinese characters are unreadably small. Let's fix that by making them larger. class RootWindow : public Window { public: virtual LPCTSTR ClassName() { return TEXT("Scratch"); } static RootWindow *Create(); RootWindow(); ~RootWind...

Code
Sep 12, 2005
Post comments count0
Post likes count0

Understanding the consequences of WAIT_ABANDONED

Raymond Chen
Raymond Chen

One of the important distinctions between mutexes and the other synchronization objects is that mutexes have owners. If the thread that owns a mutex exits without releasing the mutex, the mutex is automatically released on the thread's behalf. But if this happens, you're in big trouble. One thing many people gloss over is the WAIT_ABANDONED re...

Code
Sep 9, 2005
Post comments count0
Post likes count0

Reading the output of a command from batch

Raymond Chen
Raymond Chen

The FOR command has become the batch language's looping construct. If you ask for help via FOR /? you can see all the ways it has become overloaded. For example, you can read the output of a command by using the for command. FOR /F "tokens=*" %i IN ('ver') DO echo %i The /F switch in conjunction with the single quotation marks indicates that t...

Code