Showing tag results for Code

Jul 3, 2007
Post comments count0
Post likes count0

If the system says that an embedded string could not be converted from Unicode to ANSI, maybe it's trying to tell you something

Raymond Chen
Raymond Chen

It's probably trying to tell you that an embedded string could not be converted from Unicode to ANSI. One of our programs is throwing the exception "Type could not be marshaled because an embedded string could not be converted from Unicode to ANSI." It happens only if we use the Chinese version of the program. Why are we getting this exception? ...

Code
Jun 29, 2007
Post comments count0
Post likes count0

Don't forget to pass the current directory along with the command line to your single-instance program

Raymond Chen
Raymond Chen

If you make a single-instance program, and somebody runs a second copy of the program and passes a command line, the most common way of handling this is to hand the command line to the first copy of the program and let the first copy deal with it. When you do this, don't forget about the current directory. If somebody passes a relative path to t...

Code
Jun 27, 2007
Post comments count0
Post likes count0

Those who do not understand the dialog manager are doomed to reimplement it, badly

Raymond Chen
Raymond Chen

A customer wanted to alter the behavior of a multi-line edit control so that it did not treat a press of the Tab key as a request to insert a tab character but rather treated it as a normal dialog navigation key. The approach the customer took was to subclass the edit control and intercept the Tab key: There are many things wrong with this appr...

Code
Jun 26, 2007
Post comments count0
Post likes count0

Why do DLGC_WANTALLKEYS and DLGC_WANTMESSAGE have the same value?

Raymond Chen
Raymond Chen

From a purely theoretical point of view, there is only one "want" code you really need: . All the others are just conveniences. For example, returning means "I want this message if it is an arrow key; otherwise, I don't care." It lets you write instead of the more cumbersome (but equivalent) Similarly, is equivalent to returning if the me...

Code
May 31, 2007
Post comments count0
Post likes count0

Visual C++ 2005 will generate manifests for you

Raymond Chen
Raymond Chen

New in Visual C++ 2005 is the ability to specify a manifest dependency via a directive. This greatly simplifies using version 6 of the shell common controls. You just have to drop the line into your program and the linker will do the rest. Note that the processor architecture is hard-coded into the above directive, which means that if ...

Code
May 29, 2007
Post comments count0
Post likes count0

Psychic debugging: Why does FormatMessage say the resource couldn't be found?

Raymond Chen
Raymond Chen

Solving this next problem should be a snap with your nascent psychic powers: I'm trying use to load a resource string with one insertion in it, and this doesn't work for some reason. The string is "Blah blah blah %1. Blah blah blah." The call to fails, and returns . What am I doing wrong? Hint: Take a closer look at the parameter . Hint&...

Code
May 25, 2007
Post comments count0
Post likes count0

The parameters to PostQueuedCompletionStatus are not interpreted

Raymond Chen
Raymond Chen

Larry Osterman mentioned this almost in passing quite a while ago, that the parameters to are not interpreted by the operating system. Well, obviously the first parameter, the handle to the completion port, is interpreted as the handle to the completion port. But the other parameters, , , and are not interpreted at all. Even though they have na...

Code
May 21, 2007
Post comments count0
Post likes count0

Don't be helpless: I don't know anything about MFC modal loops, but unlike some people, I'm not afraid to find out

Raymond Chen
Raymond Chen

Commenter Tom Grelinger asks via the Suggestion Box: If I have a modal CDialog that is visible and usable to the user. Let's say I receive an event somewhere else in the program and I call DestroyWindow on the modal CDialog from within the event. I notice that the OnDestroy is called on the CDialog, but DoModal never exits until a WM_QUIT is po...

Code
May 8, 2007
Post comments count0
Post likes count0

Session 0 isolation: Where backward compatibility loses to security

Raymond Chen
Raymond Chen

One of the major changes to services in Windows Vista is session 0 isolation. After reading the summary, you can follow that first supplementary link, Impact of Session 0 Isolation on Services and Drivers in Windows Vista, to dig deeper and receive guidance on how you need to modify your service. Then again, some of the questions I see regar...

Code
May 7, 2007
Post comments count0
Post likes count0

Drag and drop is a general purpose transfer model, not exclusive to Explorer directories

Raymond Chen
Raymond Chen

If you've designed your program so that it assumes that the the only thing a user can use drag/drop for is dropping your object into a file system directory, then you've already lost. piers wants to be able to determine the destination of a drag/drop operation. From the description, it appears that what piers really wants is the destination path,...

Code