Showing tag results for Code

Jun 29, 2004
Post comments count0
Post likes count1

The difference between thread-safety and re-entrancy

Raymond Chen

An operation is "thread-safe" if it can be performed from multiple threads safely, even if the calls happen simultaneously on multiple threads. An operation is re-entrant if it can be performed while the operation is already in progress (perhaps in another context). This is a stronger concept than thread-safety, because the second attempt to per...

Code
Jun 28, 2004
Post comments count0
Post likes count1

When does SHLoadInProc unload a DLL?

Raymond Chen

The SHLoadInProc function instructs Explorer to create an instance of a particular CLSID. This causes the DLL responsible for that CLSID to be loaded. But when is it unloaded? This is one of those puzzles you should be able to figure out by thinking about it. Consider: The object is created by calling CoCreateInstance and then imme...

Code
Jun 11, 2004
Post comments count0
Post likes count1

A hidden performance cost of regional windows

Raymond Chen

Regional windows are neat, but they come at a cost. Most of the cost you can see directly. For example, constantly changing the region clearly generates a cost since you have to sit there and generate new regions all the time. One question that came up on an internal performance alias highlights one of the hidden costs of regional windows: The p...

Code
Jun 10, 2004
Post comments count0
Post likes count1

Speeding up adding items to a combobox or listbox

Raymond Chen

Just a little tip: If you're going to be adding a lot of items to a listbox or combobox, there are a few little things you can do to improve the performance significantly. (Note: The improvements work only if you have a lot of items, like hundreds. Of course, the usability of a listbox with a hundred items is questionable, but I'm assuming you h...

Code
Jun 8, 2004
Post comments count0
Post likes count1

When can a thread receive window messages?

Raymond Chen

Everybody who has messed with window messaging knows that GetMessage and PeekMessage retrieve queued messages, which are dispatched to windows via DispatchMessage. Most people also know that GetMessage and PeekMessage will also dispatch nonqueued messages. (All pending nonqueued messages are dispatched, then the first queued message is retur...

Code
Jun 7, 2004
Post comments count0
Post likes count1

Deleted but not yet forgotten

Raymond Chen

What happens when you delete a file while it is open?

Code
Jun 4, 2004
Post comments count0
Post likes count1

An easy way to determine whether you have a particular file permission

Raymond Chen

Sometimes you might want to determine whether you can do something without actually doing it. For example, you might want to know whether you have a particular permission in a directory, say permission to delete files from it. One way is to retrieve the ACL and then check whether the current user has the desired permission. The AccessCheck functio...

Code
Jun 1, 2004
Post comments count0
Post likes count1

What does SHGFI_USEFILEATTRIBUTES mean?

Raymond Chen

One of the flags you can pass to the SHGetFileInfo function is SHGFI_USEFILEATTRIBUTES. What does this flag mean? It means, "Do not access the disk. Pretend that the file/directory exists, and that its file attributes are what I passed as the dwFileAttributes parameter. Do this regardless of whether it actually exists or not." You can ...

Code
May 28, 2004
Post comments count0
Post likes count1

High-performance multithreading is very hard

Raymond Chen

Among other things, you need to understand weak memory models. Hereby incorporating by reference Brad Abrams' discussion of volatile and MemoryBarrier(). In particular, Vance Morrison's discussion of memory models is important reading. (Though I think Brad is being too pessimistic about volatile. Ensuring release semantics at the stor...

Code
May 24, 2004
Post comments count0
Post likes count0

Extending the Internet Explorer context menu

Raymond Chen

In a comment, Darrell Norton asked for a "View in Mozilla" option for Internet Explorer. You can already do this. Internet Explorer's context menu extension mechanism has been in MSDN for years. Let me show you how you can create this extension yourself. First, create the following registry key: Of course, you need to change C:\some\pa...

Code