Showing tag results for Code

Mar 26, 2014
Post comments count0
Post likes count2

Can CoCreateGuid ever return GUID_NULL?

Raymond Chen
Raymond Chen

A customer asked whether the function can ever return . Their code uses for special purposes, and it would be bad if that was ever returned as the GUID for an object. "Can we assume that never returns ? Or should we test the return value against , and if it is equal, then call and try again?" Some people started running a bunch of times and o...

Code
Mar 24, 2014
Post comments count0
Post likes count1

Enumerating set partitions with Bell numbers and Stirling numbers of the second kind

Raymond Chen
Raymond Chen

Just for fun, today's Little Program is going to generate set partitions. (Why? Because back in 2005, somebody asked about it on an informal mailing list, suggesting it would be an interesting puzzle, and now I finally got around to solving it.) The person who asked the question said, Below we show the partitions of [4]. The periods separate ...

Code
Mar 20, 2014
Post comments count0
Post likes count1

Going for the facts: Who is displaying this message box?

Raymond Chen
Raymond Chen

A customer wanted to know whether had a problem with Unicode. A problem with it? Quite the contrary. loves Unicode! In fact, if you call the ANSI version, it converts the strings to Unicode and then finishes the work in Unicode. Okay, here's the customer's problem. We have a custom application written in managed code. When we launch the p...

Code
Mar 17, 2014
Post comments count0
Post likes count1

How do I show the contents of a directory while respecting the user's preferences for hidden and super-hidden files as well as the user's language preferences?

Raymond Chen
Raymond Chen

A customer was writing a program in (and this is what they said) "32 bit C++ .Net 4.0" which displayed the contents of a directory, and they wanted to filter out items such as hidden files and protected operating system files (also known as super-hidden files) based on the user's current Explorer preferences. Furthermore, they wanted to show local...

Code
Mar 14, 2014
Post comments count0
Post likes count1

How do I create an IShellItemArray from a bunch of file paths?

Raymond Chen
Raymond Chen

The interface accepts bulk operations in the form of an . So how do you take a list of file names and convert them into an ? There is no function, but there is a , and we know how to convert a path to an ID list, namely via . So lets snap two blocks together. The template function takes an array of paths and starts by creating a correspon...

Code
Mar 13, 2014
Post comments count0
Post likes count1

Why does the Directory.GetFiles method sometimes ignore *.html files when I ask for *.htm?

Raymond Chen
Raymond Chen

The documentation for the method says When using the asterisk wildcard character in a search­Pattern, such as "*.txt", the matching behavior when the extension is exactly three characters long is different than when the extension is more or less than three characters long. A search­Pattern with a file extension of exactly three character...

Code
Mar 10, 2014
Post comments count0
Post likes count1

Programmatically uploading a file to an FTP site

Raymond Chen
Raymond Chen

Today's Little Program uploads a file to an FTP site in binary mode with the assistance of the Wininet library. This program has sat in my bag of tools for years. The program accepts five command line arguments: site (no "ftp://" in front) userid password path for the file to upload location to place the uploaded file For example, I might s...

Code
Mar 7, 2014
Post comments count0
Post likes count1

Converting from a UTC-based SYSTEMTIME directly to a local-time-based SYSTEMTIME

Raymond Chen
Raymond Chen

Last year, I presented this commutative diagram A 2-by-2 grid of boxes. The top row is labeled FILE­TIME; the bottom row is labeled SYSTEM­TIME. The first column is labeled UTC; the second column is labeled Local. The upper left box is labeled Get­System­Time­As­File­Time. There is an outgoing arrow to th...

CodeTime