Calvin Hsia's WebLog

thoughts from a professional developer

Browse by Tags

Tagged Content List
  • Blog Post: See how often your code runs and how much time it takes

    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 . This will allow us...
  • Blog Post: Create your own CLR Profiler

    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 the class name for the object (Like “System.String...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: Sometimes you want 2 returned values: playing around with Tuples

    When writing code in various languages, you’ll write functions from which you get a return value. Sometimes you’ll want to get 2 return values. A common way to handle this is to use parameters to pass a variable by reference that will get one of the return values. Alternatively, you could use a...
  • Blog Post: Use Named Pipes and Shared Memory for inter process communication with a child process or two

    I wanted to inject some very low impact code that would run in any “parent” process, like Notepad or Excel or Visual Studio. I wanted to have some User Interface for the data that my injected code gathered about the parent process, and that would work best in a different “child” process, preferably using...
  • Blog Post: Use a Custom Allocator for your STL container

    Last time in Play around with .Net Dictionaries and STL maps , we talked about various containers. Today we’ll write our own allocator for a particular STL container. A general purpose allocator, like malloc in the C Runtime library or HeapAlloc in the Windows API needs to handle allocation requests...
  • Blog Post: Play around with .Net Dictionaries and STL maps

    Last time ( Adventures in interop code: explore string interop memory ) we investigated sharing memory between native and managed code, or between processes. Data structures are very useful: things like arrays, structures, lists, dictionaries, stacks, queues, etc. are used throughout programming...
  • Blog Post: Adventures in interop code: explore string interop memory

    In Create an ActiveX control using ATL that you can use from Fox, Excel, VB6, VB.Net , I showed how to create a control (with which the user can interact) which can be hosted in many places. Today’s sample creates a class in C++ that doesn’t necessarily have UI, and thus isn’t visually hosted,...
  • Blog Post: Comment/Uncomment code to switch versions quickly without using macros

    In a typical day, I write or debug programs in several languages: typically Foxpro, C#, VB, C++ and 32 bit assembly, with an occasional MSIL, IDL and 64 bit ASM thrown in. Sometimes, I like to switch between one version of code and another. This is useful if I want to do side by side comparisons...
  • Blog Post: Overload Operator new to detect memory leaks

    There are various leak detection methods for memory allocators. A popular one is to tag each allocation with some information about the caller. When there’s a memory leak, you just need to look at that tag info to find the line of code that allocated the memory. However, this requires that the...
  • Blog Post: Write simple Debug helpers to help you debug and maintain your code

    Much of my time is spent using the Visual Studio debugger examining code to figure out how it works and how to fix it. When stepping through a function, the values the function uses are very useful for code understanding. The debugger shows these values in the Watch/Locals/Auto/Callstack windows. For...
  • Blog Post: Make your code more maintainable: The evils of the Return statement

    What does it mean to make code more maintainable? Certainly obfuscated code is hard to understand, by definition. A big part of maintainability is making it easier for others to read and understand what the code is doing. Your code may have been working for years, but then somebody comes along...
  • Blog Post: How fast is interop code?

    How fast is interop code? If you’re in one kind of code and your calling another, what is the cost of the interop? For example, .Net code can call native C++ code (like Windows APIs) and vice versa. Similarly with Foxpro and C++ code. .Net code is often referred to as Managed code because much...
  • Blog Post: Vista Aero DWM seems to optimize out GDI paint calls

    In this post: Foxpro Menu items, combo boxes not refreshing selected item under Aero in Vista I describe a problem in Foxpro where menu and list items that are supposed to be non-selected aren’t painted correctly. I described a workaround: call the GdiSetBatchLimit API, which limits the GDI paint functions...
  • Blog Post: Windows Vista Aero BorderStyle Paint problem as non Administrator

    Above is an image of an inner form (from the C++ project below) before and after I dragged it a little bit up and left to obscure the title bar, then back to the original position. You can see the title, icon, close/minimize buttons were not painted correctly. The same thing happens in Foxpro and VS...
  • Blog Post: Fix your forms to paint borders correctly under Vista Aero

    Apparently, the borders of some forms don’t get painted correctly on Windows Vista. When executing a Fox Form, Fox asks Windows to create a window, then sets the BorderStyle of the window. Apparently, under Vista Aero (except as Administrator), the BorderStyle cannot be set after the Window has...
  • Blog Post: Foxpro Menu items, combo boxes not refreshing selected item under Aero in Vista

    If you’re running a Foxpro application under Vista when using Aero , you might encounter a problem when scrolling through lists, such as intellisense dropdowns, comboboxes, menus. As you move from one item in the list to the next, each item in turn appears to be selected (colors inverted), which...
  • Blog Post: Create an ActiveX control using ATL that you can use from Fox, Excel, VB6, VB.Net

    Creating an ActiveX control is a good exercise in understanding how one works. It also helps to have full control over its source code for learning and testing purposes. A customer asked about migrating legacy ActiveX controls over to .Net. Many controls can be used without any changes in .Net. (See...
  • Blog Post: Host the CLR and Generate IL to call a MessageBox

    Here’s some C++ code to host the CLR. It’s an alternative to using COM Interop (s ee A Visual Basic COM object is simple to create, call and debug from Excel ), or using a User Control (see Create a .Net UserControl that calls a web service that acts as an ActiveX control to use in Excel, VB6, Foxpro...
  • Blog Post: Customize the VS debugger display of your data

    As a software developer, I spend much of my time looking at code, learning how it works, and figuring out how to modify or fix it. A very good tool to help examine code is the Visual Studio debugger. (Even if you’re not a hard core programmer, the following tutorial shows some of the power of the...
  • Blog Post: Windows Security and how it affects running generated code

    Here I described how VFP generates executable code and runs it for early and late binding COM clients and implementing COM interfaces. However, there is an important issue with generating and running executable code in the same process. A computer has a processor (or a few) that fetches instructions...
  • Blog Post: What is a C0000005 crash?

    In my blog about Dr. Watson I talked about product crashes. What is an example of a crash? How destructive is it? Here’s a simple example. MyFunction takes a string parameter and calculates its length MyFunction ( char * StringParam) { int nlen; // declare an integer variable...
Page 1 of 1 (24 items)