Calvin Hsia's WebLog

thoughts from a professional developer

  • Calvin Hsia's WebLog

    Logo Turtle Graphics in WPF

    • 2 Comments
    Logo is a programming language that somehow involves a turtle. Imagine a turtle on a large piece of paper on the floor. The  turtle has a pen. You can command the turtle to go forward, turn right, then repeat 4 times to draw a square. The last time...
  • Calvin Hsia's WebLog

    Surface Pro 3 cursor disappears

    • 2 Comments
    I like my new Surface Pro 3. Things were working fine and all of a sudden, the cursor would disappear. I just have the Type Cover and a memory card installed: no other hardware. Narrowing down the issue: if I move my finger in circles on the trackpad...
  • Calvin Hsia's WebLog

    DPI Aware Sample

    • 0 Comments
    Last time I showed a way to use immediate mode graphics in WPF by showing balls bouncing around in a window. This time, we’ll add a few features. I’ve made the program DPI (Dots Per Inch) Aware. On most machines it works correctly. However, on my brand...
  • Calvin Hsia's WebLog

    WPF immediate mode graphics

    • 1 Comments
    Windows Presentation Foundation (WPF) is a retained mode graphics system (see Retained Mode Versus Immediate Mode ). That means when you write code to draw something, you’re actually declaring a set of graphics objects (like lines or shapes) to use. The...
  • Calvin Hsia's WebLog

    How to monitor and respond to memory use

    • 0 Comments
    A colleague asked me how to run code in response to low memory condition. Apparently, data is buffered and can be flushed to disk or a server when memory gets low. So I showed him the code below. Start Visual Studio File->New->Project->C# WPF...
  • Calvin Hsia's WebLog

    Async methods failures can be hard to diagnose

    • 0 Comments
    Using asynchronous programming can make your application be more responsive and seem faster. However, beware of possible failures that are hard to diagnose. I’ve just been analyzing some of these crash reports that are sent to Microsoft from the Problem...
  • Calvin Hsia's WebLog

    The Enum changed to int: How do you convert the int back to a name?

    • 0 Comments
    I wrote a tool that loaded some binary data and displayed it in a nice form, where the user could browse the data, sort by various columns, filter, export, etc. The tool relied on the fact that a column of the data contained an integer ID indicating the...
  • Calvin Hsia's WebLog

    See how often your code runs and how much time it takes

    • 0 Comments
    Last post I showed how to create your own CLR profiler. This time, we’ll add a little code to run whenever a managed method is entered and exited. We’ll do this by signing up for the  Enter and Leave function hooks by calling ICorProfilerInfo2->SetEnterLeaveFunctionHooks2...
  • Calvin Hsia's WebLog

    Create your own CLR Profiler

    • 0 Comments
    A CLR profiler is a very powerful way to examine your managed code. Let’s create your own CLR Profiler. This simple example will 1. Start the specified managed application that we will profile 2. Intercept the creation of all managed objects 3. Calculate...
  • Calvin Hsia's WebLog

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

    • 0 Comments
    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...
  • Calvin Hsia's WebLog

    Use Reflection to create instances of objects

    • 0 Comments
    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...
  • Calvin Hsia's WebLog

    Create and play your own Breakout game

    • 2 Comments
    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...
  • Calvin Hsia's WebLog

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

    • 0 Comments
    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...
  • Calvin Hsia's WebLog

    Call managed code from your C++ code

    • 1 Comments
    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....
  • Calvin Hsia's WebLog

    Scan the Windows Event Log for your application crashes and hangs

    • 0 Comments
    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...
  • Calvin Hsia's WebLog

    Use Custom Attributes to initialize test environments

    • 0 Comments
    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...
  • Calvin Hsia's WebLog

    Use status events to log and analyze an application

    • 0 Comments
    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...
  • Calvin Hsia's WebLog

    Does the CLR release memory when no longer needed?

    • 0 Comments
    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...
  • Calvin Hsia's WebLog

    Cartoon animation works great on Surface Pro

    • 1 Comments
    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...
  • Calvin Hsia's WebLog

    The Visual Studio Feedback tool

    • 1 Comments
      Sometimes when you use Visual Studio, or any application on a computer, there’s a notable pause when you try to do something. For example, trying to access a file on a network share somewhere, perhaps on a slow connection, the application will...
  • Calvin Hsia's WebLog

    Compiling code at runtime and MVP program is 20

    • 0 Comments
    This month marks the 20 th anniversary of the Microsoft MVP program, so MVPs were in the news. Apparently I had a lot to do with the founding of the program J Wikipedia: http://en.wikipedia.org/wiki/Microsoft_Most_Valuable_Professional Microsoft News...
  • Calvin Hsia's WebLog

    Windows Error Reporting and the Appdomain.UnhandledException Event

    • 1 Comments
    Sometimes applications fail. If you are the author and it fails on your machine, typically you fire up the code in a debugger, figure out the issue, fix it, and rebuild the code. If the applications is out in the wild, perhaps with millions of users,...
  • Calvin Hsia's WebLog

    Create a logger for watching your test progress as it runs.

    • 0 Comments
      I was creating a project that’s a Windows Service, which has components running in multiple processes, using multiple threads and named pipes for communication. To understand the behavior of the code, I wanted to have accurate logging that: · The...
  • Calvin Hsia's WebLog

    Turn your tests into stress tests easily

    • 0 Comments
    It’s great to be able to write tests and execute them while developing a project. While I’m developing, I can hit a button and run the dozens of tests to see if I’ve broken anything. As code gets written lots of things get refactored, moved around, etc...
  • Calvin Hsia's WebLog

    Its easy to Create your own FrameWorkElement in WPF

    • 0 Comments
    Sometimes you want to have very fine control of how your application looks and behaves. Other times, you just want to draw something on your UI. It’s pretty easy to create your own control class and put instances of it on your form. The sample below create...
Page 1 of 18 (427 items) 12345»