Sunday, June 20, 2010

.net 1.1 (vs2003) applications on Windows 7 x64

I needed to create a demo application (LARGE one) built with Net 1.1 Framework for demonstration on Windows 7 x64 computers (it was just easier than prepare a Net 3.5 version). I've met several problems this way, may be some one will find this information useful:

1. Windows 7 misses C-Runtime components for Vs2003, I mean MSVCR71.DLL file. If your program is using it, you should redistribute it (and place it in your program binaries directory or into System32 (for x86 windows)  / SysWow64 (for x64).

2. Emulation (or backward compatibility) of  1.1 framework works fine withing Windows 7 (framework 3.5sp1 integrated), beside one particular moment: NativeOverlapped object. Type of EventHandle field of this object was SILENTLY changed from int to IntPtr in move from Framework 1.1 to 2.0. This is very funny, since now any 1.1 programs using this object won't work at frameworks >=2.0 at all, with error looking like "Unhandled AppDomain Exception (CLR is terminating: True): System.MissingFieldException: Field not found: 'System.Threading.NativeOverlapped.EventHandle'.".
I don't know how you can help yourself if you haven't got source codes of net 1.1 application, otherwise the solution is simple: replace all direct accesses to this (EventHandle) field with indirect one, like this:

Considering this declarations
        NativeOverlapped addrChangeOverlapped = new NativeOverlapped();
        ManualResetEvent addrChangeEvent = new ManualResetEvent(false);


It was (in our application):
        addrChangeOverlapped.EventHandle = addrChangeEvent.Handle.ToInt32();




It become (in version compatible for execution with net 3.5):
        IntPtr aceHandle = addrChangeEvent.Handle;
        FieldInfo aceFI = typeof(NativeOverlapped).GetField("EventHandle");
        aceFI.SetValue(addrChangeOverlapped, 

               aceFI.FieldType == typeof(int)?(object)aceHandle.ToInt32():aceHandle);                           

No comments:

Post a Comment