Showing tag results for Code

Dec 2, 2010
Post comments count0
Post likes count1

The alignment declaration specifier is in bytes, not bits

Raymond Chen
Raymond Chen

Explicit object alignment is not something most people worry about when writing code, which means that when you decide to worry about it, you may be a bit rusty on how the declarations work. (After all, if it's something you worried about all the time, then you wouldn't have trouble remembering how to do it!) I was looking at some customer code,...

Code
Nov 26, 2010
Post comments count0
Post likes count1

The easy way out is to just answer the question: What is the current Explorer window looking at?

Raymond Chen
Raymond Chen

A customer had the following question: We have an application which copies and pastes files. Our problem is that we want to paste the files into the folder which corresponds to the currently active Windows Explorer window. Right now, we're using , but we find this method unsatisfactory because we want to replace Explorer's default file copy engine...

Code
Nov 22, 2010
Post comments count0
Post likes count2

Consequences of using variables declared __declspec(thread)

Raymond Chen
Raymond Chen

As a prerequisite, I am going to assume that you understand how TLS works, and in particular how variables work. There's a quite thorough treatise on the subject by Ken Johnson (better known as Skywing), who comments quite frequently on this site. The series starts here and continues for a total of 8 installments, ending here. That last page al...

Code
Nov 18, 2010
Post comments count0
Post likes count1

One possible reason why ShellExecute returns SE_ERR_ACCESSDENIED and ShellExecuteEx returns ERROR_ACCESS_DENIED

Raymond Chen
Raymond Chen

(The strangely-phrased subject line is for search engine optimization.) A customer reported that when they called , the function sometimes fails with , depending on what they are trying to execute. (If they had tried they would have gotten the error .) After a good amount of back-and-forth examing file type registrations, a member of the develo...

Code
Oct 28, 2010
Post comments count0
Post likes count0

Why is there an LVN_ODSTATECHANGED notification when there's already a perfectly good LVN_ITEMCHANGED notification?

Raymond Chen
Raymond Chen

If you work with owner-data listviews, you take the responsibility for managing the data associated with each item in the list view. The list view control itself only knows how many items there are; when it needs information about an item, it asks you for it. It's the fancy name for a "virtual list view" control. When you use an ownerdata list vi...

Code
Oct 25, 2010
Post comments count0
Post likes count0

When you call a function, your code doesn't resume execution until that function returns

Raymond Chen
Raymond Chen

Consider this code fragment: When calls , and has not yet returned, does continue executing? Does get called before returns? No, it does not. The basic structure of the C/C++ language imposes sequential execution. Control does not return to the function until returns control, either by reaching the end of the function or by an explic...

Code
Oct 20, 2010
Post comments count0
Post likes count0

How do I get the dimensions of a cursor or icon?

Raymond Chen
Raymond Chen

Given a or a , how do you get the dimensions of the icon or cursor? The function gets you most of the way there, returning you an structure which gives you the mask and color bitmaps (and the hotspot, if a cursor). You can then use the function to get the attributes of the bitmap. And then here's the tricky part: You have to massage the data...

Code
Oct 15, 2010
Post comments count0
Post likes count0

What does the FOF_NOCOPYSECURITYATTRIBS flag really do (or not do)?

Raymond Chen
Raymond Chen

In the old days, the shell copy engine didn't pay attention to ACLs. It just let the file system do whatever the default file system behavior was. The result was something like this: Perfectly logical, right? If a new file is created, then the security attributes are inherited from the container. If an existing file is moved, then its security a...

Code
Oct 14, 2010
Post comments count0
Post likes count0

The memcmp function reports the result of the comparison at the point of the first difference, but it can still read past that point

Raymond Chen
Raymond Chen

This story originally involved a more complex data structure, but that would have required too much explaining (with relatively little benefit since the data structure was not related to the moral of the story), so I'm going to retell it with double null-terminated strings as the data structure instead. Consider the following code to compare tw...

Code
Oct 13, 2010
Post comments count0
Post likes count0

How do I get the color depth of the screen?

Raymond Chen
Raymond Chen

How do I get the color depth of the screen? This question already makes an assumption that isn't always true, but we'll answer the question first, then discuss why the answer is wrong. If you have a device context for the screen, you can query the color depth with a simple arithmetic calculation: Now that you have the answer, I'll explain why...

Code