Showing tag results for Code

Mar 11, 2013
Post comments count0
Post likes count0

How can I see what files and shares are being accessed remotely, and the general usage pattern for the NetXxx functions

Raymond Chen
Raymond Chen

Today's Little Program is a command line version of the Shared Folders MMC snap-in. Why? Because it illustrates the usage pattern for the Net­Xxx family of functions. (It's also a clone of the networking portion of the openfiles tool.) The Net­Xxx family of functions generally work like this: You pass in some parameters that describe ...

Code
Mar 7, 2013
Post comments count0
Post likes count0

What are the conventions for managing standard handles?

Raymond Chen
Raymond Chen

Consider this function: void ChangeConsoleColor(WORD wColor) { HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); if (h != INVALID_HANDLE_VALUE) { SetConsoleTextAttribute(h, wColor); CloseHandle(h); } } "When I call this function, it works the first time, but when I call it a second time, Get­Std­Handle returns a handle numerically ide...

Code
Mar 6, 2013
Post comments count0
Post likes count0

What are the dire consequences of not selecting objects out of my DC?

Raymond Chen
Raymond Chen

The convention when working with device contexts is to restore them to the way you found them. If a drawing function selects a bitmap into a device context, then it should select the original bitmap into the device context before returning. Same for fonts, pens, all that stuff. But what if you decide to violate that convention? For example, maybe...

Code
Mar 4, 2013
Post comments count0
Post likes count0

Marking a shortcut to say that it should not be placed on the Windows 8 Start page upon installation or treated as a newly-installed application

Raymond Chen
Raymond Chen

Today's Little Program creates a shortcut on the Start menu but marks it as "Do not put me on the front page upon installation." This is something you should do to any secondary shortcuts your installer creates. And while you're at it, you may as well set the "Don't highlight me as a newly-installed program" attribute used by Windows 7. (Reme...

Code
Mar 1, 2013
Post comments count0
Post likes count2

The source of much confusion: “backed by the system paging file”

Raymond Chen
Raymond Chen

Perhaps one of the most misunderstood sentences in the Win32 documentation is this little bit in the documentation for : If hFile is INVALID_HANDLE_VALUE, the calling process must also specify a size for the file mapping object in the dwMaximum­Size­High and dwMaximum­Size­Low parameters. In this scenario, Create­File­Map...

Code
Feb 28, 2013
Post comments count0
Post likes count0

What does 1#J mean? A strange corner case of the printing of special values

Raymond Chen
Raymond Chen

As a puzzle, commenter nobugz asks, "What kind of infinity is 1.#J?" double z = 0; printf("%.2f", 1/z); Now, the division by zero results in IEEE positive infinity, would would normally be printed as 1#INF. But the catch here is that the print format says "Display at most two places after the decimal point." But where is the decimal point in i...

Code
Feb 28, 2013
Post comments count0
Post likes count0

Is there a way to specify an icon to appear next to a menu item via the resource template?

Raymond Chen
Raymond Chen

The structure lets you specify a bitmap to appear next to the menu item. Is there a way to do this from a menu resource template? No. If you look at the format of menu templates, you'll see that there is nowhere to specify a bitmap. Which kind of makes sense, because it is the responsibility of the application to destroy the bitmap refer...

Code
Feb 22, 2013
Post comments count0
Post likes count0

Now that version 4 of the .NET Framework supports in-process side-by-side runtimes, is it now okay to write shell extensions in managed code?

Raymond Chen
Raymond Chen

Many years ago, I wrote, "Do not write in-process shell extensions in managed code." Since I originally wrote that article, version 4 of the .NET Framework was released, and one of the features of that version is that it supports in-process side-by-side runtimes. Does that mean that it's now okay to write shell extensions in managed code? The ans...

Code
Feb 22, 2013
Post comments count0
Post likes count0

Isn’t the CompletionKey parameter to CreateIoCompletionPort superfluous?

Raymond Chen
Raymond Chen

When you associate a file handle with an I/O completion port with the function, you can pass an arbitrary pointer-sized integer called the which will be returned by the function for every I/O that completes against that file handle. But isn't that parameter superfluous? If somebody wanted to associated additional data with a file handle, they...

Code