Click here to view current Bits From Bill posts Bits from Bill

Technology thoughts leaking from the brain of "Bill Pytlovany"

Sunday, September 23, 2012

Use New 64 bit Features On Older 32 bit Windows

One of the challenges for programmers is to continue to support all customers and still take advantage of new features available in operating systems. Instead of managing multiple code bases I’ve learned to support older versions while still taking advantage of new features. Recently, I learned it the hard way.

I thought it would be useful to share an example of code that I currently use that not only supports 64 bit Windows, but uses new functions that aren’t supported by the still popular 32 bit Windows XP.

1. Accessing 32 and 64 bit Registry Locations
In this example, I wanted to use a new function that Microsoft enhanced for 64 bit Windows. To remove registry keys I’ve used the following function.

RegDeleteKey( HKEY, LPCSTR)

The registry in 64 bit Windows has a special tree that is used to store registry values used by 32 bit applications.  Many values under the global software registry is automatically redirected to be saved under the following key.  See List of Keys

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node

Most applications that store options in the registry don’t need to know if their registry calls are redirected. A utility like my WinPatrol absolutely needs to know which registry location is used and when Windows is redirecting values. Using the actual location is crucial for detecting malware or modifying legitimate software which may behave badly.

To allow programmers access to either the normal registry location or Wow6432Node many registry functions have been enhanced to specify the real location instead of being reflected or redirected. One new replacement function is

RegDeleteKeyEx( HKEY, LPCTSTR, REGSAM, DWORD);

The REGSAM value can be either KEY_WOW64_32KEY(0x200) for removing a key in the Wow6432Node tree used by 32 bit applications or KEY_WOW64_64KEY(0x100) which doesn’t get redirected.

2. Using new Windows Functions not supported by XP

In my WinPatrol program I need to use the function “RegDeleteKeyEx” which is located in a Windows library by the name “Advapi32”.  Unfortunately, not all 32 bit versions of Windows support this function including Windows XP.

When I build WinPatrol.exe using Microsoft Visual Studio, it finds information needed to use RegDeleteKeyEx and includes the entry point address in my final code. It hard codes or “statically links” this function in my executable. When WinPatrol ran it expected to find the Advapi32dll file on the computer and expected to find the RegDeleteKeyEx function within it. 

When WinPatrol or any program is launched Windows checks to make sure all the required DLL’s exist and they include any static links. The version of “Advapi32dll” on a 32 bit version of Windows XP has no knowledge of the RegDeleteKeyEx function.  The resulting error message doesn’t make sense to most users but when I received this screen shot in Emails I knew immediately where I had screwed up.
error

Instead of making two versions of WinPatrol I created a replacement routine that uses a “run-time dynamic link”.  By not having a static definition in my code Windows XP won’t detect the references to a function that doesn’t exist.

This is my own function to delete a key in the registry. It works for all the versions of Windows that are supported by WinPatrol.  I’ve removed most comments, a branch for unicode systems and some error checking so you can see the required code which is explained under the example.

code As with many type based languages,  I begin my function by defining local variables. The 3rd one defines a the pointer(lpfRegDeleteKeyEx) to a Windows API that returns a long result. The name of this variable can be anything. I include parameters that RegDeleteKeyEx use for readability. This variable will contain the entry point address to the function so I can still call it but versions of Windows that don’t know about it won’t barf.
All the details on using this new function are available in documentation free from Microsoft Developer Network. This information will allow you to do similar operations with other languages. 

The glx64 is just a global variable I set early on when I check to see if we’re running on a 64 bit system.  If it’s not a 64 bit system I don’t need special code. I can just call the same old RegDeleteKey function which will have no trouble finding the Key because there isn’t an alternate Wow6432Node tree in the registry.

  • If it is a 64 bit system I use run-time dynamic linking to call the new function.
    *  First I use LoadLibrary to access Advapi32.dll which has many Registry API’s including RegDeleteKeyEx.  The call returns a “handle” to the library which I will need in future calls.
    *  If the library loads ok, then I call “GetProcAddress” to get a pointer to the entry point of the RegDeleteKeyEx function.
    *  If the entry point is found I can just use the pointer variable to call the function passing the same parameters required if we used static linking.
    *  Lastly I tell Windows I’m done with FreeLibrary. For this example I removed some checks if my call failed for some reason.


As one of the main components in Windows Advapi32.dll is most likely already in memory so it’s not like the disk is accessed each time this function is called.  Calls to LoadLibrary will increment a counter for the library and FreeLibrary decrements the count. If it reaches zero then Windows knows it can be unloaded from memory.

When Microsoft documents an API function it will also include the name of which DLL is used and what versions of Windows are supported.  If an older version of Windows isn’t supported you’ll want to use Run-time Dynamic Linking similar to this example.

Share on Facebook


Wednesday, September 19, 2012

WinPatrol 25.6.2012 License Agreement Explained

While I was tempted to follow the trend of others and call our new version WinPatrol 2013, I know how to read a calendar and no matter what others say it’s still 2012!

The new version of WinPatrol doesn’t have any major new features but thanks to detailed reports from loyal users I’ve tracked down a number of annoying bugs.

