Calvin Hsia's WebLog

thoughts from a professional developer

  • Calvin Hsia's WebLog

    Use C++ and no managed code to create a WPF form

    • 0 Comments
    In Use the power of Reflection to create and manipulate managed objects I showed how to create a WPF form with a StackPanel, Button and Textbox from a C# console app, using reflection. The code adds text to the textbox and sets some properties on it....
  • Calvin Hsia's WebLog

    Use the power of Reflection to create and manipulate managed objects

    • 0 Comments
    When you create a Windows Presentation Foundation (WPF) project in Visual Studio, references to WPF libraries, like PresentationFrameworks.dll, PresentationCore.dll, WindowsBase.dll, are automatically added, from which you can create types and invoke...
  • Calvin Hsia's WebLog

    Big numbers

    • 0 Comments
    When I first started learning about numbers I remember marveling at what infinity means. How many integers are there? Are there more real numbers than integers? How many numbers are there between zero and 1? Then I remember thinking about how these numbers...
  • Calvin Hsia's WebLog

    Drawing old playing card images for bridge

    • 1 Comments
    About 11 years ago I wrote a blog about Contract bridge card distributions . When you play bridge, with a normal 52 card deck, it helps to know about how often a particular suit distribution might occur. For example, if you and your partner have 9 Spades...
  • Calvin Hsia's WebLog

    Examining a crash dump

    • 1 Comments
    A crash dump is very helpful for diagnosing a problem with software. It can contain enough information to recreate a debug session, almost as if you’re debugging the problem live on the repro machine. Last time I showed some code to create a crash dump...
  • Calvin Hsia's WebLog

    Create your own crash dumps

    • 1 Comments
    Sometimes programs will crash on your machine. Windows Error Reporting can send problem reports back to Microsoft. You can use the Windows Event log to see more detail about prior crashes. Some crashes will send crash dumps to Microsoft so that the crash...
  • Calvin Hsia's WebLog

    Blinking Lights are useful

    • 2 Comments
    A while ago, computers had blinking lights on a front panel. I recognized various patterns of blinking lights as indicating various operating modes: idle, waiting for teletype input, typing on the teletype machine, reading a paper tape, busy with high...
  • Calvin Hsia's WebLog

    Execute tasks in parallel using async and await to speed up computation

    • 0 Comments
    Suppose you have five tasks you want your computer to execute and that each takes 1 second to execute. In the old days, one would figure that each task would be executed sequentially, resulting in a total execution time of 5 seconds. Even today, many...
  • Calvin Hsia's WebLog

    Create your own Process Explorer

    • 0 Comments
    I was playing around with showing some resizable content in a WPF window. I wanted 2 variable sized Lists, one on top of the other. The lists had various lengths, but also various widths: the user could adjust the size of the columns. This smelled like...
  • Calvin Hsia's WebLog

    Wireless HeadPhone Adventures

    • 2 Comments
    I wanted to get wireless headphones to listen to music. At the office I have 3 desktops, with a range of power. The most powerful has 3 monitors connected. The next has 1, while a 3 rd doesn’t have any (I Remote Desktop to it). I run various flavors of...
  • Calvin Hsia's WebLog

    Write native to managed interop code: reg free COM

    • 0 Comments
    If you followed the steps of the last post ( Call C# code from your legacy C++ code ), then your C++ program simply started the CLR (Common Language Runtime), invoked a C# method that returned the length of the passed in string argument. Not very exciting...
  • Calvin Hsia's WebLog

    Call C# code from your legacy C++ code

    • 0 Comments
    For many decades, folks have been quite productive in creating C++ code. These “legacy” apps have been quite useful. However, as most software developers know, software needs to be maintained. Business needs change, and the applications need to change...
  • Calvin Hsia's WebLog

    Heap Corruption Exception 0xC0000374

    • 0 Comments
    Modern computers can execute millions of instructions per second, and if one of them is erroneous, then the process could crash. Often analysis of a crash dump can immediately indicates what the problem is, so the fix is easy. For example a NullReference...
  • Calvin Hsia's WebLog

    Debugger features help to find memory leaks

    • 2 Comments
    You can use the debugger $CALLSTACK and TracePoints to find memory leaks. Memory leaks are very tedious to find. Often they don’t affect an application at all except a gradual performance slowdown on a customer machine. Leaks can be found in old code...
  • Calvin Hsia's WebLog

    Create managed Tests for native code

    • 0 Comments
    In the old days of code development, the developer would do several steps repeatedly: 1. edit the code 2. Save 3. Compile 4. Link 5. Deploy (if necessary) 6. Start (or switch to) the debugger 7. Start the app under the debugger. 8. Examine the code behavior...
  • Calvin Hsia's WebLog

    Export your data to Excel using CSV and all data appears in one column

    • 0 Comments
    In many prior posts, I export data to Excel via writing to a TEMP file and just starting that TEMP file, which starts Excel, if Excel is on the machine.   var tempFileName = System.IO. Path .ChangeExtension( System.IO. Path .GetTempFileName(),...
  • Calvin Hsia's WebLog

    Fish vs Sharks: Predator Prey simulation

    • 0 Comments
    Many years ago, A.K. Dewdney wrote an article in Scientific American Magazine (December 1984) about a world called Wator, which is a world of fish and sharks. The world is a cellular automaton with each cell being in one of three states: empty, a shark...
  • Calvin Hsia's WebLog

    Logo Turtle Graphics in WPF

    • 3 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

    • 44 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...
Page 1 of 18 (444 items) 12345»