Showing tag results for Code

May 3, 2013
Post comments count0
Post likes count1

Creating a simple pidl: For the times you care enough to send the very fake

Raymond Chen
Raymond Chen

I'll assume that we all know what pidls are and how the shell namespace uses them. That's the prerequisite for today. A simple pidl is an item ID list that refers to a file or directory that may not actually exist. It's a way of playing "what if": "If there were a file or directory at this location, here is what I would have created to represent...

Code
May 1, 2013
Post comments count0
Post likes count1

How do I get the current value of the RSP register from a C/C++ function? (No answer, but a solution.)

Raymond Chen
Raymond Chen

A customer using Visual Studio wanted to know how to obtain the current value of the x64 RSP register from a C/C++ function. They noted that on the x86, you can drop to inline assembly, and on the ia64, you can use the intrinsic to retrieve the value of any register. There is no corresponding intrinsic on x64. There's no really good way of doin...

Code
Apr 29, 2013
Post comments count0
Post likes count1

Getting the display name for a shell property

Raymond Chen
Raymond Chen

Today's Little Program takes the symbolic name for a shell property and returns a string suitable for display to the end-user, translated into the user's specified display language. #include <windows.h> #include <ole2.h> #include <propsys.h> #include <propkey.h> #include <atlbase.h> #include <atlalloc.h> int ...

Code
Apr 26, 2013
Post comments count0
Post likes count1

Another way to create a process with attributes, maybe worse maybe better

Raymond Chen
Raymond Chen

Adam Rosenfield noted that "those sure are a lot of hoops you have to jump through to solve this unusual problem" of specifying which handles are inherited by a new process. Well, first of all, what's so wrong with that? You have to jump through a lot of hoops when you are in an unusual situation. But by definition, most people are not in an unus...

Code
Apr 25, 2013
Post comments count0
Post likes count1

If you’re going to use an interlocked operation to generate a unique value, you need to use it before it’s gone

Raymond Chen
Raymond Chen

Is the Interlocked­Increment function broken? One person seemed to think so. We're finding that the Interlocked­Increment is producing duplicate values. Are there are any know bugs in Interlocked­Increment? Because of course when something doesn't work, it's because you are the victim of a vast conspiracy. There is a fundamental ...

Code
Apr 24, 2013
Post comments count0
Post likes count1

Dark corners of C/C++: The typedef keyword doesn’t need to be the first word on the line

Raymond Chen
Raymond Chen

Here are some strange but legal declarations in C/C++: int typedef a; short unsigned typedef b; By convention, the typedef keyword comes at the beginning of the line, but this is not actually required by the language. The above declarations are equivalent to typedef int a; typedef short unsigned b; The C language (but not C++) also permits...

Code
Apr 22, 2013
Post comments count0
Post likes count1

Getting the current selection from an Explorer window

Raymond Chen
Raymond Chen

Today's Little Program prints the current selection in all open Explorer windows. (This is an alternative to the C++ version that involves a ridiculous amount of typing.) var shellWindows = new ActiveXObject("Shell.Application").Windows(); for (var i = 0; i < shellWindows.Count; i++) { var w = shellWindows.Item(i); WScript.StdOut.WriteLine...

Code
Apr 19, 2013
Post comments count0
Post likes count3

Why does CoCreateInstance work even though my thread never called CoInitialize? The curse of the implicit MTA

Raymond Chen
Raymond Chen

While developing tests, a developer observed erratic behavior with respect to : In my test, I call and it fails with . Fair enough, because my test forgot to call . But then I went and checked the production code: In response to a client request, the production code creates a brand new thread to service the request. The brand new thread does ...

Code
Apr 15, 2013
Post comments count0
Post likes count1

Using opportunistic locks to get out of the way if somebody wants the file

Raymond Chen
Raymond Chen

Opportunistic locks allow you to be notified when somebody else tries to access a file you have open. This is usually done if you want to use a file provided nobody else wants it. For example, you might be a search indexer that wants to extract information from a file, but if somebody opens the file for writing, you don't want them to get Sharin...

Code
Apr 12, 2013
Post comments count0
Post likes count3

Is it legal to have a cross-process parent/child or owner/owned window relationship?

Raymond Chen
Raymond Chen

A customer liaison asked whether it was legal to use to create a parent/child relationship between windows which belong to different processes. "If I remember correctly, the documentation for used to contain a stern warning that it is not supported, but that remark does not appear to be present any more. I have a customer who is reparenting windo...

Code