As part of the new setup, I’ve included a short yet important description of the WinPatrol license agreement. In the past, it wasn’t always clear what benefits and restrictions were part of our WinPatrol license agreement. Details on the FREE and PLUS licenses are now spelled out during installation. Following the description here I’ve included details on what’s new and a link to download WinPatrol 25.6.

WinPatrol FREE License
The Free Edition of WinPatrol is available for permanent use and is not just a trial version. This program is a powerful tool that alerts you to system changes, allows you to prevent selected programs from running, allows you to safely explore what programs might be slowing you down and more. The WinPatrol Free Edition license is limited to personal use but may be installed on multiple computers. You agree to use WinPatrol at your own risk.

WinPatrol PLUS       Single User Personal License
Upgrading to WinPatrol PLUS is a one-time investment, not a yearly subscription. You'll never be asked to pay again but you may not share your PLUS activation code with others. Once you receive a PLUS code you may use it to activate PLUS features on any computer you own and you personally use. It does not include computers used by family members if you only provide support & maintenance. WinPatrol PLUS may be purchased for a business environment but is still limited to individual  users. This license is fully transferable to any new computers you purchase or new versions of WinPatrol software.

Using a PLUS activation code not obtained from BillP Studios, WinPatrol.com or one of our partners is discouraged and could result in your PLUS features being disabled without warning. Obtaining a PLUS code from an illegal "keygen" download site may be the source of a malware infection. When using an illegal code your IP address may be reported to organizations currently working to reduce the use of pirated software.


WinPatrol PLUS        Family Pack License

A single WinPatrol Family Pack code may be used by all members of your immediate family within your household. Immediate family includes a common-law spouse or a domestic partnership as well as any offspring living within your home.  It also includes children who are away at school.
Like the standard license, you may continue to use your activation code on all future versions of WinPatrol without any additional fee.

Small and Large businesses should contact support@WinPatrol.com for special offers to support environments with 10 or more WinPatrol users..


WinPatrol PLUS       Single Machine License
As a special marketing test, WinPatrol PLUS  was available for a limited time at a unique price of 99 cents. Just like our Single User License this purchase provides a  fully transferable, lifetime of WinPatrol PLUS. Each 99 cent order however is good for a single physical computer. A single activation code will be provide per individual and may be used on multiple computers.  Each computer is associated with each payment of 99 cents. A single physical computer includes the use of one WinPatrol PLUS license on multiple virtual machines.

setup

Version 25.6.2012.0                                   September 19th, 2012

Based on user feedback and especially the extra effort from loyal WinPatrol fans we've improved reliability with WinPatrol 25.6. WinPatrol features work better than ever and we've removed the possibility of confusing messages that may have given incorrect alert messages.

* Fixed Multiple Alerts When Startup Removed
One of the newest features of WinPatrol 25 is letting users know if a Startup program had been removed without their knowledge. Unfortunately, occasionally a bug appeared that once the initial warning appeared, WinPatrol continued to warn about the removal of other programs which still existed in the list of Startup Programs.

* Windows 7 Performance Boost
WinPatrol has always worked well with all versions of Windows including Windows 7, this version takes better advantage of performance ability available to Windows 7 users.

* Multiple Add/Remove Uninstall Entries
When checking the Uninstall list using the Add/Remove or Uninstall applet, WinPatrol may have retained previous versions. This version will remove past entries that exist.

* License Agreement Info
In the past the license agreement for various WinPatrol versions were not clearly stated and easy to find on our website. The new setup program includes a description of the Free, PLUS, Family Pack and special licenses. Users will now see how unique WinPatrol is and what few restrictions exist.

* Scotty Barking at Random
This has been a long time unexplainable quirk that never made sense. Reports of Scotty barking with no alert should be a thing of the past.

* IE Helper Enhanced
Some IE Helpers may have been missed on some machines. They will all now be properly displayed.

* Uninstall Enhancements
While we now have a stand alone WinPatrolRemove program, this version includes an Uninstaller that works much better than our past embarrassments. Improvements to the WinPatrol Uninstall program will now removed registry entries that gave incorrect screen positions when multiple monitors were used. We'll also remove any language packs which you may have installed in error.

* Explorer Menu Integration
While some users may still not have the full privileges, most users will be able to look up PLUS Info for EXE's and DLL's directly from the right-click menu on Explorer file lists.

downloadClick Here for WinPatrol Download Page

 


Update September 20th : Released compatibility issue with 32 bit Windows XP. The use of the function RegDeleteKeyEx, is not support by 32 bit versions of XP, slipped by our original release. This function was required to support 64 bit Windows.  I was able to patch this error by using dynamic library linking so after testing the new code on each platform I was able to release 25.6.2012.1 just after midnight EST.  If you’re not using Windows XP you don’t need to rush to download this patch if you have already downloaded 25.6.  Special thanks to our XP users who were quick to help even taking the time to send screen shots.


By popular demand I will post the code I used to show programmers not only how to support 64 bit systems but how to take advantage of new Windows functions yet still support versions of Windows no longer supported by Microsoft.

Share on Facebook