Showing tag results for Code

Sep 20, 2007
Post comments count0
Post likes count0

It rather involved being on the other side of this airtight hatchway: Elevation to administrator

Raymond Chen
Raymond Chen

Surprisingly, it is not a security vulnerability that administrators can add other users to the Administrators group. But that doesn't stop people from claiming that it is. For example, it's not uncommon for a vulnerability report to come in with the following steps: Wow, this looks bad. An unprivileged user can elevate to administrator and... ...

Code
Sep 19, 2007
Post comments count0
Post likes count0

What happens if you pass a source length greater than the actual string length?

Raymond Chen
Raymond Chen

Many functions accept a source string that consists of both a pointer and a length. And if you pass a length that is greater than the length of the string, the result depends on the function itself. Some of those functions, when given a string and a length, will stop either when the length is exhausted or a null terminator is reached whichever c...

Code
Sep 18, 2007
Post comments count0
Post likes count0

Why is my delay-rendered format being rendered too soon?

Raymond Chen
Raymond Chen

Here's a customer question: I've put data on the clipboard as delay-rendered, but I'm getting a request for my for many operations even though nobody actually looks at the files. Operations such as right-clicking a blank space on the desktop or opening the Edit menu. I don't want to render the data until the user hits Paste because generating th...

Code
Sep 14, 2007
Post comments count0
Post likes count0

The code page on the server is not necessarily the code page on the client

Raymond Chen
Raymond Chen

It's not enough to choose a code page. You have to choose the right code page. We have a system that reformats and reinstalls a network client computer each time it boots up. The client connects to the server to obtain a loader program, and the loader program then connects to the server to download the actual operating system. If anything goes wr...

Code
Sep 11, 2007
Post comments count0
Post likes count0

What's the difference between EM_UNDO and WM_UNDO?

Raymond Chen
Raymond Chen

Daniel Chait wonders why we have both and . You know, I wonder the same thing. But I'm going to make an educated guess. Actually, most of what I write is just a lot of educated guessing. Like my explanation of why has such complicated rules? A guess. Why address space granularity is 64KB? A guess. Why most messages are in the system message...

Code
Sep 10, 2007
Post comments count0
Post likes count0

If control-specific messages belong to the WM_USER range, why are messages like BM_SETCHECK in the system message range?

Raymond Chen
Raymond Chen

When I discussed which message numbers belong to whom, you may have noticed that the messages for edit boxes, buttons, list boxes, combo boxes, scroll bars, and static controls go into the system range even though they are control-specific. How did those messages end up there? They didn't start out there. In 16-bit windows, these control-spec...

Code
Sep 4, 2007
Post comments count0
Post likes count1

Does creating a thread from DllMain deadlock or doesn't it?

Raymond Chen
Raymond Chen

Let me get this out of the way up front: Creating a thread from is not recommended. The discussion here has to do with explaining the behavior you may observe if you violate this advice. Commenter Pete points out that "according to Usenet" creating a thread in is supposed to deadlock, but that's not what he saw. All he saw was that the thread ...

Code
Aug 29, 2007
Post comments count0
Post likes count1

Kernel handles are not reference-counted

Raymond Chen
Raymond Chen

Here's a question that floated past some time ago: In my code, I have multiple objects that want to talk to the same handle (via ). Each time I create an object, I use to increment the reference count on the handle. That way, when each object calls , only the last one actually closes the handle. However, when I run the code, I find as soon as t...

Code
Aug 17, 2007
Post comments count0
Post likes count0

What are these spurious nop instructions doing in my C# code?

Raymond Chen
Raymond Chen

Prerequisites: Basic understanding of assembly language. When you debug through some managed code at the assembly level, you may find that there are an awful lot of instructions scattered throughout your method. What are they doing there; isn't the JIT smart enough to remove them? Isn't this going to slow down execution of my program? It is my u...

Code
Aug 16, 2007
Post comments count0
Post likes count0

What are these strange cmp [ecx], ecx instructions doing in my C# code?

Raymond Chen
Raymond Chen

When you debug through some managed code at the assembly level, you'll find a whole lot of seemingly pointless instructions that perform a comparison but ignore the result. What's the point of comparing two values if you don't care what the result is? In C++, invoking an instance method on a pointer results in undefined behavior. In other words, ...

Code