Use reflection from native C++ code to run managed code

In the prior post (Use Reflection to create instances of objects) I showed how to create a plain C# console application that has no special references (including none to any WinForms assembly) that can load and invoke a WinForm.Exe program. Today, we’ll look at doing the same thing from a plain old C++ native program….


Use Reflection to create instances of objects

You can use reflection (specifically classes in the System.Reflection namespace) to create instances of objects. Last time (Create and play your own Breakout game ) , I showed a Windows Form application that is a Breakout game. This time, let’s see if we can create and run that WinForm game (Paddle.Exe) from a C# console…


Create and play your own Breakout game

I remember pouring quarters into a video game called Breakout a few decades ago. The summer of 1975, I spent at Rensselaer PolyTechnic Institute (RPI) in Troy, NY. I was taking a structured programming course using Fortran on an IBM 360, using punched cards. The student union building had an arcade in which there were…


Manipulate managed and native objects in C++ to show the registry in a WPF TreeView

Last time, we looked at how easy it is to add managed code to your existing C++ application. (Call managed code from your C++ code) The sample below shows a more substantial C++ program which Liberally intermixes both native and managed objects in C++ code for demo purposes. Reads the registry recursively using native C++…


Call managed code from your C++ code

Over the decades of writing code, I’ve found that writing managed code (C#, VB) is much more productive than native code (C++). This is especially true due to the capabilities of the .Net framework libraries that can be used easily from managed code. For a given programming task, the number of lines of code is…


Scan the Windows Event Log for your application crashes and hangs

When you write software that runs on someone’s machine, it might crash or hang. If this occurs, there are ways to see if this occurred from your program. For example, I wrote a simple application in C++ called CppTest that crashes by dereferencing a null: char *ptr = 0; *ptr = 0; Lo and behold:…


Use Custom Attributes to initialize test environments

Some tests can be quite complex, perhaps having prerequisites that consist of various steps, querying initial conditions, loading test data, etc. You can use Attributes to specify various test configurations. The sample below shows how to create your own attribute class and how to retrieve and use it in various parts of your code. I…


Use status events to log and analyze an application

Applications can get quite complex, with multiple components, assemblies, subsystems, etc. Understanding this complexity can be daunting. An old but still very effective way of analyzing code is to modify the code to output a string whenever that section of code gets executed. Remember the old Printf() from old C/C++ programs? Perhaps that code could…


Does the CLR release memory when no longer needed?

A colleague asked the other day if the CLR releases memory when it’s no longer needed. Suppose you allocate lots of memory, then release it. The CLR will grow the managed heap (the green below), but it will also shrink it if it can. All memory in a process must come from a pool of…


Cartoon animation works great on Surface Pro

I showed my 9 year old son a cool drawing program called Physamajig, in which users can draw objects, which behave like real physical objects, including reacting to gravity, friction, and bounce. He was having fun with it on my Surface RT and it reminded me of another program. Years ago (around 1981) when I…