tags:

views:

113

answers:

2

We use an open source library written in C# wrapping Windows BITS COM component. However, the code is only safe to run it in x86 mode. I would like to contribute to the library by making it safe for both x86 and x64, however I have no deep knowledge in this field.

Could you please list here good/bad practices, typical issues, maybe principles also, etc, what to watch out for?

For example, I have seen in the code IntPtr is casted to System.Int32, which does not fly well on x64. How would you address this and similar issues in a platform agnostic manner?

+1  A: 

Hm, you dont ;)

Seriously.

Problem is that 64 bit and 32 bit com objects are not interoperable, so you definitely need either some lazy load setup without stron gbinding (and then we dont talk COM but COM with IDispatch), or two different wrapepr assemblies.

The whole x86/x64 thing is a SIGNIFICANT gap - in that it is very hard to cross. For example, yuo CAN NOT load a 32 bit DLL into a 64 bit process - regardless of wrapper or not, you just can not load it.

MS designed it in this way, on purpose. As such - there is no way around it.

TomTom
Thanx Tom, but I wonder... We are talking about BITS component which is native part of Windows. So if I run Win x64, I assume that the BITS COM component is already 64 bit implementation. So using the 32 bit .NET wrapper is not necessarily a good idea. Or am I wrong?
Not sure. Seriously - BITS may as well be 32 bit only even on 64 bit systems - if it makes no sense to compile it 64 bit (not needing th ememory etc.) you may find that there is no 64 bit version of it. You need to check the documentation. Note that this is not a limitation - for example. MS advices that websites (IIS) should run 32 bit always, as it is more efficient and websites rarely need the 64 bit memory capabiltiies in their app pools.
TomTom
+1  A: 

I think you are talking about SharpBits.NET, a wrapper for the BITS component. Yes, there are several places where the author fumbled the interop. There is otherwise no reason why it couldn't work, BITS is available both as a 32-bit and a 64-bit COM server. One example of such a fumble is in this thread.

Getting the P/Invoke declaration wrong or improperly manual marshaling is the vast majority of all 64-bit interop problems. I've left lots of hints on 64-bit coding problems in this thread.

Hans Passant