Showing tag results for Code

Jul 20, 2011
Post comments count0
Post likes count1

How do I find the original name of a hard link?

Raymond Chen
Raymond Chen

A customer asked, "Given a hardlink name, is it possible to get the original file name used to create it in the first place?" Recall that hard links create an alternate name for a file. Once that alternate name is created, there is no way to tell which is the original name and which is the new name. The new file does not have a "link back to the...

Code
Jul 8, 2011
Post comments count0
Post likes count1

We've traced the pipe, and it's coming from inside the process!

Raymond Chen
Raymond Chen

We saw last time one of the deadlocks you can run into when playing with pipes. Today we'll look at another one: Our program runs a helper process with stdin/stdout/stderr redirected. The helper process takes input via stdin and prints the result to stdout. Sometimes we find that the from the controlling process into the stdin pipe hangs. Clos...

Code
Jul 6, 2011
Post comments count0
Post likes count2

Looking at the problem at the wrong level: Closing a process's stdin

Raymond Chen
Raymond Chen

A customer was having trouble manipulating the stdin stream that was given to a process. How do you simulate sending Ctrl+Z to a hidden console process programmatically? I am using and want to send the console a Ctrl+Z. I've tried sending ASCII code 26, but that doesn't work. supports Ctrl+C and Ctrl+Break but not Ctrl+Z. Here's what I'm ...

Code
Jul 1, 2011
Post comments count0
Post likes count1

The list of heaps returned by GetProcessHeaps is valid when it returns, but who knows what happens later

Raymond Chen
Raymond Chen

A customer had a problem involving heap corruption. In our code, we call and then for each heap, we call to enable the low fragmentation heap. However, the application crashes due to an invalid heap handle. My question is, why do we need to allocate an array of size 1025 even though we pass 1024 to ? Ha, faked you out with that question...

Code
Jun 30, 2011
Post comments count0
Post likes count1

The UseUrl attribute in the App Paths key indicates that your application can accept a URL on the command line

Raymond Chen
Raymond Chen

Setting the attribute in your key indicates that your application can accept a URL on the command line as the document to be opened. The documentation for this attribute is a confusing blend of raw documentation, guidance, history, and an example. Let's tease the parts apart so you won't confuse the example with the contract. The raw documentat...

Code
Jun 29, 2011
Post comments count0
Post likes count1

What happens to WPARAM, LPARAM, and LRESULT when they travel between 32-bit and 64-bit windows?

Raymond Chen
Raymond Chen

The integral types , , and are 32 bits wide on 32-bit systems and 64 bits wide on 64-bit systems. What happens when a 32-bit process sends a message to a 64-bit window or vice versa? There's really only one choice when converting a 64-bit value to a 32-bit value: Truncation. When a 64-bit process sends a message to a 32-bit window, the 64-bit ...

Code
Jun 28, 2011
Post comments count0
Post likes count1

How do I display the Find Printers dialog programmatically?

Raymond Chen
Raymond Chen

A customer wanted to display the Find Printers dialog programmatically to let the user pick a printer from Active Directory and wanted to know whether this was possible. Yes, it's possible, and there's more than one way to do it. There's the lazy way and the overachieving way. The overachieving way is to use the method. The sample function spe...

Code
Jun 24, 2011
Post comments count0
Post likes count1

Why doesn't my MessageBox wrap at the right location?

Raymond Chen
Raymond Chen

A customer reported that the function was wrapping text "at the wrong location." Our program displays a message with the function, and we use the '\n' character to force line breaks at positions we choose. But we've found that starting in Windows Vista, the line breaks we placed are not working. The function is inserting its own line break...

Code