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 and wants to…

9

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…

22

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 that are batched. Apparently some…

7

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…

9

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 been created.   To reproduce the…

15

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 means the prior selected…

11

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 Using ActiveX Controls with…

21

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 (see 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,…

6

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…

15

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 from memory and executes…

6