Welcome to MSDN Blogs Sign in | Join | Help

Browse by Tags

All Tags » Sample Code   (RSS)

Quiz: can you count how many combinations ...

Here's a combinatorics quiz: If you have 2 ordered lists (lengths N, M), how many ways can they be interleaved into a single list while still preserving the partial ordering from the original lists? So if the lists were: List 1: A,B List 2: X,Y The following
Posted by jmstall | 10 Comments
Filed under: , ,

How to add Options to Live Writer PlugIns

This entry explains how to have options associated with your Windows Live Writer plugin, including design patterns, dealing with the UI, persistence issues, and setup/uninstall implications . See here for an example of writing a plugin. What are good
Posted by jmstall | 0 Comments

WiX Script for installing Live Writer Plugins

Here's a WiX install script to build an MSI to install a Windows Live Writer (WLW) plugin dll, by xcopying the plugin dll to the Plugins directory. You can then upload your MSI to the WLW Gallery and share your plugin with others. WLW Plugins are very
Posted by jmstall | 0 Comments

Simple Tool for text substitution plus Design questions

I wrote a simple C# app to do text substitution. It takes a (key,value) mapping and then replaces any keys in between {% ... %} with their value. It's a really trivial app. But it also quickly opens a Pandora's box of design questions. It takes an xml
Posted by jmstall | 2 Comments
Filed under: ,

Foreach codegen

Do you know how the following C# code compiles? foreach ( int i in c) { Console .WriteLine(i); } In addition to the obvious branching opcodes, this can also emit try/finally, a call to IDisposable, unboxing opcodes. It turns out it really depends on the
Posted by jmstall | 5 Comments
Filed under: ,

Setting transparency in an image

Just as Jackie Chan does his own stunts; I do my own image drawing. Some of my "art": (The yellow arrow here ). The shapes in my Silverlight 1.1 app : The astute observer probably noticed that all of my work is very primitive and done in MS Paint (yup,
Posted by jmstall | 7 Comments
Filed under: ,

My first (non-trivial) Windows Live Writer Plugin

So the Live Writer Plugin model is so cool and easy that I had to write a plugin. (and do it with Edit-and-Continue ). The obvious ones were already done (eg, Paste code from VS), so I scratched my head for an idea and I finally got one: a "verse of the
Posted by jmstall | 9 Comments

Sample code for copying Html to Clipboard

// Sample class for Copying and Pasting HTML fragments to and from the clipboard. // // Mike Stall. http://blogs.msdn.com/jmstall // using System; using System.Diagnostics; using System.Windows.Forms; using System.Text.RegularExpressions; using System.Collections.Generic;
Posted by jmstall | 1 Comments
Filed under:

Copying HTML on the clipboard

Setting plain text on the clipboard is easy. Call Clipboad.SetText("Hello!"), and it works great. But what if you want to set HTML? Tempting to think you just call Clipboard.SetText ("<b>Hello!</b>", TextDataFormat.Html ). But that doesn't
Posted by jmstall | 6 Comments
Filed under:

Type-safe Managed wrappers for kernel32!GetProcAddress

Pinvoke is cool in managed code, but sometimes you need to get straight at kernel32!GetProcAddress. For example, maybe you need dynamic control over which unmanaged dll you want to load. But that returns a void*, which is a major no-no in managed code.
Posted by jmstall | 6 Comments
Filed under:

C# app to count #ifdef usage

Here's a little tool I wrote to count #ifdef usage in a project. It provides a summary of the #define name and frequency; plus a detailed XML file of each location that the #define occurred at. For example, when applied to this sample file (in directory
Posted by jmstall | 3 Comments
Filed under:

Viewing types with Reflection-Only

It's natural for a tool to use Reflection-Only loading to load an assembly and view the types in it. For example, I used this in my pdb2xml tool. However, I missed an important detail that I wanted to warn you about after getting it wrong myself. Consider
Posted by jmstall | 5 Comments
Filed under: ,

Unit testing databases

Here's a cool tool on CodePlex that Tim pointed me to f or anyone who needs to write unit tests on your data-access code: http://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=MassDataHandler “The MassDataHandler is a framework to assist with
Posted by jmstall | 1 Comments
Filed under:

Writing an RTF to HTML converter, posting code in blogs.

Visual Studio's IDE will copy code as RTF (Rich Text Format). Web browsers like HTML. So posting code from Visual into blogs means a decent RTF to HTML conversion. And having a technical blog means posting code. So I needed to solve this conversion problem.
Posted by jmstall | 12 Comments
Filed under:

Using CreateRemoteThread from C#

If you want to create a new thread in your process in C#, you can use Thread.Start . But things are a little harder if you want to create a thread in another process, ala kernel32!CreateRemoteThread . Disclaimer : CreateRemoteThread is evil, could dead-lock,
Posted by jmstall | 6 Comments
Filed under:
More Posts Next page »
 
Page view tracker