Tuesday, February 20, 2007

const (in C++/CLI) considered harmful

Today I found the following "gotcha" in combining C++/CLI and C#.
Create a C++/CLI dll containing something along the lines of:

public ref class Foo
static const int BAR = 42;
Use that from C#, maybe like so:
int temp = Foo.BAR;
= -1;
string.Format("The answer is: {0} ...or {1}",
temp, Foo.BAR),
Wait, that should not be possible! We just said that BAR was const in the C++/CLI code didn't we?

The problem is that it is possible (and gives the following screenshot):

Digging deeper reveals that C++/CLI const turns into an ordinary field with an optional modifier IsConst that languages are free to ignore, (which e.g. C# does).

If you in fact want a "constant" constant (which is probably why you wrote const in the first place?), then you will need to use literal in C++/CLI to get the same result as a C# const.

Thursday, February 15, 2007


The second version of Dependency Visualizer was just uploaded. This time it might actually work :) And in the case it does not, the possibilities to get traces for me should be infinitely better than the first version.

Wednesday, February 14, 2007

Dependency Visualizer released

I just put up the first public version of the Dependency Visualizer. You might want to try it out..

Tuesday, February 13, 2007

Extend right-click menu in Explorer in WiX installer

I just had the need to make an installer that created a right-click menu item for Visual Studio solution files (.sln)

The easiest way to accomplish this would have been to use the WiX built in support for registering extensions:

<Extension ContentType="text\plain" Id="sln">
<Verb Id="Visualize" Command="Visualize dependencies"

However, I soon found out that this was a Bad Idea, in the sense that then my software took over as the default handler for .sln files. Not exactly what I wanted...

Turns out that I needed to manually install the registry keys/values in the appropriate place to get it to work:

<Component Id="DependencyVisualizerComponent" Guid="PUT-GUID-HERE">
<File Name="DependencyVisualizer.exe" Id="DependencyVisualizerExe"
<RegistryKey Action="createAndRemoveOnUninstall" Root="HKCR"
<RegistryValue Action="write" Value="Visualize Dependencies" Type="string" />
<RegistryKey Action="createAndRemoveOnUninstall" Key="Command">
<RegistryValue Action="write" Type="string"
="&quot;[#DependencyVisualizerExe]&quot; "%1""/>

Oh, and the tool I'm working on is a tool for visualizing inter-project dependencies...