Showing tag results for Code

Feb 14, 2013
Post comments count0
Post likes count1

If you can’t find the function, find the caller and see what the caller jumps to

Raymond Chen

You're debugging a program and you want to set a breakpoint on some function, say, netapi32!Ds­Address­To­Site­NameW, but when you execute the bp netapi32!Ds­Address­To­Site­NameW command in the debugger, the debugger says that there is no such function. The Advanced Windows Debugging book says that the bp comman...

Code
Feb 13, 2013
Post comments count0
Post likes count1

How do I launch a file as if it were a text file, even though its extension is not .txt?

Raymond Chen

You might have a program that generates log files or other text content with an extension other than . You naturally might want to open these documents in the user's default text editor. You might decide to ask the Windows developer support team, "How can I figure out what program is the handler for text files?" The idea being that once you get t...

Code
Feb 11, 2013
Post comments count0
Post likes count1

Display an overlay on the taskbar button

Raymond Chen

Today's "Little Program" displays an overlay on the taskbar button. I've seen some people call this a "badge", but "overlay" is the official term. Start with our scratch program and make the following changes: #include <comip.h> #include <comdef.h> #include <shlobj.h> #include <shellapi.h> _COM_SMARTPTR_TYPEDEF(ITaskb...

Code
Feb 4, 2013
Post comments count0
Post likes count1

Obtaining the parsing name (and pidl) for a random shell object

Raymond Chen

The parsing name for a shell item is handy, because it lets you regenerate the item later. Actually, the pidl for the shell item is even better, because that is the official way of saving and restoring objects. It's the pidl that gets saved in a shortcut, and since shortcuts can be copied around from machine to machine, pidls must be transportable...

Code
Feb 1, 2013
Post comments count0
Post likes count1

Psychic debugging: Why your IContextMenu::InvokeCommand doesn’t get called even though you returned success from IContextMenu::QueryContextMenu

Raymond Chen

A customer was having trouble with their IContext­Menu implementation. They observed that their IContext­Menu::Query­Context­Menu method was being called, but when the user selected their menu item, IContext­Menu::Invoke­Command was not being called. Given what you know about shell context menus, you can already direct th...

Code
Jan 31, 2013
Post comments count0
Post likes count1

The somewhat misguided question of whether MapViewOfFile or WriteProcessMemory is faster

Raymond Chen

A customer asked, "Which is faster for copying data from one process to another; or ?" This is one of those "Huh?"-type questions, where the customer has solved half of a problem and is looking for help with the other half, the half that makes no sense. First of all, the question is malformed because does not copy any data at all. It takes e...

Code
Jan 30, 2013
Post comments count0
Post likes count1

Why doesn’t HeapValidate detect corruption in the managed heap?

Raymond Chen

A customer had a program that was corrupting the managed heap by p/invoking incorrectly. The problem didn't show up until the next garbage collection pass, at which point the CLR got all freaked-out-like. "According to Knowledge Base article 286470, the tool is supposed to catch heap corruption, but it doesn't catch squat." Depending on your po...

Code
Jan 28, 2013
Post comments count0
Post likes count1

Finding a printer, and then creating a shortcut to that printer

Raymond Chen

Today's "Little Program" does two things: It looks for a printer in the Printers folder, and then once it finds it, it creates a shortcut to that printer. As is common with "Little Programs", I don't bother with error checking. I'll leave you to do that. Second part first, since it is handy on its own: Creating a shortcut to an arbitrary item ...

Code
Jan 25, 2013
Post comments count0
Post likes count1

When you have a SAFEARRAY, you need to know what it is a SAFEARRAY *of*

Raymond Chen

A customer had a problem with SAFEARRAY, or more specifically, with CComSafeArray. CComSafeArray<VARIANT> sa; GetAwesomeArray(&sa); LONG lb = sa.GetLowerBound(); LONG ub = sa.GetUpperBound(); for (LONG i = lb; i <= ub; i++) { CComVariant item = sa.GetAt(i); ... use the item ... } The GetAt method returns a VARIANT&, and wh...

Code